All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch review 6/6] radio-mr800: redesign radio->users counter
@ 2009-08-08 17:46 Alexey Klimov
  2009-08-08 18:01 ` Trent Piepho
  2009-08-10 22:24 ` David Ellingsworth
  0 siblings, 2 replies; 7+ messages in thread
From: Alexey Klimov @ 2009-08-08 17:46 UTC (permalink / raw)
  To: Douglas Schilling Landgraf; +Cc: linux-media

Redesign radio->users counter. Don't allow more that 5 users on radio in
usb_amradio_open() and don't stop radio device if other userspace
application uses it in usb_amradio_close().

Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>

--
diff -r c2dd9da28106 linux/drivers/media/radio/radio-mr800.c
--- a/linux/drivers/media/radio/radio-mr800.c	Sat Aug 08 17:28:18 2009 +0400
+++ b/linux/drivers/media/radio/radio-mr800.c	Sat Aug 08 18:12:01 2009 +0400
@@ -540,7 +540,13 @@
 {
 	struct amradio_device *radio = video_get_drvdata(video_devdata(file));
 
-	radio->users = 1;
+	/* don't allow more than 5 users on radio */
+	if (radio->users > 4)
+		return -EBUSY;
+
+	mutex_lock(&radio->lock);
+	radio->users++;
+	mutex_unlock(&radio->lock);
 
 	return 0;
 }
@@ -554,9 +560,20 @@
 		return -ENODEV;
 
 	mutex_lock(&radio->lock);
-	radio->users = 0;
+	radio->users--;
 	mutex_unlock(&radio->lock);
 
+	/* In case several userspace applications opened the radio
+	 * and one of them closes and stops it,
+	 * we check if others use it and if they do we start the radio again. */
+	if (radio->users && radio->status == AMRADIO_STOP) {
+		int retval;
+		retval = amradio_set_mute(radio, AMRADIO_START);
+		if (retval < 0)
+			dev_warn(&radio->videodev->dev,
+				"amradio_start failed\n");
+	}
+
 	return 0;
 }
 


-- 
Best regards, Klimov Alexey


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-08 17:46 [patch review 6/6] radio-mr800: redesign radio->users counter Alexey Klimov
@ 2009-08-08 18:01 ` Trent Piepho
  2009-08-08 19:08   ` Alexey Klimov
  2009-08-10 22:24 ` David Ellingsworth
  1 sibling, 1 reply; 7+ messages in thread
From: Trent Piepho @ 2009-08-08 18:01 UTC (permalink / raw)
  To: Alexey Klimov; +Cc: Douglas Schilling Landgraf, linux-media

On Sat, 8 Aug 2009, Alexey Klimov wrote:
> Redesign radio->users counter. Don't allow more that 5 users on radio in

Why?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-08 18:01 ` Trent Piepho
@ 2009-08-08 19:08   ` Alexey Klimov
  2009-08-08 20:16     ` wk
  0 siblings, 1 reply; 7+ messages in thread
From: Alexey Klimov @ 2009-08-08 19:08 UTC (permalink / raw)
  To: Trent Piepho; +Cc: Douglas Schilling Landgraf, linux-media

On Sat, Aug 8, 2009 at 10:01 PM, Trent Piepho<xyzzy@speakeasy.org> wrote:
> On Sat, 8 Aug 2009, Alexey Klimov wrote:
>> Redesign radio->users counter. Don't allow more that 5 users on radio in
>
> Why?

Well, v4l2 specs says that multiple opens are optional. Honestly, i
think that five userspace applications open /dev/radio is enough. Btw,
if too many userspace applications opened radio that means that
something wrong happened in userspace. And driver can handle such
situation by disallowing new open calls(returning EBUSY). I can't
imagine user that runs more than five mplayers or gnomeradios, or
kradios and so on.

Am i totally wrong here?

Thanks.
-- 
Best regards, Klimov Alexey

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-08 19:08   ` Alexey Klimov
@ 2009-08-08 20:16     ` wk
  2009-08-09  8:19       ` Hans Verkuil
  0 siblings, 1 reply; 7+ messages in thread
From: wk @ 2009-08-08 20:16 UTC (permalink / raw)
  To: Alexey Klimov; +Cc: Trent Piepho, Douglas Schilling Landgraf, linux-media

Alexey Klimov schrieb:
> On Sat, Aug 8, 2009 at 10:01 PM, Trent Piepho<xyzzy@speakeasy.org> wrote:
>   
>> On Sat, 8 Aug 2009, Alexey Klimov wrote:
>>     
>>> Redesign radio->users counter. Don't allow more that 5 users on radio in
>>>       
>> Why?
>>     
>
> Well, v4l2 specs says that multiple opens are optional. Honestly, i
> think that five userspace applications open /dev/radio is enough. Btw,
> if too many userspace applications opened radio that means that
> something wrong happened in userspace. And driver can handle such
> situation by disallowing new open calls(returning EBUSY). I can't
> imagine user that runs more than five mplayers or gnomeradios, or
> kradios and so on.
>
> Am i totally wrong here?
>
> Thanks.
>   
"I can't imagine.." Funny answer, reminds at the 640kB limit of old 
computers.. :)
But if there's no real technical restriction, the driver should not 
restrict access a device at all.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-08 20:16     ` wk
@ 2009-08-09  8:19       ` Hans Verkuil
  2009-08-09 11:04         ` Alexey Klimov
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Verkuil @ 2009-08-09  8:19 UTC (permalink / raw)
  To: wk; +Cc: Alexey Klimov, Trent Piepho, Douglas Schilling Landgraf, linux-media

On Saturday 08 August 2009 22:16:28 wk wrote:
> Alexey Klimov schrieb:
> > On Sat, Aug 8, 2009 at 10:01 PM, Trent Piepho<xyzzy@speakeasy.org> wrote:
> >   
> >> On Sat, 8 Aug 2009, Alexey Klimov wrote:
> >>     
> >>> Redesign radio->users counter. Don't allow more that 5 users on radio in
> >>>       
> >> Why?
> >>     
> >
> > Well, v4l2 specs says that multiple opens are optional. Honestly, i
> > think that five userspace applications open /dev/radio is enough. Btw,
> > if too many userspace applications opened radio that means that
> > something wrong happened in userspace. And driver can handle such
> > situation by disallowing new open calls(returning EBUSY). I can't
> > imagine user that runs more than five mplayers or gnomeradios, or
> > kradios and so on.
> >
> > Am i totally wrong here?
> >
> > Thanks.
> >   
> "I can't imagine.." Funny answer, reminds at the 640kB limit of old 
> computers.. :)
> But if there's no real technical restriction, the driver should not 
> restrict access a device at all.

Exactly. It's an artificial restriction that serves no purpose. Also
remember that apps can open a radio device just to do e.g. a QUERYCAP
or something like that. It does not necessarily has to be an mplayer
or gnomeradio.

Regards,

	Hans

-- 
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-09  8:19       ` Hans Verkuil
@ 2009-08-09 11:04         ` Alexey Klimov
  0 siblings, 0 replies; 7+ messages in thread
From: Alexey Klimov @ 2009-08-09 11:04 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: wk, Trent Piepho, Douglas Schilling Landgraf, linux-media

On Sun, Aug 9, 2009 at 12:19 PM, Hans Verkuil<hverkuil@xs4all.nl> wrote:
> On Saturday 08 August 2009 22:16:28 wk wrote:
>> Alexey Klimov schrieb:
>> > On Sat, Aug 8, 2009 at 10:01 PM, Trent Piepho<xyzzy@speakeasy.org> wrote:
>> >
>> >> On Sat, 8 Aug 2009, Alexey Klimov wrote:
>> >>
>> >>> Redesign radio->users counter. Don't allow more that 5 users on radio in
>> >>>
>> >> Why?
>> >>
>> >
>> > Well, v4l2 specs says that multiple opens are optional. Honestly, i
>> > think that five userspace applications open /dev/radio is enough. Btw,
>> > if too many userspace applications opened radio that means that
>> > something wrong happened in userspace. And driver can handle such
>> > situation by disallowing new open calls(returning EBUSY). I can't
>> > imagine user that runs more than five mplayers or gnomeradios, or
>> > kradios and so on.
>> >
>> > Am i totally wrong here?
>> >
>> > Thanks.
>> >
>
> Exactly. It's an artificial restriction that serves no purpose. Also
> remember that apps can open a radio device just to do e.g. a QUERYCAP
> or something like that. It does not necessarily has to be an mplayer
> or gnomeradio.
>
> Regards,
>
>        Hans
>
> --
> Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom

Ok, i'll update the patch.
Idea initially came in mind from gspca.c.

-- 
Best regards, Klimov Alexey

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch review 6/6] radio-mr800: redesign radio->users counter
  2009-08-08 17:46 [patch review 6/6] radio-mr800: redesign radio->users counter Alexey Klimov
  2009-08-08 18:01 ` Trent Piepho
@ 2009-08-10 22:24 ` David Ellingsworth
  1 sibling, 0 replies; 7+ messages in thread
From: David Ellingsworth @ 2009-08-10 22:24 UTC (permalink / raw)
  To: Alexey Klimov; +Cc: Douglas Schilling Landgraf, linux-media

On Sat, Aug 8, 2009 at 1:46 PM, Alexey Klimov<klimov.linux@gmail.com> wrote:
> Redesign radio->users counter. Don't allow more that 5 users on radio in
> usb_amradio_open() and don't stop radio device if other userspace
> application uses it in usb_amradio_close().
>
> Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>
>
> --
> diff -r c2dd9da28106 linux/drivers/media/radio/radio-mr800.c
> --- a/linux/drivers/media/radio/radio-mr800.c   Sat Aug 08 17:28:18 2009 +0400
> +++ b/linux/drivers/media/radio/radio-mr800.c   Sat Aug 08 18:12:01 2009 +0400
> @@ -540,7 +540,13 @@
>  {
>        struct amradio_device *radio = video_get_drvdata(video_devdata(file));
>
> -       radio->users = 1;
> +       /* don't allow more than 5 users on radio */
> +       if (radio->users > 4)
> +               return -EBUSY;

I agree with what the others have said regarding this.. there should
be no such restriction here. The code is broken anyway as it doesn't
acquire the lock before checking the number of active users. So
technically, while you've tried to limit it to five, six, seven, or
more users could gain access to it under the right conditions.

> +
> +       mutex_lock(&radio->lock);
> +       radio->users++;
> +       mutex_unlock(&radio->lock);
>
>        return 0;
>  }
> @@ -554,9 +560,20 @@
>                return -ENODEV;
>
>        mutex_lock(&radio->lock);
> -       radio->users = 0;
> +       radio->users--;
>        mutex_unlock(&radio->lock);
>
> +       /* In case several userspace applications opened the radio
> +        * and one of them closes and stops it,
> +        * we check if others use it and if they do we start the radio again. */
> +       if (radio->users && radio->status == AMRADIO_STOP) {

More locking issues here as well. Two competing opens might both see
the status as stopped and both try to start the device.

> +               int retval;
> +               retval = amradio_set_mute(radio, AMRADIO_START);
> +               if (retval < 0)
> +                       dev_warn(&radio->videodev->dev,
> +                               "amradio_start failed\n");
> +       }
> +
>        return 0;
>  }
>

Regards,

David Ellingsworth

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-08-10 22:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-08 17:46 [patch review 6/6] radio-mr800: redesign radio->users counter Alexey Klimov
2009-08-08 18:01 ` Trent Piepho
2009-08-08 19:08   ` Alexey Klimov
2009-08-08 20:16     ` wk
2009-08-09  8:19       ` Hans Verkuil
2009-08-09 11:04         ` Alexey Klimov
2009-08-10 22:24 ` David Ellingsworth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.