diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-01-10 06:33:47 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-01-10 19:35:30 -0500 |
commit | db702a7af6c85d94ff32b6110b3646180f93f086 (patch) | |
tree | 32a7d74fa85f6e7841886ed8517ce3de5d0de87a | |
parent | 7528cd273e14020117e6cdb6cc307f223e97c5ed (diff) |
[media] cx231xx: cx231xx_devused is racy
cx231xx_devused is racy. Re-implement it in a proper way,
to remove the risk of mangling it.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-cards.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c index bd82f017ccdf..1f2fbbfebc76 100644 --- a/drivers/media/video/cx231xx/cx231xx-cards.c +++ b/drivers/media/video/cx231xx/cx231xx-cards.c | |||
@@ -854,7 +854,7 @@ void cx231xx_release_resources(struct cx231xx *dev) | |||
854 | usb_put_dev(dev->udev); | 854 | usb_put_dev(dev->udev); |
855 | 855 | ||
856 | /* Mark device as unused */ | 856 | /* Mark device as unused */ |
857 | cx231xx_devused &= ~(1 << dev->devno); | 857 | clear_bit(dev->devno, &cx231xx_devused); |
858 | 858 | ||
859 | kfree(dev->video_mode.alt_max_pkt_size); | 859 | kfree(dev->video_mode.alt_max_pkt_size); |
860 | kfree(dev->vbi_mode.alt_max_pkt_size); | 860 | kfree(dev->vbi_mode.alt_max_pkt_size); |
@@ -1039,21 +1039,21 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1039 | return -ENODEV; | 1039 | return -ENODEV; |
1040 | 1040 | ||
1041 | /* Check to see next free device and mark as used */ | 1041 | /* Check to see next free device and mark as used */ |
1042 | nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); | 1042 | do { |
1043 | cx231xx_devused |= 1 << nr; | 1043 | nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); |
1044 | 1044 | if (nr >= CX231XX_MAXBOARDS) { | |
1045 | if (nr >= CX231XX_MAXBOARDS) { | 1045 | /* No free device slots */ |
1046 | cx231xx_err(DRIVER_NAME | 1046 | cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n", |
1047 | ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS); | 1047 | CX231XX_MAXBOARDS); |
1048 | cx231xx_devused &= ~(1 << nr); | 1048 | return -ENOMEM; |
1049 | return -ENOMEM; | 1049 | } |
1050 | } | 1050 | } while (test_and_set_bit(nr, &cx231xx_devused)); |
1051 | 1051 | ||
1052 | /* allocate memory for our device state and initialize it */ | 1052 | /* allocate memory for our device state and initialize it */ |
1053 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 1053 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
1054 | if (dev == NULL) { | 1054 | if (dev == NULL) { |
1055 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); | 1055 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); |
1056 | cx231xx_devused &= ~(1 << nr); | 1056 | clear_bit(dev->devno, &cx231xx_devused); |
1057 | return -ENOMEM; | 1057 | return -ENOMEM; |
1058 | } | 1058 | } |
1059 | 1059 | ||
@@ -1129,7 +1129,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1129 | if (assoc_desc->bFirstInterface != ifnum) { | 1129 | if (assoc_desc->bFirstInterface != ifnum) { |
1130 | cx231xx_err(DRIVER_NAME ": Not found " | 1130 | cx231xx_err(DRIVER_NAME ": Not found " |
1131 | "matching IAD interface\n"); | 1131 | "matching IAD interface\n"); |
1132 | cx231xx_devused &= ~(1 << nr); | 1132 | clear_bit(dev->devno, &cx231xx_devused); |
1133 | kfree(dev); | 1133 | kfree(dev); |
1134 | dev = NULL; | 1134 | dev = NULL; |
1135 | return -ENODEV; | 1135 | return -ENODEV; |
@@ -1148,7 +1148,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1148 | retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); | 1148 | retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); |
1149 | if (retval) { | 1149 | if (retval) { |
1150 | cx231xx_errdev("v4l2_device_register failed\n"); | 1150 | cx231xx_errdev("v4l2_device_register failed\n"); |
1151 | cx231xx_devused &= ~(1 << nr); | 1151 | clear_bit(dev->devno, &cx231xx_devused); |
1152 | kfree(dev); | 1152 | kfree(dev); |
1153 | dev = NULL; | 1153 | dev = NULL; |
1154 | return -EIO; | 1154 | return -EIO; |
@@ -1156,7 +1156,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1156 | /* allocate device struct */ | 1156 | /* allocate device struct */ |
1157 | retval = cx231xx_init_dev(&dev, udev, nr); | 1157 | retval = cx231xx_init_dev(&dev, udev, nr); |
1158 | if (retval) { | 1158 | if (retval) { |
1159 | cx231xx_devused &= ~(1 << dev->devno); | 1159 | clear_bit(dev->devno, &cx231xx_devused); |
1160 | v4l2_device_unregister(&dev->v4l2_dev); | 1160 | v4l2_device_unregister(&dev->v4l2_dev); |
1161 | kfree(dev); | 1161 | kfree(dev); |
1162 | dev = NULL; | 1162 | dev = NULL; |
@@ -1181,7 +1181,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1181 | 1181 | ||
1182 | if (dev->video_mode.alt_max_pkt_size == NULL) { | 1182 | if (dev->video_mode.alt_max_pkt_size == NULL) { |
1183 | cx231xx_errdev("out of memory!\n"); | 1183 | cx231xx_errdev("out of memory!\n"); |
1184 | cx231xx_devused &= ~(1 << nr); | 1184 | clear_bit(dev->devno, &cx231xx_devused); |
1185 | v4l2_device_unregister(&dev->v4l2_dev); | 1185 | v4l2_device_unregister(&dev->v4l2_dev); |
1186 | kfree(dev); | 1186 | kfree(dev); |
1187 | dev = NULL; | 1187 | dev = NULL; |
@@ -1215,7 +1215,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1215 | 1215 | ||
1216 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { | 1216 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { |
1217 | cx231xx_errdev("out of memory!\n"); | 1217 | cx231xx_errdev("out of memory!\n"); |
1218 | cx231xx_devused &= ~(1 << nr); | 1218 | clear_bit(dev->devno, &cx231xx_devused); |
1219 | v4l2_device_unregister(&dev->v4l2_dev); | 1219 | v4l2_device_unregister(&dev->v4l2_dev); |
1220 | kfree(dev); | 1220 | kfree(dev); |
1221 | dev = NULL; | 1221 | dev = NULL; |
@@ -1250,7 +1250,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1250 | 1250 | ||
1251 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { | 1251 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { |
1252 | cx231xx_errdev("out of memory!\n"); | 1252 | cx231xx_errdev("out of memory!\n"); |
1253 | cx231xx_devused &= ~(1 << nr); | 1253 | clear_bit(dev->devno, &cx231xx_devused); |
1254 | v4l2_device_unregister(&dev->v4l2_dev); | 1254 | v4l2_device_unregister(&dev->v4l2_dev); |
1255 | kfree(dev); | 1255 | kfree(dev); |
1256 | dev = NULL; | 1256 | dev = NULL; |
@@ -1286,7 +1286,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1286 | 1286 | ||
1287 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { | 1287 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { |
1288 | cx231xx_errdev("out of memory!\n"); | 1288 | cx231xx_errdev("out of memory!\n"); |
1289 | cx231xx_devused &= ~(1 << nr); | 1289 | clear_bit(dev->devno, &cx231xx_devused); |
1290 | v4l2_device_unregister(&dev->v4l2_dev); | 1290 | v4l2_device_unregister(&dev->v4l2_dev); |
1291 | kfree(dev); | 1291 | kfree(dev); |
1292 | dev = NULL; | 1292 | dev = NULL; |