All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: alsa-devel@alsa-project.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Jesus Ramos <jesus-ramos@live.com>,
	johan.hedberg@gmail.com, Chris Wulff <crwulff@gmail.com>,
	Nick Kossifidis <mickflemm@gmail.com>,
	marcel@holtmann.org, linux-usb@vger.kernel.org,
	Dmitry Panchenko <dmitry@d-systems.ee>,
	linux-kernel@vger.kernel.org, Jussi Laako <jussi@sonarnerd.net>,
	linux-bluetooth@vger.kernel.org,
	Eli Billauer <eli.billauer@gmail.com>,
	Emiliano Ingrassia <ingrassia@epigenesys.com>,
	Alexander Tsoy <alexander@tsoy.me>,
	tiwai@suse.com, "Geoffrey D. Bennett" <g@b4.vu>,
	dvyukov@google.com, himadrispandya@gmail.com
Subject: Re: [PATCH 01/10] USB: move snd_usb_pipe_sanity_check into the USB core
Date: Thu, 3 Sep 2020 09:32:30 +0200	[thread overview]
Message-ID: <20200903073230.GA162335@kroah.com> (raw)
In-Reply-To: <20200903004553.GA642955@rowland.harvard.edu>

On Wed, Sep 02, 2020 at 08:45:53PM -0400, Alan Stern wrote:
> On Wed, Sep 02, 2020 at 01:01:03PM +0200, Greg Kroah-Hartman wrote:
> > snd_usb_pipe_sanity_check() is a great function, so let's move it into
> > the USB core so that other parts of the kernel, including the USB core,
> > can call it.
> > 
> > Name it usb_pipe_type_check() to match the existing
> > usb_urb_ep_type_check() call, which now uses this function.
> > 
> > Cc: Jaroslav Kysela <perex@perex.cz>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> > Cc: Eli Billauer <eli.billauer@gmail.com>
> > Cc: Emiliano Ingrassia <ingrassia@epigenesys.com>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: Alexander Tsoy <alexander@tsoy.me>
> > Cc: "Geoffrey D. Bennett" <g@b4.vu>
> > Cc: Jussi Laako <jussi@sonarnerd.net>
> > Cc: Nick Kossifidis <mickflemm@gmail.com>
> > Cc: Dmitry Panchenko <dmitry@d-systems.ee>
> > Cc: Chris Wulff <crwulff@gmail.com>
> > Cc: Jesus Ramos <jesus-ramos@live.com>
> > Cc: linux-usb@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Cc: alsa-devel@alsa-project.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> 
> > diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
> > index 27e83e55a590..45bc2914c1ba 100644
> > --- a/drivers/usb/core/urb.c
> > +++ b/drivers/usb/core/urb.c
> > @@ -192,24 +192,39 @@ static const int pipetypes[4] = {
> >  };
> >  
> >  /**
> > - * usb_urb_ep_type_check - sanity check of endpoint in the given urb
> > - * @urb: urb to be checked
> > + * usb_pipe_type_check - sanity check of a specific pipe for a usb device
> > + * @dev: struct usb_device to be checked
> > + * @pipe: pipe to check
> >   *
> >   * This performs a light-weight sanity check for the endpoint in the
> > - * given urb.  It returns 0 if the urb contains a valid endpoint, otherwise
> > - * a negative error code.
> > + * given usb device.  It returns 0 if the pipe is a valid for the specific usb
> -----------------------------------------------------^
> Typo.

Oops, will fix, thanks.


> 
> > + * device, otherwise a negative error code.
> >   */
> > -int usb_urb_ep_type_check(const struct urb *urb)
> > +int usb_pipe_type_check(struct usb_device *dev, unsigned int pipe)
> >  {
> >  	const struct usb_host_endpoint *ep;
> >  
> > -	ep = usb_pipe_endpoint(urb->dev, urb->pipe);
> > +	ep = usb_pipe_endpoint(dev, pipe);
> >  	if (!ep)
> >  		return -EINVAL;
> > -	if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
> > +	if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
> >  		return -EINVAL;
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(usb_pipe_type_check);
> > +
> > +/**
> > + * usb_urb_ep_type_check - sanity check of endpoint in the given urb
> > + * @urb: urb to be checked
> > + *
> > + * This performs a light-weight sanity check for the endpoint in the
> > + * given urb.  It returns 0 if the urb contains a valid endpoint, otherwise
> > + * a negative error code.
> > + */
> > +int usb_urb_ep_type_check(const struct urb *urb)
> > +{
> > +	return usb_pipe_type_check(urb->dev, urb->pipe);
> > +}
> >  EXPORT_SYMBOL_GPL(usb_urb_ep_type_check);
> 
> Since this routine is used in only one place in the entire kernel, you 
> might as well inline the code there and get rid of the function 
> entirely.

Good idea, will do.

> > diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
> > index abf99b814a0f..fc3aab04a0bc 100644
> > --- a/sound/usb/quirks.c
> > +++ b/sound/usb/quirks.c
> > @@ -846,7 +846,7 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
> >  	static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
> >  	void *buf;
> >  
> > -	if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x05)))
> > +	if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x05)))
> >  		return -EINVAL;
> >  	buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
> >  	if (!buf)
> > @@ -875,7 +875,7 @@ static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
> >  {
> >  	int ret;
> >  
> > -	if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0)))
> > +	if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
> >  		return -EINVAL;
> 
> In a few places here this check is completely unnecessary.  All it does 
> is verify that the device does have an endpoint 0 and the the type of 
> the endpoint matches the type of the pipe.  Well, every USB device 
> always has an endpoint 0, and it is always a bidirectional control 
> endpoint.

I think this was probably added to handle syzbot issues.  As long as the
USB core does ensure that a USB device has endpoint 0, I agree, these
can be removed.  I'll go check that and add a follow-on patch to the
series to do this, thanks.

thanks,

greg k-h

WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: himadrispandya@gmail.com, dvyukov@google.com,
	linux-usb@vger.kernel.org, perex@perex.cz, tiwai@suse.com,
	linux-kernel@vger.kernel.org, marcel@holtmann.org,
	johan.hedberg@gmail.com, linux-bluetooth@vger.kernel.org,
	alsa-devel@alsa-project.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Eli Billauer <eli.billauer@gmail.com>,
	Emiliano Ingrassia <ingrassia@epigenesys.com>,
	Alexander Tsoy <alexander@tsoy.me>,
	"Geoffrey D. Bennett" <g@b4.vu>,
	Jussi Laako <jussi@sonarnerd.net>,
	Nick Kossifidis <mickflemm@gmail.com>,
	Dmitry Panchenko <dmitry@d-systems.ee>,
	Chris Wulff <crwulff@gmail.com>,
	Jesus Ramos <jesus-ramos@live.com>
Subject: Re: [PATCH 01/10] USB: move snd_usb_pipe_sanity_check into the USB core
Date: Thu, 3 Sep 2020 09:32:30 +0200	[thread overview]
Message-ID: <20200903073230.GA162335@kroah.com> (raw)
In-Reply-To: <20200903004553.GA642955@rowland.harvard.edu>

On Wed, Sep 02, 2020 at 08:45:53PM -0400, Alan Stern wrote:
> On Wed, Sep 02, 2020 at 01:01:03PM +0200, Greg Kroah-Hartman wrote:
> > snd_usb_pipe_sanity_check() is a great function, so let's move it into
> > the USB core so that other parts of the kernel, including the USB core,
> > can call it.
> > 
> > Name it usb_pipe_type_check() to match the existing
> > usb_urb_ep_type_check() call, which now uses this function.
> > 
> > Cc: Jaroslav Kysela <perex@perex.cz>
> > Cc: Takashi Iwai <tiwai@suse.com>
> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> > Cc: Eli Billauer <eli.billauer@gmail.com>
> > Cc: Emiliano Ingrassia <ingrassia@epigenesys.com>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: Alexander Tsoy <alexander@tsoy.me>
> > Cc: "Geoffrey D. Bennett" <g@b4.vu>
> > Cc: Jussi Laako <jussi@sonarnerd.net>
> > Cc: Nick Kossifidis <mickflemm@gmail.com>
> > Cc: Dmitry Panchenko <dmitry@d-systems.ee>
> > Cc: Chris Wulff <crwulff@gmail.com>
> > Cc: Jesus Ramos <jesus-ramos@live.com>
> > Cc: linux-usb@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Cc: alsa-devel@alsa-project.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> 
> > diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
> > index 27e83e55a590..45bc2914c1ba 100644
> > --- a/drivers/usb/core/urb.c
> > +++ b/drivers/usb/core/urb.c
> > @@ -192,24 +192,39 @@ static const int pipetypes[4] = {
> >  };
> >  
> >  /**
> > - * usb_urb_ep_type_check - sanity check of endpoint in the given urb
> > - * @urb: urb to be checked
> > + * usb_pipe_type_check - sanity check of a specific pipe for a usb device
> > + * @dev: struct usb_device to be checked
> > + * @pipe: pipe to check
> >   *
> >   * This performs a light-weight sanity check for the endpoint in the
> > - * given urb.  It returns 0 if the urb contains a valid endpoint, otherwise
> > - * a negative error code.
> > + * given usb device.  It returns 0 if the pipe is a valid for the specific usb
> -----------------------------------------------------^
> Typo.

Oops, will fix, thanks.


> 
> > + * device, otherwise a negative error code.
> >   */
> > -int usb_urb_ep_type_check(const struct urb *urb)
> > +int usb_pipe_type_check(struct usb_device *dev, unsigned int pipe)
> >  {
> >  	const struct usb_host_endpoint *ep;
> >  
> > -	ep = usb_pipe_endpoint(urb->dev, urb->pipe);
> > +	ep = usb_pipe_endpoint(dev, pipe);
> >  	if (!ep)
> >  		return -EINVAL;
> > -	if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
> > +	if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
> >  		return -EINVAL;
> >  	return 0;
> >  }
> > +EXPORT_SYMBOL_GPL(usb_pipe_type_check);
> > +
> > +/**
> > + * usb_urb_ep_type_check - sanity check of endpoint in the given urb
> > + * @urb: urb to be checked
> > + *
> > + * This performs a light-weight sanity check for the endpoint in the
> > + * given urb.  It returns 0 if the urb contains a valid endpoint, otherwise
> > + * a negative error code.
> > + */
> > +int usb_urb_ep_type_check(const struct urb *urb)
> > +{
> > +	return usb_pipe_type_check(urb->dev, urb->pipe);
> > +}
> >  EXPORT_SYMBOL_GPL(usb_urb_ep_type_check);
> 
> Since this routine is used in only one place in the entire kernel, you 
> might as well inline the code there and get rid of the function 
> entirely.

Good idea, will do.

> > diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
> > index abf99b814a0f..fc3aab04a0bc 100644
> > --- a/sound/usb/quirks.c
> > +++ b/sound/usb/quirks.c
> > @@ -846,7 +846,7 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
> >  	static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
> >  	void *buf;
> >  
> > -	if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x05)))
> > +	if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x05)))
> >  		return -EINVAL;
> >  	buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
> >  	if (!buf)
> > @@ -875,7 +875,7 @@ static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
> >  {
> >  	int ret;
> >  
> > -	if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0)))
> > +	if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
> >  		return -EINVAL;
> 
> In a few places here this check is completely unnecessary.  All it does 
> is verify that the device does have an endpoint 0 and the the type of 
> the endpoint matches the type of the pipe.  Well, every USB device 
> always has an endpoint 0, and it is always a bidirectional control 
> endpoint.

I think this was probably added to handle syzbot issues.  As long as the
USB core does ensure that a USB device has endpoint 0, I agree, these
can be removed.  I'll go check that and add a follow-on patch to the
series to do this, thanks.

thanks,

greg k-h

  parent reply	other threads:[~2020-09-03  7:33 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 11:01 [PATCH 00/10] USB: new USB control message helper functions Greg Kroah-Hartman
2020-09-02 11:01 ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 01/10] USB: move snd_usb_pipe_sanity_check into the USB core Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:35   ` Takashi Iwai
2020-09-02 14:35     ` Takashi Iwai
2020-09-07 14:42     ` Greg Kroah-Hartman
2020-09-07 14:42       ` Greg Kroah-Hartman
2020-09-03  0:45   ` Alan Stern
2020-09-03  0:45     ` Alan Stern
2020-09-03  6:40     ` Takashi Iwai
2020-09-03  6:40       ` Takashi Iwai
2020-09-03  7:32     ` Greg Kroah-Hartman [this message]
2020-09-03  7:32       ` Greg Kroah-Hartman
2020-09-07 14:16       ` Greg Kroah-Hartman
2020-09-07 14:16         ` Greg Kroah-Hartman
2020-09-07 14:24         ` Alan Stern
2020-09-07 14:24           ` Alan Stern
2020-09-02 11:01 ` [PATCH 02/10] USB: add usb_control_msg_send() and usb_control_msg_recv() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 03/10] USB: core: message.c: use usb_control_msg_send() in a few places Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 11:23   ` Andy Shevchenko
2020-09-02 11:23     ` Andy Shevchenko
2020-09-02 11:01 ` [PATCH 04/10] USB: core: hub.c: " Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:57   ` Alan Stern
2020-09-02 14:57     ` Alan Stern
2020-09-02 15:21     ` Greg Kroah-Hartman
2020-09-02 15:21       ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 05/10] USB: legousbtower: use usb_control_msg_recv() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 06/10] sound: usx2y: move to use usb_control_msg_send() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:36   ` Takashi Iwai
2020-09-02 14:36     ` Takashi Iwai
2020-09-02 11:01 ` [PATCH 07/10] sound: 6fire: move to use usb_control_msg_send() and usb_control_msg_recv() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:36   ` Takashi Iwai
2020-09-02 14:36     ` Takashi Iwai
2020-09-02 11:01 ` [PATCH 7/9] sound: line6: convert to use new usb control function Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:41   ` Takashi Iwai
2020-09-02 14:41     ` Takashi Iwai
2020-09-02 15:22     ` Greg Kroah-Hartman
2020-09-02 15:22       ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 8/9] sound: 6fire: move to use new usb control functions Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 08/10] sound: line6: move to use usb_control_msg_send() and usb_control_msg_recv() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:38   ` Takashi Iwai
2020-09-02 14:38     ` Takashi Iwai
2020-09-02 11:01 ` [PATCH 9/9] sound: hiface: convert to use new usb_control functions Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 11:01 ` [PATCH 09/10] sound: hiface: move to use usb_control_msg_send() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman
2020-09-02 14:40   ` Takashi Iwai
2020-09-02 14:40     ` Takashi Iwai
2020-09-02 11:01 ` [PATCH 10/10] Bluetooth: ath3k: use usb_control_msg_send() and usb_control_msg_recv() Greg Kroah-Hartman
2020-09-02 11:01   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200903073230.GA162335@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander@tsoy.me \
    --cc=alsa-devel@alsa-project.org \
    --cc=crwulff@gmail.com \
    --cc=dmitry@d-systems.ee \
    --cc=dvyukov@google.com \
    --cc=eli.billauer@gmail.com \
    --cc=g@b4.vu \
    --cc=gustavoars@kernel.org \
    --cc=himadrispandya@gmail.com \
    --cc=ingrassia@epigenesys.com \
    --cc=jesus-ramos@live.com \
    --cc=johan.hedberg@gmail.com \
    --cc=jussi@sonarnerd.net \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=mickflemm@gmail.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.