Skip to content

Commit 6bb8ef9

Browse files
Hans Verkuilmchehab
authored andcommitted
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 <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent c7a2925 commit 6bb8ef9

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

drivers/media/cec/core/cec-api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static int cec_open(struct inode *inode, struct file *filp)
580580
fh->mode_initiator = CEC_MODE_INITIATOR;
581581
fh->adap = adap;
582582

583-
err = cec_get_device(devnode);
583+
err = cec_get_device(adap);
584584
if (err) {
585585
kfree(fh);
586586
return err;
@@ -686,7 +686,7 @@ static int cec_release(struct inode *inode, struct file *filp)
686686
mutex_unlock(&fh->lock);
687687
kfree(fh);
688688

689-
cec_put_device(devnode);
689+
cec_put_device(adap);
690690
filp->private_data = NULL;
691691
return 0;
692692
}

drivers/media/cec/core/cec-core.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,6 @@ static struct dentry *top_cec_dir;
5151
/* dev to cec_devnode */
5252
#define to_cec_devnode(cd) container_of(cd, struct cec_devnode, dev)
5353

54-
int cec_get_device(struct cec_devnode *devnode)
55-
{
56-
/*
57-
* Check if the cec device is available. This needs to be done with
58-
* the devnode->lock held to prevent an open/unregister race:
59-
* without the lock, the device could be unregistered and freed between
60-
* the devnode->registered check and get_device() calls, leading to
61-
* a crash.
62-
*/
63-
mutex_lock(&devnode->lock);
64-
/*
65-
* return ENODEV if the cec device has been removed
66-
* already or if it is not registered anymore.
67-
*/
68-
if (!devnode->registered) {
69-
mutex_unlock(&devnode->lock);
70-
return -ENODEV;
71-
}
72-
/* and increase the device refcount */
73-
get_device(&devnode->dev);
74-
mutex_unlock(&devnode->lock);
75-
return 0;
76-
}
77-
78-
void cec_put_device(struct cec_devnode *devnode)
79-
{
80-
put_device(&devnode->dev);
81-
}
82-
8354
/* Called when the last user of the cec device exits. */
8455
static void cec_devnode_release(struct device *cd)
8556
{

drivers/media/cec/core/cec-priv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ static inline bool msg_is_raw(const struct cec_msg *msg)
3737

3838
/* cec-core.c */
3939
extern int cec_debug;
40-
int cec_get_device(struct cec_devnode *devnode);
41-
void cec_put_device(struct cec_devnode *devnode);
4240

4341
/* cec-adap.c */
4442
int cec_monitor_all_cnt_inc(struct cec_adapter *adap);

include/media/cec.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,37 @@ struct cec_adapter {
298298
char input_phys[40];
299299
};
300300

301+
static inline int cec_get_device(struct cec_adapter *adap)
302+
{
303+
struct cec_devnode *devnode = &adap->devnode;
304+
305+
/*
306+
* Check if the cec device is available. This needs to be done with
307+
* the devnode->lock held to prevent an open/unregister race:
308+
* without the lock, the device could be unregistered and freed between
309+
* the devnode->registered check and get_device() calls, leading to
310+
* a crash.
311+
*/
312+
mutex_lock(&devnode->lock);
313+
/*
314+
* return ENODEV if the cec device has been removed
315+
* already or if it is not registered anymore.
316+
*/
317+
if (!devnode->registered) {
318+
mutex_unlock(&devnode->lock);
319+
return -ENODEV;
320+
}
321+
/* and increase the device refcount */
322+
get_device(&devnode->dev);
323+
mutex_unlock(&devnode->lock);
324+
return 0;
325+
}
326+
327+
static inline void cec_put_device(struct cec_adapter *adap)
328+
{
329+
put_device(&adap->devnode.dev);
330+
}
331+
301332
static inline void *cec_get_drvdata(const struct cec_adapter *adap)
302333
{
303334
return adap->priv;

0 commit comments

Comments
 (0)