summaryrefslogtreecommitdiffstats
path: root/include/media
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2024-08-02 12:19:48 +0200
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2024-09-05 20:12:15 +0200
commit6bb8ef90c444c2fd97208bfce42137c4add32bbb (patch)
treed01c414fdfbdaefee51dc6b2dc6b26271cc17732 /include/media
parentmedia: input: serio.h: add SERIO_EXTRON_DA_HD_PLUS (diff)
downloadlinux-6bb8ef90c444c2fd97208bfce42137c4add32bbb.tar.xz
linux-6bb8ef90c444c2fd97208bfce42137c4add32bbb.zip
media: cec: move cec_get/put_device to header
Move cec_get/put_device to the media/cec.h header. This allows CEC drivers to use this. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Diffstat (limited to 'include/media')
-rw-r--r--include/media/cec.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/media/cec.h b/include/media/cec.h
index 07d2ee8a3904..16b412b3131b 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -298,6 +298,37 @@ struct cec_adapter {
char input_phys[40];
};
+static inline int cec_get_device(struct cec_adapter *adap)
+{
+ struct cec_devnode *devnode = &adap->devnode;
+
+ /*
+ * Check if the cec device is available. This needs to be done with
+ * the devnode->lock held to prevent an open/unregister race:
+ * without the lock, the device could be unregistered and freed between
+ * the devnode->registered check and get_device() calls, leading to
+ * a crash.
+ */
+ mutex_lock(&devnode->lock);
+ /*
+ * return ENODEV if the cec device has been removed
+ * already or if it is not registered anymore.
+ */
+ if (!devnode->registered) {
+ mutex_unlock(&devnode->lock);
+ return -ENODEV;
+ }
+ /* and increase the device refcount */
+ get_device(&devnode->dev);
+ mutex_unlock(&devnode->lock);
+ return 0;
+}
+
+static inline void cec_put_device(struct cec_adapter *adap)
+{
+ put_device(&adap->devnode.dev);
+}
+
static inline void *cec_get_drvdata(const struct cec_adapter *adap)
{
return adap->priv;