USB: move snd_usb_pipe_sanity_check into the USB core

[ Upstream commit fcc2cc1f35613c016e1de25bb001bfdd9eaa25f9 ]

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 <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: Eli Billauer <[email protected]>
Cc: Emiliano Ingrassia <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Alexander Tsoy <[email protected]>
Cc: "Geoffrey D. Bennett" <[email protected]>
Cc: Jussi Laako <[email protected]>
Cc: Nick Kossifidis <[email protected]>
Cc: Dmitry Panchenko <[email protected]>
Cc: Chris Wulff <[email protected]>
Cc: Jesus Ramos <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Stable-dep-of: 2052138b7da5 ("media: dvb-usb: Fix unexpected infinite loop in dvb_usb_read_remote_control()")
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
Greg Kroah-Hartman 2020-09-14 17:37:46 +02:00
commit 5f6aeae1e7
6 changed files with 32 additions and 31 deletions

View file

@ -63,20 +63,6 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype
return NULL;
}
/* check the validity of pipe and EP types */
int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe)
{
static const int pipetypes[4] = {
PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
};
struct usb_host_endpoint *ep;
ep = usb_pipe_endpoint(dev, pipe);
if (!ep || usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
return -EINVAL;
return 0;
}
/*
* Wrapper for usb_control_msg().
* Allocates a temp buffer to prevent dmaing from/to the stack.
@ -89,7 +75,7 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
void *buf = NULL;
int timeout;
if (snd_usb_pipe_sanity_check(dev, pipe))
if (usb_pipe_type_check(dev, pipe))
return -EINVAL;
if (size > 0) {

View file

@ -7,7 +7,6 @@ unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size);
void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype);
void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype);
int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe);
int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
__u8 request, __u8 requesttype, __u16 value, __u16 index,
void *data, __u16 size);

View file

@ -1988,7 +1988,7 @@ static int scarlett2_mixer_status_create(struct usb_mixer_interface *mixer)
return 0;
}
if (snd_usb_pipe_sanity_check(dev, pipe))
if (usb_pipe_type_check(dev, pipe))
return -EINVAL;
mixer->urb = usb_alloc_urb(0, GFP_KERNEL);

View file

@ -854,7 +854,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)
@ -883,7 +883,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;
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@ -992,7 +992,7 @@ static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0)))
if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
return -EINVAL;
/* If the Axe-Fx III has not fully booted, it will timeout when trying
* to enable the audio streaming interface. A more generous timeout is
@ -1026,7 +1026,7 @@ static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf,
{
int err, actual_length;
if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x01)))
if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x01)))
return -EINVAL;
err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x01), buf, *length,
&actual_length, 1000);
@ -1038,7 +1038,7 @@ static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf,
memset(buf, 0, buf_size);
if (snd_usb_pipe_sanity_check(dev, usb_rcvintpipe(dev, 0x82)))
if (usb_pipe_type_check(dev, usb_rcvintpipe(dev, 0x82)))
return -EINVAL;
err = usb_interrupt_msg(dev, usb_rcvintpipe(dev, 0x82), buf, buf_size,
&actual_length, 1000);
@ -1125,7 +1125,7 @@ static int snd_usb_motu_m_series_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;
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1, USB_TYPE_VENDOR | USB_RECIP_DEVICE,