Commit e64d07c9 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] dsbr100: convert to unlocked_ioctl

Use core-assisted locking so .ioctl can be replaced by .unlocked_ioctl.
Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2335e2b8
...@@ -148,7 +148,7 @@ struct dsbr100_device { ...@@ -148,7 +148,7 @@ struct dsbr100_device {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
u8 *transfer_buffer; u8 *transfer_buffer;
struct mutex lock; /* buffer locking */ struct mutex v4l2_lock;
int curfreq; int curfreq;
int stereo; int stereo;
int removed; int removed;
...@@ -182,8 +182,6 @@ static int dsbr100_start(struct dsbr100_device *radio) ...@@ -182,8 +182,6 @@ static int dsbr100_start(struct dsbr100_device *radio)
int retval; int retval;
int request; int request;
mutex_lock(&radio->lock);
retval = usb_control_msg(radio->usbdev, retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0), usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS, USB_REQ_GET_STATUS,
...@@ -207,11 +205,9 @@ static int dsbr100_start(struct dsbr100_device *radio) ...@@ -207,11 +205,9 @@ static int dsbr100_start(struct dsbr100_device *radio)
} }
radio->status = STARTED; radio->status = STARTED;
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0]; return (radio->transfer_buffer)[0];
usb_control_msg_failed: usb_control_msg_failed:
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev, dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n", "%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request); __func__, retval, request);
...@@ -225,8 +221,6 @@ static int dsbr100_stop(struct dsbr100_device *radio) ...@@ -225,8 +221,6 @@ static int dsbr100_stop(struct dsbr100_device *radio)
int retval; int retval;
int request; int request;
mutex_lock(&radio->lock);
retval = usb_control_msg(radio->usbdev, retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0), usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS, USB_REQ_GET_STATUS,
...@@ -250,11 +244,9 @@ static int dsbr100_stop(struct dsbr100_device *radio) ...@@ -250,11 +244,9 @@ static int dsbr100_stop(struct dsbr100_device *radio)
} }
radio->status = STOPPED; radio->status = STOPPED;
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0]; return (radio->transfer_buffer)[0];
usb_control_msg_failed: usb_control_msg_failed:
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev, dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n", "%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request); __func__, retval, request);
...@@ -269,8 +261,6 @@ static int dsbr100_setfreq(struct dsbr100_device *radio) ...@@ -269,8 +261,6 @@ static int dsbr100_setfreq(struct dsbr100_device *radio)
int request; int request;
int freq = (radio->curfreq / 16 * 80) / 1000 + 856; int freq = (radio->curfreq / 16 * 80) / 1000 + 856;
mutex_lock(&radio->lock);
retval = usb_control_msg(radio->usbdev, retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0), usb_rcvctrlpipe(radio->usbdev, 0),
DSB100_TUNE, DSB100_TUNE,
...@@ -306,12 +296,10 @@ static int dsbr100_setfreq(struct dsbr100_device *radio) ...@@ -306,12 +296,10 @@ static int dsbr100_setfreq(struct dsbr100_device *radio)
} }
radio->stereo = !((radio->transfer_buffer)[0] & 0x01); radio->stereo = !((radio->transfer_buffer)[0] & 0x01);
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0]; return (radio->transfer_buffer)[0];
usb_control_msg_failed: usb_control_msg_failed:
radio->stereo = -1; radio->stereo = -1;
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev, dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n", "%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request); __func__, retval, request);
...@@ -324,8 +312,6 @@ static void dsbr100_getstat(struct dsbr100_device *radio) ...@@ -324,8 +312,6 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
{ {
int retval; int retval;
mutex_lock(&radio->lock);
retval = usb_control_msg(radio->usbdev, retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0), usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS, USB_REQ_GET_STATUS,
...@@ -340,33 +326,8 @@ static void dsbr100_getstat(struct dsbr100_device *radio) ...@@ -340,33 +326,8 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
} else { } else {
radio->stereo = !(radio->transfer_buffer[0] & 0x01); radio->stereo = !(radio->transfer_buffer[0] & 0x01);
} }
mutex_unlock(&radio->lock);
}
/* USB subsystem interface begins here */
/*
* Handle unplugging of the device.
* We call video_unregister_device in any case.
* The last function called in this procedure is
* usb_dsbr100_video_device_release
*/
static void usb_dsbr100_disconnect(struct usb_interface *intf)
{
struct dsbr100_device *radio = usb_get_intfdata(intf);
usb_set_intfdata (intf, NULL);
mutex_lock(&radio->lock);
radio->removed = 1;
mutex_unlock(&radio->lock);
video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
} }
static int vidioc_querycap(struct file *file, void *priv, static int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *v) struct v4l2_capability *v)
{ {
...@@ -432,9 +393,7 @@ static int vidioc_s_frequency(struct file *file, void *priv, ...@@ -432,9 +393,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
if (radio->removed) if (radio->removed)
return -EIO; return -EIO;
mutex_lock(&radio->lock);
radio->curfreq = f->frequency; radio->curfreq = f->frequency;
mutex_unlock(&radio->lock);
retval = dsbr100_setfreq(radio); retval = dsbr100_setfreq(radio);
if (retval < 0) if (retval < 0)
...@@ -548,12 +507,36 @@ static int vidioc_s_audio(struct file *file, void *priv, ...@@ -548,12 +507,36 @@ static int vidioc_s_audio(struct file *file, void *priv,
return 0; return 0;
} }
/* USB subsystem interface begins here */
/*
* Handle unplugging of the device.
* We call video_unregister_device in any case.
* The last function called in this procedure is
* usb_dsbr100_video_device_release
*/
static void usb_dsbr100_disconnect(struct usb_interface *intf)
{
struct dsbr100_device *radio = usb_get_intfdata(intf);
usb_set_intfdata(intf, NULL);
mutex_lock(&radio->v4l2_lock);
radio->removed = 1;
mutex_unlock(&radio->v4l2_lock);
video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
}
/* Suspend device - stop device. */ /* Suspend device - stop device. */
static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message) static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
{ {
struct dsbr100_device *radio = usb_get_intfdata(intf); struct dsbr100_device *radio = usb_get_intfdata(intf);
int retval; int retval;
mutex_lock(&radio->v4l2_lock);
if (radio->status == STARTED) { if (radio->status == STARTED) {
retval = dsbr100_stop(radio); retval = dsbr100_stop(radio);
if (retval < 0) if (retval < 0)
...@@ -564,11 +547,9 @@ static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message) ...@@ -564,11 +547,9 @@ static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
* we set status equal to STARTED. * we set status equal to STARTED.
* On resume we will check status and run radio if needed. * On resume we will check status and run radio if needed.
*/ */
mutex_lock(&radio->lock);
radio->status = STARTED; radio->status = STARTED;
mutex_unlock(&radio->lock);
} }
mutex_unlock(&radio->v4l2_lock);
dev_info(&intf->dev, "going into suspend..\n"); dev_info(&intf->dev, "going into suspend..\n");
...@@ -581,11 +562,13 @@ static int usb_dsbr100_resume(struct usb_interface *intf) ...@@ -581,11 +562,13 @@ static int usb_dsbr100_resume(struct usb_interface *intf)
struct dsbr100_device *radio = usb_get_intfdata(intf); struct dsbr100_device *radio = usb_get_intfdata(intf);
int retval; int retval;
mutex_lock(&radio->v4l2_lock);
if (radio->status == STARTED) { if (radio->status == STARTED) {
retval = dsbr100_start(radio); retval = dsbr100_start(radio);
if (retval < 0) if (retval < 0)
dev_warn(&intf->dev, "dsbr100_start failed\n"); dev_warn(&intf->dev, "dsbr100_start failed\n");
} }
mutex_unlock(&radio->v4l2_lock);
dev_info(&intf->dev, "coming out of suspend..\n"); dev_info(&intf->dev, "coming out of suspend..\n");
...@@ -605,7 +588,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev) ...@@ -605,7 +588,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev)
/* File system interface */ /* File system interface */
static const struct v4l2_file_operations usb_dsbr100_fops = { static const struct v4l2_file_operations usb_dsbr100_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = video_ioctl2, .unlocked_ioctl = video_ioctl2,
}; };
static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = { static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
...@@ -653,13 +636,13 @@ static int usb_dsbr100_probe(struct usb_interface *intf, ...@@ -653,13 +636,13 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
return retval; return retval;
} }
mutex_init(&radio->v4l2_lock);
strlcpy(radio->videodev.name, v4l2_dev->name, sizeof(radio->videodev.name)); strlcpy(radio->videodev.name, v4l2_dev->name, sizeof(radio->videodev.name));
radio->videodev.v4l2_dev = v4l2_dev; radio->videodev.v4l2_dev = v4l2_dev;
radio->videodev.fops = &usb_dsbr100_fops; radio->videodev.fops = &usb_dsbr100_fops;
radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops; radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops;
radio->videodev.release = usb_dsbr100_video_device_release; radio->videodev.release = usb_dsbr100_video_device_release;
radio->videodev.lock = &radio->v4l2_lock;
mutex_init(&radio->lock);
radio->removed = 0; radio->removed = 0;
radio->usbdev = interface_to_usbdev(intf); radio->usbdev = interface_to_usbdev(intf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment