Re: Replace audio(9) get_props() with duplex check in open() for record-only drivers

2022-10-27 Thread Alexandre Ratchov
On Thu, Oct 27, 2022 at 08:28:53PM +, Klemens Nanni wrote:
> On Thu, Oct 27, 2022 at 03:49:55PM +0200, Alexandre Ratchov wrote:
> > On Thu, Oct 27, 2022 at 01:09:57PM +, Klemens Nanni wrote:
> > > @@ -1859,6 +1857,9 @@ utvfu_audio_open(void *v, int flags)
> > >   if (usbd_is_dying(sc->sc_udev))
> > >   return (EIO);
> > >  
> > > + if ((flags & (FWRITE | FREAD)))
> > > + return (ENXIO);
> > > +
> > >   if ((flags & FWRITE))
> > >   return (ENXIO);
> > >  
> > 
> > We already return ENXIO if playback is requested, so no need for the
> > additional full-duplex check
> 
> Yes.  My diff was purely mechanical and this single occasion does does
> not need an aditional check.
> 
> Feedback? OK?
> 

ok ratchov@

> ---
>  sys/dev/usb/utvfu.c | 8 
>  1 file changed, 8 deletions(-)
> 
> diff --git a/sys/dev/usb/utvfu.c b/sys/dev/usb/utvfu.c
> index 930f2d12568..37b76ffb285 100644
> --- a/sys/dev/usb/utvfu.c
> +++ b/sys/dev/usb/utvfu.c
> @@ -795,7 +795,6 @@ int   utvfu_audio_halt_in(void *);
>  int  utvfu_audio_mixer_set_port(void *, struct mixer_ctrl *);
>  int  utvfu_audio_mixer_get_port(void *, struct mixer_ctrl *);
>  int  utvfu_audio_query_devinfo(void *, struct mixer_devinfo *);
> -int  utvfu_audio_get_props(void *);
>  int  utvfu_audio_trigger_output(void *, void *, void *, int,
>   void (*)(void *), void *, struct audio_params *);
>  int  utvfu_audio_trigger_input(void *, void *, void *, int,
> @@ -851,7 +850,6 @@ const struct audio_hw_if utvfu_au_hw_if = {
>   .set_port = utvfu_audio_mixer_set_port,
>   .get_port = utvfu_audio_mixer_get_port,
>   .query_devinfo = utvfu_audio_query_devinfo,
> - .get_props = utvfu_audio_get_props,
>   .trigger_output = utvfu_audio_trigger_output,
>   .trigger_input = utvfu_audio_trigger_input,
>  };
> @@ -1995,12 +1993,6 @@ utvfu_audio_query_devinfo(void *v, struct 
> mixer_devinfo *mi)
>   return (0);
>  }
>  
> -int
> -utvfu_audio_get_props(void *v)
> -{
> - return (0);
> -}
> -
>  int
>  utvfu_audio_trigger_output(void *v, void *start, void *end, int blksize,
>  void (*intr)(void *), void *arg, struct audio_params *param)
> -- 
> 2.38.1
> 
> 



Re: Replace audio(9) get_props() with duplex check in open() for record-only drivers

2022-10-27 Thread Klemens Nanni
On Thu, Oct 27, 2022 at 03:49:55PM +0200, Alexandre Ratchov wrote:
> On Thu, Oct 27, 2022 at 01:09:57PM +, Klemens Nanni wrote:
> > @@ -1859,6 +1857,9 @@ utvfu_audio_open(void *v, int flags)
> > if (usbd_is_dying(sc->sc_udev))
> > return (EIO);
> >  
> > +   if ((flags & (FWRITE | FREAD)))
> > +   return (ENXIO);
> > +
> > if ((flags & FWRITE))
> > return (ENXIO);
> >  
> 
> We already return ENXIO if playback is requested, so no need for the
> additional full-duplex check

Yes.  My diff was purely mechanical and this single occasion does does
not need an aditional check.

Feedback? OK?

---
 sys/dev/usb/utvfu.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/sys/dev/usb/utvfu.c b/sys/dev/usb/utvfu.c
index 930f2d12568..37b76ffb285 100644
--- a/sys/dev/usb/utvfu.c
+++ b/sys/dev/usb/utvfu.c
@@ -795,7 +795,6 @@ int utvfu_audio_halt_in(void *);
 intutvfu_audio_mixer_set_port(void *, struct mixer_ctrl *);
 intutvfu_audio_mixer_get_port(void *, struct mixer_ctrl *);
 intutvfu_audio_query_devinfo(void *, struct mixer_devinfo *);
-intutvfu_audio_get_props(void *);
 intutvfu_audio_trigger_output(void *, void *, void *, int,
void (*)(void *), void *, struct audio_params *);
 intutvfu_audio_trigger_input(void *, void *, void *, int,
@@ -851,7 +850,6 @@ const struct audio_hw_if utvfu_au_hw_if = {
.set_port = utvfu_audio_mixer_set_port,
.get_port = utvfu_audio_mixer_get_port,
.query_devinfo = utvfu_audio_query_devinfo,
-   .get_props = utvfu_audio_get_props,
.trigger_output = utvfu_audio_trigger_output,
.trigger_input = utvfu_audio_trigger_input,
 };
@@ -1995,12 +1993,6 @@ utvfu_audio_query_devinfo(void *v, struct mixer_devinfo 
*mi)
return (0);
 }
 
-int
-utvfu_audio_get_props(void *v)
-{
-   return (0);
-}
-
 int
 utvfu_audio_trigger_output(void *v, void *start, void *end, int blksize,
 void (*intr)(void *), void *arg, struct audio_params *param)
-- 
2.38.1



Re: Replace audio(9) get_props() with duplex check in open() for record-only drivers

2022-10-27 Thread Alexandre Ratchov
On Thu, Oct 27, 2022 at 01:09:57PM +, Klemens Nanni wrote:
> @@ -1859,6 +1857,9 @@ utvfu_audio_open(void *v, int flags)
>   if (usbd_is_dying(sc->sc_udev))
>   return (EIO);
>  
> + if ((flags & (FWRITE | FREAD)))
> + return (ENXIO);
> +
>   if ((flags & FWRITE))
>   return (ENXIO);
>  

We already return ENXIO if playback is requested, so no need for the
additional full-duplex check



Replace audio(9) get_props() with duplex check in open() for record-only drivers

2022-10-27 Thread Klemens Nanni
Make drivers which do *not* adverise AUDIO_PROP_FULLDPLEX return ENXIO
in their open() if full-duplex mode was requested.

This way, sys/dev/audio.c:audio_open() will fail immediately rather than
later through the to-be-removed get_props() check.

utvfu(4) seems to be the only driver that currently supports recording
but not playing, so I just factored it out into its own diff.

Builds fine.
Feedback? Objection? OK?
---
 sys/dev/usb/utvfu.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/sys/dev/usb/utvfu.c b/sys/dev/usb/utvfu.c
index 930f2d12568..dc43144adac 100644
--- a/sys/dev/usb/utvfu.c
+++ b/sys/dev/usb/utvfu.c
@@ -795,7 +795,6 @@ int utvfu_audio_halt_in(void *);
 intutvfu_audio_mixer_set_port(void *, struct mixer_ctrl *);
 intutvfu_audio_mixer_get_port(void *, struct mixer_ctrl *);
 intutvfu_audio_query_devinfo(void *, struct mixer_devinfo *);
-intutvfu_audio_get_props(void *);
 intutvfu_audio_trigger_output(void *, void *, void *, int,
void (*)(void *), void *, struct audio_params *);
 intutvfu_audio_trigger_input(void *, void *, void *, int,
@@ -851,7 +850,6 @@ const struct audio_hw_if utvfu_au_hw_if = {
.set_port = utvfu_audio_mixer_set_port,
.get_port = utvfu_audio_mixer_get_port,
.query_devinfo = utvfu_audio_query_devinfo,
-   .get_props = utvfu_audio_get_props,
.trigger_output = utvfu_audio_trigger_output,
.trigger_input = utvfu_audio_trigger_input,
 };
@@ -1859,6 +1857,9 @@ utvfu_audio_open(void *v, int flags)
if (usbd_is_dying(sc->sc_udev))
return (EIO);
 
+   if ((flags & (FWRITE | FREAD)))
+   return (ENXIO);
+
if ((flags & FWRITE))
return (ENXIO);
 
@@ -1995,12 +1996,6 @@ utvfu_audio_query_devinfo(void *v, struct mixer_devinfo 
*mi)
return (0);
 }
 
-int
-utvfu_audio_get_props(void *v)
-{
-   return (0);
-}
-
 int
 utvfu_audio_trigger_output(void *v, void *start, void *end, int blksize,
 void (*intr)(void *), void *arg, struct audio_params *param)
-- 
2.38.1