Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
6bb8ef90 c7a29258

+33 -33
+2 -2
drivers/media/cec/core/cec-api.c
··· 580 580 fh->mode_initiator = CEC_MODE_INITIATOR; 581 581 fh->adap = adap; 582 582 583 - err = cec_get_device(devnode); 583 + err = cec_get_device(adap); 584 584 if (err) { 585 585 kfree(fh); 586 586 return err; ··· 686 686 mutex_unlock(&fh->lock); 687 687 kfree(fh); 688 688 689 - cec_put_device(devnode); 689 + cec_put_device(adap); 690 690 filp->private_data = NULL; 691 691 return 0; 692 692 }
-29
drivers/media/cec/core/cec-core.c
··· 51 51 /* dev to cec_devnode */ 52 52 #define to_cec_devnode(cd) container_of(cd, struct cec_devnode, dev) 53 53 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 - 83 54 /* Called when the last user of the cec device exits. */ 84 55 static void cec_devnode_release(struct device *cd) 85 56 {
-2
drivers/media/cec/core/cec-priv.h
··· 37 37 38 38 /* cec-core.c */ 39 39 extern int cec_debug; 40 - int cec_get_device(struct cec_devnode *devnode); 41 - void cec_put_device(struct cec_devnode *devnode); 42 40 43 41 /* cec-adap.c */ 44 42 int cec_monitor_all_cnt_inc(struct cec_adapter *adap);
+31
include/media/cec.h
··· 298 298 char input_phys[40]; 299 299 }; 300 300 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 + 301 332 static inline void *cec_get_drvdata(const struct cec_adapter *adap) 302 333 { 303 334 return adap->priv;