V4L/DVB (3380): Semaphore to mutex conversion on drivers/media

- Semaphore to mutex conversion.
The conversion was generated via scripts, and the result was validated
automatically via a script as well.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

authored by Ingo Molnar and committed by Mauro Carvalho Chehab 1e4baed3 7d83e843

+45 -43
+11 -11
drivers/media/dvb/dvb-core/dvbdev.c
··· 33 #include <linux/device.h> 34 #include <linux/fs.h> 35 #include <linux/cdev.h> 36 - 37 #include "dvbdev.h" 38 39 static int dvbdev_debug; ··· 44 #define dprintk if (dvbdev_debug) printk 45 46 static LIST_HEAD(dvb_adapter_list); 47 - static DECLARE_MUTEX(dvbdev_register_lock); 48 49 static const char * const dnames[] = { 50 "video", "audio", "sec", "frontend", "demux", "dvr", "ca", ··· 202 struct dvb_device *dvbdev; 203 int id; 204 205 - if (down_interruptible (&dvbdev_register_lock)) 206 return -ERESTARTSYS; 207 208 if ((id = dvbdev_get_free_id (adap, type)) < 0) { 209 - up (&dvbdev_register_lock); 210 *pdvbdev = NULL; 211 printk ("%s: could get find free device id...\n", __FUNCTION__); 212 return -ENFILE; ··· 215 *pdvbdev = dvbdev = kmalloc(sizeof(struct dvb_device), GFP_KERNEL); 216 217 if (!dvbdev) { 218 - up(&dvbdev_register_lock); 219 return -ENOMEM; 220 } 221 222 - up (&dvbdev_register_lock); 223 224 memcpy(dvbdev, template, sizeof(struct dvb_device)); 225 dvbdev->type = type; ··· 289 { 290 int num; 291 292 - if (down_interruptible (&dvbdev_register_lock)) 293 return -ERESTARTSYS; 294 295 if ((num = dvbdev_get_free_adapter_num ()) < 0) { 296 - up (&dvbdev_register_lock); 297 return -ENFILE; 298 } 299 ··· 309 310 list_add_tail (&adap->list_head, &dvb_adapter_list); 311 312 - up (&dvbdev_register_lock); 313 314 return num; 315 } ··· 320 { 321 devfs_remove("dvb/adapter%d", adap->num); 322 323 - if (down_interruptible (&dvbdev_register_lock)) 324 return -ERESTARTSYS; 325 list_del (&adap->list_head); 326 - up (&dvbdev_register_lock); 327 return 0; 328 } 329 EXPORT_SYMBOL(dvb_unregister_adapter);
··· 33 #include <linux/device.h> 34 #include <linux/fs.h> 35 #include <linux/cdev.h> 36 + #include <linux/mutex.h> 37 #include "dvbdev.h" 38 39 static int dvbdev_debug; ··· 44 #define dprintk if (dvbdev_debug) printk 45 46 static LIST_HEAD(dvb_adapter_list); 47 + static DEFINE_MUTEX(dvbdev_register_lock); 48 49 static const char * const dnames[] = { 50 "video", "audio", "sec", "frontend", "demux", "dvr", "ca", ··· 202 struct dvb_device *dvbdev; 203 int id; 204 205 + if (mutex_lock_interruptible(&dvbdev_register_lock)) 206 return -ERESTARTSYS; 207 208 if ((id = dvbdev_get_free_id (adap, type)) < 0) { 209 + mutex_unlock(&dvbdev_register_lock); 210 *pdvbdev = NULL; 211 printk ("%s: could get find free device id...\n", __FUNCTION__); 212 return -ENFILE; ··· 215 *pdvbdev = dvbdev = kmalloc(sizeof(struct dvb_device), GFP_KERNEL); 216 217 if (!dvbdev) { 218 + mutex_unlock(&dvbdev_register_lock); 219 return -ENOMEM; 220 } 221 222 + mutex_unlock(&dvbdev_register_lock); 223 224 memcpy(dvbdev, template, sizeof(struct dvb_device)); 225 dvbdev->type = type; ··· 289 { 290 int num; 291 292 + if (mutex_lock_interruptible(&dvbdev_register_lock)) 293 return -ERESTARTSYS; 294 295 if ((num = dvbdev_get_free_adapter_num ()) < 0) { 296 + mutex_unlock(&dvbdev_register_lock); 297 return -ENFILE; 298 } 299 ··· 309 310 list_add_tail (&adap->list_head, &dvb_adapter_list); 311 312 + mutex_unlock(&dvbdev_register_lock); 313 314 return num; 315 } ··· 320 { 321 devfs_remove("dvb/adapter%d", adap->num); 322 323 + if (mutex_lock_interruptible(&dvbdev_register_lock)) 324 return -ERESTARTSYS; 325 list_del (&adap->list_head); 326 + mutex_unlock(&dvbdev_register_lock); 327 return 0; 328 } 329 EXPORT_SYMBOL(dvb_unregister_adapter);
+8 -7
drivers/media/video/cx88/cx88-core.c
··· 32 #include <linux/pci.h> 33 #include <linux/delay.h> 34 #include <linux/videodev2.h> 35 36 #include "cx88.h" 37 #include <media/v4l2-common.h> ··· 76 77 static unsigned int cx88_devcount; 78 static LIST_HEAD(cx88_devlist); 79 - static DECLARE_MUTEX(devlist); 80 81 #define NO_SYNC_LINE (-1U) 82 ··· 1037 struct list_head *item; 1038 int i; 1039 1040 - down(&devlist); 1041 list_for_each(item,&cx88_devlist) { 1042 core = list_entry(item, struct cx88_core, devlist); 1043 if (pci->bus->number != core->pci_bus) ··· 1048 if (0 != get_ressources(core,pci)) 1049 goto fail_unlock; 1050 atomic_inc(&core->refcount); 1051 - up(&devlist); 1052 return core; 1053 } 1054 core = kzalloc(sizeof(*core),GFP_KERNEL); ··· 1123 cx88_card_setup(core); 1124 cx88_ir_init(core,pci); 1125 1126 - up(&devlist); 1127 return core; 1128 1129 fail_free: 1130 kfree(core); 1131 fail_unlock: 1132 - up(&devlist); 1133 return NULL; 1134 } 1135 ··· 1141 if (!atomic_dec_and_test(&core->refcount)) 1142 return; 1143 1144 - down(&devlist); 1145 cx88_ir_fini(core); 1146 if (0 == core->i2c_rc) 1147 i2c_bit_del_bus(&core->i2c_adap); 1148 list_del(&core->devlist); 1149 iounmap(core->lmmio); 1150 cx88_devcount--; 1151 - up(&devlist); 1152 kfree(core); 1153 } 1154
··· 32 #include <linux/pci.h> 33 #include <linux/delay.h> 34 #include <linux/videodev2.h> 35 + #include <linux/mutex.h> 36 37 #include "cx88.h" 38 #include <media/v4l2-common.h> ··· 75 76 static unsigned int cx88_devcount; 77 static LIST_HEAD(cx88_devlist); 78 + static DEFINE_MUTEX(devlist); 79 80 #define NO_SYNC_LINE (-1U) 81 ··· 1036 struct list_head *item; 1037 int i; 1038 1039 + mutex_lock(&devlist); 1040 list_for_each(item,&cx88_devlist) { 1041 core = list_entry(item, struct cx88_core, devlist); 1042 if (pci->bus->number != core->pci_bus) ··· 1047 if (0 != get_ressources(core,pci)) 1048 goto fail_unlock; 1049 atomic_inc(&core->refcount); 1050 + mutex_unlock(&devlist); 1051 return core; 1052 } 1053 core = kzalloc(sizeof(*core),GFP_KERNEL); ··· 1122 cx88_card_setup(core); 1123 cx88_ir_init(core,pci); 1124 1125 + mutex_unlock(&devlist); 1126 return core; 1127 1128 fail_free: 1129 kfree(core); 1130 fail_unlock: 1131 + mutex_unlock(&devlist); 1132 return NULL; 1133 } 1134 ··· 1140 if (!atomic_dec_and_test(&core->refcount)) 1141 return; 1142 1143 + mutex_lock(&devlist); 1144 cx88_ir_fini(core); 1145 if (0 == core->i2c_rc) 1146 i2c_bit_del_bus(&core->i2c_adap); 1147 list_del(&core->devlist); 1148 iounmap(core->lmmio); 1149 cx88_devcount--; 1150 + mutex_unlock(&devlist); 1151 kfree(core); 1152 } 1153
+4 -3
drivers/media/video/em28xx/em28xx-video.c
··· 29 #include <linux/i2c.h> 30 #include <linux/version.h> 31 #include <linux/video_decoder.h> 32 33 #include "em28xx.h" 34 #include <media/tuner.h> ··· 192 193 static struct usb_driver em28xx_usb_driver; 194 195 - static DECLARE_MUTEX(em28xx_sysfs_lock); 196 static DECLARE_RWSEM(em28xx_disconnect); 197 198 /********************* v4l2 interface ******************************************/ ··· 395 */ 396 static void em28xx_release_resources(struct em28xx *dev) 397 { 398 - down(&em28xx_sysfs_lock); 399 400 em28xx_info("V4L2 device /dev/video%d deregistered\n", 401 dev->vdev->minor); ··· 404 /* video_unregister_device(dev->vbi_dev); */ 405 em28xx_i2c_unregister(dev); 406 usb_put_dev(dev->udev); 407 - up(&em28xx_sysfs_lock); 408 } 409 410 /*
··· 29 #include <linux/i2c.h> 30 #include <linux/version.h> 31 #include <linux/video_decoder.h> 32 + #include <linux/mutex.h> 33 34 #include "em28xx.h" 35 #include <media/tuner.h> ··· 191 192 static struct usb_driver em28xx_usb_driver; 193 194 + static DEFINE_MUTEX(em28xx_sysfs_lock); 195 static DECLARE_RWSEM(em28xx_disconnect); 196 197 /********************* v4l2 interface ******************************************/ ··· 394 */ 395 static void em28xx_release_resources(struct em28xx *dev) 396 { 397 + mutex_lock(&em28xx_sysfs_lock); 398 399 em28xx_info("V4L2 device /dev/video%d deregistered\n", 400 dev->vdev->minor); ··· 403 /* video_unregister_device(dev->vbi_dev); */ 404 em28xx_i2c_unregister(dev); 405 usb_put_dev(dev->udev); 406 + mutex_unlock(&em28xx_sysfs_lock); 407 } 408 409 /*
+10 -9
drivers/media/video/saa7134/saa7134-core.c
··· 31 #include <linux/sound.h> 32 #include <linux/interrupt.h> 33 #include <linux/delay.h> 34 35 #include "saa7134-reg.h" 36 #include "saa7134.h" ··· 85 MODULE_PARM_DESC(tuner, "tuner type"); 86 MODULE_PARM_DESC(card, "card type"); 87 88 - static DECLARE_MUTEX(devlist_lock); 89 LIST_HEAD(saa7134_devlist); 90 static LIST_HEAD(mops_list); 91 static unsigned int saa7134_devcount; ··· 970 pci_set_drvdata(pci_dev,dev); 971 saa7134_devcount++; 972 973 - down(&devlist_lock); 974 list_for_each(item,&mops_list) { 975 mops = list_entry(item, struct saa7134_mpeg_ops, next); 976 mpeg_ops_attach(mops, dev); 977 } 978 list_add_tail(&dev->devlist,&saa7134_devlist); 979 - up(&devlist_lock); 980 981 /* check for signal */ 982 saa7134_irq_video_intl(dev); ··· 1032 saa7134_hwfini(dev); 1033 1034 /* unregister */ 1035 - down(&devlist_lock); 1036 list_del(&dev->devlist); 1037 list_for_each(item,&mops_list) { 1038 mops = list_entry(item, struct saa7134_mpeg_ops, next); 1039 mpeg_ops_detach(mops, dev); 1040 } 1041 - up(&devlist_lock); 1042 saa7134_devcount--; 1043 1044 saa7134_i2c_unregister(dev); ··· 1072 struct list_head *item; 1073 struct saa7134_dev *dev; 1074 1075 - down(&devlist_lock); 1076 list_for_each(item,&saa7134_devlist) { 1077 dev = list_entry(item, struct saa7134_dev, devlist); 1078 mpeg_ops_attach(ops, dev); 1079 } 1080 list_add_tail(&ops->next,&mops_list); 1081 - up(&devlist_lock); 1082 return 0; 1083 } 1084 ··· 1087 struct list_head *item; 1088 struct saa7134_dev *dev; 1089 1090 - down(&devlist_lock); 1091 list_del(&ops->next); 1092 list_for_each(item,&saa7134_devlist) { 1093 dev = list_entry(item, struct saa7134_dev, devlist); 1094 mpeg_ops_detach(ops, dev); 1095 } 1096 - up(&devlist_lock); 1097 } 1098 1099 EXPORT_SYMBOL(saa7134_ts_register);
··· 31 #include <linux/sound.h> 32 #include <linux/interrupt.h> 33 #include <linux/delay.h> 34 + #include <linux/mutex.h> 35 36 #include "saa7134-reg.h" 37 #include "saa7134.h" ··· 84 MODULE_PARM_DESC(tuner, "tuner type"); 85 MODULE_PARM_DESC(card, "card type"); 86 87 + static DEFINE_MUTEX(devlist_lock); 88 LIST_HEAD(saa7134_devlist); 89 static LIST_HEAD(mops_list); 90 static unsigned int saa7134_devcount; ··· 969 pci_set_drvdata(pci_dev,dev); 970 saa7134_devcount++; 971 972 + mutex_lock(&devlist_lock); 973 list_for_each(item,&mops_list) { 974 mops = list_entry(item, struct saa7134_mpeg_ops, next); 975 mpeg_ops_attach(mops, dev); 976 } 977 list_add_tail(&dev->devlist,&saa7134_devlist); 978 + mutex_unlock(&devlist_lock); 979 980 /* check for signal */ 981 saa7134_irq_video_intl(dev); ··· 1031 saa7134_hwfini(dev); 1032 1033 /* unregister */ 1034 + mutex_lock(&devlist_lock); 1035 list_del(&dev->devlist); 1036 list_for_each(item,&mops_list) { 1037 mops = list_entry(item, struct saa7134_mpeg_ops, next); 1038 mpeg_ops_detach(mops, dev); 1039 } 1040 + mutex_unlock(&devlist_lock); 1041 saa7134_devcount--; 1042 1043 saa7134_i2c_unregister(dev); ··· 1071 struct list_head *item; 1072 struct saa7134_dev *dev; 1073 1074 + mutex_lock(&devlist_lock); 1075 list_for_each(item,&saa7134_devlist) { 1076 dev = list_entry(item, struct saa7134_dev, devlist); 1077 mpeg_ops_attach(ops, dev); 1078 } 1079 list_add_tail(&ops->next,&mops_list); 1080 + mutex_unlock(&devlist_lock); 1081 return 0; 1082 } 1083 ··· 1086 struct list_head *item; 1087 struct saa7134_dev *dev; 1088 1089 + mutex_lock(&devlist_lock); 1090 list_del(&ops->next); 1091 list_for_each(item,&saa7134_devlist) { 1092 dev = list_entry(item, struct saa7134_dev, devlist); 1093 mpeg_ops_detach(ops, dev); 1094 } 1095 + mutex_unlock(&devlist_lock); 1096 } 1097 1098 EXPORT_SYMBOL(saa7134_ts_register);
+12 -13
drivers/media/video/videodev.c
··· 29 #include <linux/devfs_fs_kernel.h> 30 #include <asm/uaccess.h> 31 #include <asm/system.h> 32 - #include <asm/semaphore.h> 33 34 #include <linux/videodev.h> 35 ··· 82 */ 83 84 static struct video_device *video_device[VIDEO_NUM_DEVICES]; 85 - static DECLARE_MUTEX(videodev_lock); 86 87 struct video_device* video_devdata(struct file *file) 88 { ··· 101 102 if(minor>=VIDEO_NUM_DEVICES) 103 return -ENODEV; 104 - down(&videodev_lock); 105 vfl=video_device[minor]; 106 if(vfl==NULL) { 107 - up(&videodev_lock); 108 request_module("char-major-%d-%d", VIDEO_MAJOR, minor); 109 - down(&videodev_lock); 110 vfl=video_device[minor]; 111 if (vfl==NULL) { 112 - up(&videodev_lock); 113 return -ENODEV; 114 } 115 } ··· 122 file->f_op = fops_get(old_fops); 123 } 124 fops_put(old_fops); 125 - up(&videodev_lock); 126 return err; 127 } 128 ··· 303 } 304 305 /* pick a minor number */ 306 - down(&videodev_lock); 307 if (nr >= 0 && nr < end-base) { 308 /* use the one the driver asked for */ 309 i = base+nr; 310 if (NULL != video_device[i]) { 311 - up(&videodev_lock); 312 return -ENFILE; 313 } 314 } else { ··· 317 if (NULL == video_device[i]) 318 break; 319 if (i == end) { 320 - up(&videodev_lock); 321 return -ENFILE; 322 } 323 } 324 video_device[i]=vfd; 325 vfd->minor=i; 326 - up(&videodev_lock); 327 328 sprintf(vfd->devfs_name, "v4l/%s%d", name_base, i - base); 329 devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor), ··· 361 362 void video_unregister_device(struct video_device *vfd) 363 { 364 - down(&videodev_lock); 365 if(video_device[vfd->minor]!=vfd) 366 panic("videodev: bad unregister"); 367 368 devfs_remove(vfd->devfs_name); 369 video_device[vfd->minor]=NULL; 370 class_device_unregister(&vfd->class_dev); 371 - up(&videodev_lock); 372 } 373 374
··· 29 #include <linux/devfs_fs_kernel.h> 30 #include <asm/uaccess.h> 31 #include <asm/system.h> 32 33 #include <linux/videodev.h> 34 ··· 83 */ 84 85 static struct video_device *video_device[VIDEO_NUM_DEVICES]; 86 + static DEFINE_MUTEX(videodev_lock); 87 88 struct video_device* video_devdata(struct file *file) 89 { ··· 102 103 if(minor>=VIDEO_NUM_DEVICES) 104 return -ENODEV; 105 + mutex_lock(&videodev_lock); 106 vfl=video_device[minor]; 107 if(vfl==NULL) { 108 + mutex_unlock(&videodev_lock); 109 request_module("char-major-%d-%d", VIDEO_MAJOR, minor); 110 + mutex_lock(&videodev_lock); 111 vfl=video_device[minor]; 112 if (vfl==NULL) { 113 + mutex_unlock(&videodev_lock); 114 return -ENODEV; 115 } 116 } ··· 123 file->f_op = fops_get(old_fops); 124 } 125 fops_put(old_fops); 126 + mutex_unlock(&videodev_lock); 127 return err; 128 } 129 ··· 304 } 305 306 /* pick a minor number */ 307 + mutex_lock(&videodev_lock); 308 if (nr >= 0 && nr < end-base) { 309 /* use the one the driver asked for */ 310 i = base+nr; 311 if (NULL != video_device[i]) { 312 + mutex_unlock(&videodev_lock); 313 return -ENFILE; 314 } 315 } else { ··· 318 if (NULL == video_device[i]) 319 break; 320 if (i == end) { 321 + mutex_unlock(&videodev_lock); 322 return -ENFILE; 323 } 324 } 325 video_device[i]=vfd; 326 vfd->minor=i; 327 + mutex_unlock(&videodev_lock); 328 329 sprintf(vfd->devfs_name, "v4l/%s%d", name_base, i - base); 330 devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor), ··· 362 363 void video_unregister_device(struct video_device *vfd) 364 { 365 + mutex_lock(&videodev_lock); 366 if(video_device[vfd->minor]!=vfd) 367 panic("videodev: bad unregister"); 368 369 devfs_remove(vfd->devfs_name); 370 video_device[vfd->minor]=NULL; 371 class_device_unregister(&vfd->class_dev); 372 + mutex_unlock(&videodev_lock); 373 } 374 375