mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 15:11:16 +00:00
V4L/DVB (7993): si470x: move global lock to device structure
this patch brings the following changes: - move the global disconnect lock into the device structure - code cleanup (spaces to tabs, long line splits, ...) Signed-off-by: Tobias Lorenz <tobias.lorenz@gmx.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
parent
4fd305b2a2
commit
ce5829e5fc
1 changed files with 41 additions and 43 deletions
|
@ -85,7 +85,7 @@
|
||||||
* Oliver Neukum <oliver@neukum.org>
|
* Oliver Neukum <oliver@neukum.org>
|
||||||
* Version 1.0.7
|
* Version 1.0.7
|
||||||
* - usb autosuspend support
|
* - usb autosuspend support
|
||||||
* - unplugging fixed
|
* - unplugging fixed
|
||||||
*
|
*
|
||||||
* ToDo:
|
* ToDo:
|
||||||
* - add seeking support
|
* - add seeking support
|
||||||
|
@ -425,7 +425,8 @@ struct si470x_device {
|
||||||
|
|
||||||
/* driver management */
|
/* driver management */
|
||||||
unsigned int users;
|
unsigned int users;
|
||||||
unsigned char disconnected;
|
unsigned char disconnected;
|
||||||
|
struct mutex disconnect_lock;
|
||||||
|
|
||||||
/* Silabs internal registers (0..15) */
|
/* Silabs internal registers (0..15) */
|
||||||
unsigned short registers[RADIO_REGISTER_NUM];
|
unsigned short registers[RADIO_REGISTER_NUM];
|
||||||
|
@ -441,12 +442,6 @@ struct si470x_device {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lock to prevent kfree of data before all users have releases the device.
|
|
||||||
*/
|
|
||||||
static DEFINE_MUTEX(open_close_lock);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
|
* The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
|
||||||
* 62.5 kHz otherwise.
|
* 62.5 kHz otherwise.
|
||||||
|
@ -582,7 +577,7 @@ static int si470x_get_rds_registers(struct si470x_device *radio)
|
||||||
usb_rcvintpipe(radio->usbdev, 1),
|
usb_rcvintpipe(radio->usbdev, 1),
|
||||||
(void *) &buf, sizeof(buf), &size, usb_timeout);
|
(void *) &buf, sizeof(buf), &size, usb_timeout);
|
||||||
if (size != sizeof(buf))
|
if (size != sizeof(buf))
|
||||||
printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
|
printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
|
||||||
"return size differs: %d != %zu\n", size, sizeof(buf));
|
"return size differs: %d != %zu\n", size, sizeof(buf));
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
|
printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
|
||||||
|
@ -591,7 +586,8 @@ static int si470x_get_rds_registers(struct si470x_device *radio)
|
||||||
if (retval >= 0)
|
if (retval >= 0)
|
||||||
for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
|
for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
|
||||||
radio->registers[STATUSRSSI + regnr] =
|
radio->registers[STATUSRSSI + regnr] =
|
||||||
get_unaligned_be16(&buf[regnr * RADIO_REGISTER_SIZE + 1]);
|
get_unaligned_be16(
|
||||||
|
&buf[regnr * RADIO_REGISTER_SIZE + 1]);
|
||||||
|
|
||||||
return (retval < 0) ? -EINVAL : 0;
|
return (retval < 0) ? -EINVAL : 0;
|
||||||
}
|
}
|
||||||
|
@ -879,8 +875,8 @@ static void si470x_work(struct work_struct *work)
|
||||||
struct si470x_device *radio = container_of(work, struct si470x_device,
|
struct si470x_device *radio = container_of(work, struct si470x_device,
|
||||||
work.work);
|
work.work);
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return;
|
return;
|
||||||
if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
|
if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1007,20 +1003,20 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
|
||||||
static int si470x_fops_release(struct inode *inode, struct file *file)
|
static int si470x_fops_release(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (!radio)
|
if (!radio)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
mutex_lock(&open_close_lock);
|
mutex_lock(&radio->disconnect_lock);
|
||||||
radio->users--;
|
radio->users--;
|
||||||
if (radio->users == 0) {
|
if (radio->users == 0) {
|
||||||
if (radio->disconnected) {
|
if (radio->disconnected) {
|
||||||
video_unregister_device(radio->videodev);
|
video_unregister_device(radio->videodev);
|
||||||
kfree(radio->buffer);
|
kfree(radio->buffer);
|
||||||
kfree(radio);
|
kfree(radio);
|
||||||
goto done;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stop rds reception */
|
/* stop rds reception */
|
||||||
cancel_delayed_work_sync(&radio->work);
|
cancel_delayed_work_sync(&radio->work);
|
||||||
|
@ -1032,9 +1028,9 @@ static int si470x_fops_release(struct inode *inode, struct file *file)
|
||||||
usb_autopm_put_interface(radio->intf);
|
usb_autopm_put_interface(radio->intf);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
unlock:
|
||||||
mutex_unlock(&open_close_lock);
|
mutex_unlock(&radio->disconnect_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1174,8 +1170,8 @@ static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
|
||||||
{
|
{
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
switch (ctrl->id) {
|
switch (ctrl->id) {
|
||||||
case V4L2_CID_AUDIO_VOLUME:
|
case V4L2_CID_AUDIO_VOLUME:
|
||||||
|
@ -1201,8 +1197,8 @@ static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
switch (ctrl->id) {
|
switch (ctrl->id) {
|
||||||
case V4L2_CID_AUDIO_VOLUME:
|
case V4L2_CID_AUDIO_VOLUME:
|
||||||
|
@ -1266,8 +1262,8 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (tuner->index > 0)
|
if (tuner->index > 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -1324,8 +1320,8 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv,
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (tuner->index > 0)
|
if (tuner->index > 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -1351,8 +1347,8 @@ static int si470x_vidioc_g_frequency(struct file *file, void *priv,
|
||||||
{
|
{
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
freq->type = V4L2_TUNER_RADIO;
|
freq->type = V4L2_TUNER_RADIO;
|
||||||
freq->frequency = si470x_get_freq(radio);
|
freq->frequency = si470x_get_freq(radio);
|
||||||
|
@ -1370,8 +1366,8 @@ static int si470x_vidioc_s_frequency(struct file *file, void *priv,
|
||||||
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (radio->disconnected)
|
if (radio->disconnected)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (freq->type != V4L2_TUNER_RADIO)
|
if (freq->type != V4L2_TUNER_RADIO)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -1436,8 +1432,10 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
|
||||||
memcpy(radio->videodev, &si470x_viddev_template,
|
memcpy(radio->videodev, &si470x_viddev_template,
|
||||||
sizeof(si470x_viddev_template));
|
sizeof(si470x_viddev_template));
|
||||||
radio->users = 0;
|
radio->users = 0;
|
||||||
|
radio->disconnected = 0;
|
||||||
radio->usbdev = interface_to_usbdev(intf);
|
radio->usbdev = interface_to_usbdev(intf);
|
||||||
radio->intf = intf;
|
radio->intf = intf;
|
||||||
|
mutex_init(&radio->disconnect_lock);
|
||||||
mutex_init(&radio->lock);
|
mutex_init(&radio->lock);
|
||||||
video_set_drvdata(radio->videodev, radio);
|
video_set_drvdata(radio->videodev, radio);
|
||||||
|
|
||||||
|
@ -1542,16 +1540,16 @@ static void si470x_usb_driver_disconnect(struct usb_interface *intf)
|
||||||
{
|
{
|
||||||
struct si470x_device *radio = usb_get_intfdata(intf);
|
struct si470x_device *radio = usb_get_intfdata(intf);
|
||||||
|
|
||||||
mutex_lock(&open_close_lock);
|
mutex_lock(&radio->disconnect_lock);
|
||||||
radio->disconnected = 1;
|
radio->disconnected = 1;
|
||||||
cancel_delayed_work_sync(&radio->work);
|
cancel_delayed_work_sync(&radio->work);
|
||||||
usb_set_intfdata(intf, NULL);
|
usb_set_intfdata(intf, NULL);
|
||||||
if (radio->users == 0) {
|
if (radio->users == 0) {
|
||||||
video_unregister_device(radio->videodev);
|
video_unregister_device(radio->videodev);
|
||||||
kfree(radio->buffer);
|
kfree(radio->buffer);
|
||||||
kfree(radio);
|
kfree(radio);
|
||||||
}
|
}
|
||||||
mutex_unlock(&open_close_lock);
|
mutex_unlock(&radio->disconnect_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue