Skip to content

Commit 6cff72f

Browse files
ribaldamchehab
authored andcommitted
media: s2255: Use refcount_t instead of atomic_t for num_channels
Use an API that resembles more the actual use of num_channels. Found by cocci: drivers/media/usb/s2255/s2255drv.c:2362:5-24: WARNING: atomic_dec_and_test variation before object free at line 2363. drivers/media/usb/s2255/s2255drv.c:1557:5-24: WARNING: atomic_dec_and_test variation before object free at line 1558. Link: https://lore.kernel.org/linux-media/[email protected] Signed-off-by: Ricardo Ribalda <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 6a56625 commit 6cff72f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/media/usb/s2255/s2255drv.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct s2255_vc {
247247
struct s2255_dev {
248248
struct s2255_vc vc[MAX_CHANNELS];
249249
struct v4l2_device v4l2_dev;
250-
atomic_t num_channels;
250+
refcount_t num_channels;
251251
int frames;
252252
struct mutex lock; /* channels[].vdev.lock */
253253
struct mutex cmdlock; /* protects cmdbuf */
@@ -1550,11 +1550,11 @@ static void s2255_video_device_release(struct video_device *vdev)
15501550
container_of(vdev, struct s2255_vc, vdev);
15511551

15521552
dprintk(dev, 4, "%s, chnls: %d\n", __func__,
1553-
atomic_read(&dev->num_channels));
1553+
refcount_read(&dev->num_channels));
15541554

15551555
v4l2_ctrl_handler_free(&vc->hdl);
15561556

1557-
if (atomic_dec_and_test(&dev->num_channels))
1557+
if (refcount_dec_and_test(&dev->num_channels))
15581558
s2255_destroy(dev);
15591559
return;
15601560
}
@@ -1659,19 +1659,19 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
16591659
"failed to register video device!\n");
16601660
break;
16611661
}
1662-
atomic_inc(&dev->num_channels);
1662+
refcount_inc(&dev->num_channels);
16631663
v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
16641664
video_device_node_name(&vc->vdev));
16651665

16661666
}
16671667
pr_info("Sensoray 2255 V4L driver Revision: %s\n",
16681668
S2255_VERSION);
16691669
/* if no channels registered, return error and probe will fail*/
1670-
if (atomic_read(&dev->num_channels) == 0) {
1670+
if (refcount_read(&dev->num_channels) == 0) {
16711671
v4l2_device_unregister(&dev->v4l2_dev);
16721672
return ret;
16731673
}
1674-
if (atomic_read(&dev->num_channels) != MAX_CHANNELS)
1674+
if (refcount_read(&dev->num_channels) != MAX_CHANNELS)
16751675
pr_warn("s2255: Not all channels available.\n");
16761676
return 0;
16771677
}
@@ -2221,7 +2221,7 @@ static int s2255_probe(struct usb_interface *interface,
22212221
goto errorFWDATA1;
22222222
}
22232223

2224-
atomic_set(&dev->num_channels, 0);
2224+
refcount_set(&dev->num_channels, 0);
22252225
dev->pid = id->idProduct;
22262226
dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
22272227
if (!dev->fw_data)
@@ -2341,12 +2341,12 @@ static void s2255_disconnect(struct usb_interface *interface)
23412341
{
23422342
struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
23432343
int i;
2344-
int channels = atomic_read(&dev->num_channels);
2344+
int channels = refcount_read(&dev->num_channels);
23452345
mutex_lock(&dev->lock);
23462346
v4l2_device_disconnect(&dev->v4l2_dev);
23472347
mutex_unlock(&dev->lock);
23482348
/*see comments in the uvc_driver.c usb disconnect function */
2349-
atomic_inc(&dev->num_channels);
2349+
refcount_inc(&dev->num_channels);
23502350
/* unregister each video device. */
23512351
for (i = 0; i < channels; i++)
23522352
video_unregister_device(&dev->vc[i].vdev);
@@ -2359,7 +2359,7 @@ static void s2255_disconnect(struct usb_interface *interface)
23592359
dev->vc[i].vidstatus_ready = 1;
23602360
wake_up(&dev->vc[i].wait_vidstatus);
23612361
}
2362-
if (atomic_dec_and_test(&dev->num_channels))
2362+
if (refcount_dec_and_test(&dev->num_channels))
23632363
s2255_destroy(dev);
23642364
dev_info(&interface->dev, "%s\n", __func__);
23652365
}

0 commit comments

Comments
 (0)