Skip to content

Commit

Permalink
ALSA: usb-audio: Add error checks for usb_driver_claim_interface() calls
Browse files Browse the repository at this point in the history
There are a few calls of usb_driver_claim_interface() but all of those
miss the proper error checks, as reported by Coverity.  This patch
adds those missing checks.

Along with it, replace the magic pointer with -1 with a constant
USB_AUDIO_IFACE_UNUSED for better readability.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1475943 ("Error handling issues")
Addresses-Coverity-ID: 1475944 ("Error handling issues")
Addresses-Coverity-ID: 1475945 ("Error handling issues")
Fixes: b1ce7ba ("ALSA: usb-audio: claim autodetected PCM interfaces all at once")
Fixes: e577999 ("ALSA: usb-audio: refactor code")
Link: https://lore.kernel.org/r/202104051059.FB7F3016@keescook
Link: https://lore.kernel.org/r/20210406113534.30455-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Apr 7, 2021
1 parent 53cc264 commit 5fb4541
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
ctrlif, interface);
return -EINVAL;
}
usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);

return 0;
return usb_driver_claim_interface(&usb_audio_driver, iface,
USB_AUDIO_IFACE_UNUSED);
}

if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
Expand All @@ -203,7 +202,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int

if (! snd_usb_parse_audio_interface(chip, interface)) {
usb_set_interface(dev, interface, 0); /* reset the current interface */
usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
return usb_driver_claim_interface(&usb_audio_driver, iface,
USB_AUDIO_IFACE_UNUSED);
}

return 0;
Expand Down Expand Up @@ -862,7 +862,7 @@ static void usb_audio_disconnect(struct usb_interface *intf)
struct snd_card *card;
struct list_head *p;

if (chip == (void *)-1L)
if (chip == USB_AUDIO_IFACE_UNUSED)
return;

card = chip->card;
Expand Down Expand Up @@ -992,7 +992,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
struct usb_mixer_interface *mixer;
struct list_head *p;

if (chip == (void *)-1L)
if (chip == USB_AUDIO_IFACE_UNUSED)
return 0;

if (!chip->num_suspended_intf++) {
Expand Down Expand Up @@ -1022,7 +1022,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
struct list_head *p;
int err = 0;

if (chip == (void *)-1L)
if (chip == USB_AUDIO_IFACE_UNUSED)
return 0;

atomic_inc(&chip->active); /* avoid autopm */
Expand Down
16 changes: 12 additions & 4 deletions sound/usb/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ static int create_composite_quirk(struct snd_usb_audio *chip,
if (!iface)
continue;
if (quirk->ifnum != probed_ifnum &&
!usb_interface_claimed(iface))
usb_driver_claim_interface(driver, iface, (void *)-1L);
!usb_interface_claimed(iface)) {
err = usb_driver_claim_interface(driver, iface,
USB_AUDIO_IFACE_UNUSED);
if (err < 0)
return err;
}
}

return 0;
Expand Down Expand Up @@ -426,8 +430,12 @@ static int create_autodetect_quirks(struct snd_usb_audio *chip,
continue;

err = create_autodetect_quirk(chip, iface, driver);
if (err >= 0)
usb_driver_claim_interface(driver, iface, (void *)-1L);
if (err >= 0) {
err = usb_driver_claim_interface(driver, iface,
USB_AUDIO_IFACE_UNUSED);
if (err < 0)
return err;
}
}

return 0;
Expand Down
2 changes: 2 additions & 0 deletions sound/usb/usbaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct snd_usb_audio {
struct media_intf_devnode *ctl_intf_media_devnode;
};

#define USB_AUDIO_IFACE_UNUSED ((void *)-1L)

#define usb_audio_err(chip, fmt, args...) \
dev_err(&(chip)->dev->dev, fmt, ##args)
#define usb_audio_warn(chip, fmt, args...) \
Expand Down

0 comments on commit 5fb4541

Please sign in to comment.