Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp318288pxj; Thu, 20 May 2021 10:01:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxc9xXzBbni+roTimjQtbjdESJKzC3dIqM8hbr/f6PfV4ZwjlhuGI3lNgaz8h6VnZPY7L9p X-Received: by 2002:a02:5d44:: with SMTP id w65mr7370747jaa.15.1621530100303; Thu, 20 May 2021 10:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621530100; cv=none; d=google.com; s=arc-20160816; b=Cx0S3laBxAtDZjo+0wg3p9RzaLz+JuLhGklziQcgr05iDTAXxTQJDGoZGZnSak0qrn /rdr4QbJi+bM6lclZxV4qVBK2yMEnr1V+QGLLbj1K9JfraoCz1L034HwWXmDWoDCrkPP 2qj+OlY3E+xPxtyv6lV2pIk2+cWvYy6pnIcBZ6iJ2aJ5ypjvMdFoAKSL5Ue318/5H0gD YaPGhlRocd8BPbcqOF/de7i2G88LfYu3SVyaxmTDbL1oB6hpKEbOtnx63bGyz9el+Fy9 1RSw9vKZkil+ADFHmfGohQa0hKDDZZZXbwKNYnD0NK9zvpdh71GkcjW37M0UIXMaUBpu wKWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tBuy+uvykQZZq/NoA2TxuWvNaa5ulFxHQTnkS1uojHM=; b=GLuAEe67AoI9HKlXyUk8hgN1O5+RoRC7Kbo1w98psklh6ERZH3fqq/CPcuPWHZPBMm XVXUVdsjtKXYJUmvhE+ZdNQVvEW7h5nIVCExMhPQ2YLArN7ve4S1S8hJg9ZJ/p644t55 orxQpmddowSoshbcPmt0aQmSvXXOdW1RWe9SgHbklyeN014aT4utQf1GR+LXa91RnJrm I78XB1SFGqViZdVVtcToPY+W6vmkxjXCw/Fjp3Tjt2QweNo6MvI4PWf1W3mTp42yzb5R fUUEikot/ePx9EMqV5G5BpA3Pb8ZT3hNd2ucgzipg6I2lb6pEOvfPw2HTdCDRt2f7RXP EOCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XDggh7jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si2819046ilo.151.2021.05.20.10.01.26; Thu, 20 May 2021 10:01:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XDggh7jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235378AbhETKIn (ORCPT + 99 others); Thu, 20 May 2021 06:08:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:37782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235135AbhETKC0 (ORCPT ); Thu, 20 May 2021 06:02:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F9D46191C; Thu, 20 May 2021 09:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503592; bh=NRsZnS6JN2e9ZfVYVSySoHClKGPFX+3St0fyqzLITzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDggh7jF6M+akuiYUeeCizJGTbtQWWUCO9VRd8ehXPlt/K07sw3WW+sC50WDmSn4W 8SbA5Yx76bYjJNbwURG2VRT8jkKYiuFexAwB7HZKSsOITtzxNdY/CEZrBgUKoNvEVI p2SqNZQcK9TwIZsfxSRC5iXXsHdfYcWvA21Qe8Qk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, coverity-bot , Takashi Iwai , Sasha Levin Subject: [PATCH 4.19 257/425] ALSA: usb-audio: Add error checks for usb_driver_claim_interface() calls Date: Thu, 20 May 2021 11:20:26 +0200 Message-Id: <20210520092139.883266950@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 5fb45414ae03421255593fd5556aa2d1d82303aa ] 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 Addresses-Coverity-ID: 1475943 ("Error handling issues") Addresses-Coverity-ID: 1475944 ("Error handling issues") Addresses-Coverity-ID: 1475945 ("Error handling issues") Fixes: b1ce7ba619d9 ("ALSA: usb-audio: claim autodetected PCM interfaces all at once") Fixes: e5779998bf8b ("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 Signed-off-by: Sasha Levin --- sound/usb/card.c | 14 +++++++------- sound/usb/quirks.c | 16 ++++++++++++---- sound/usb/usbaudio.h | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/sound/usb/card.c b/sound/usb/card.c index ba096cb4a53e..ce8925e8419e 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -189,9 +189,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 && @@ -211,7 +210,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; @@ -707,7 +707,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; @@ -807,7 +807,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++) { @@ -839,7 +839,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 */ diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 717edf3b5d3e..b5f2b18b8b42 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -66,8 +66,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; @@ -401,8 +405,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; diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 0d620c267e7a..0c7ea78317fc 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -68,6 +68,8 @@ struct snd_usb_audio { struct usb_host_interface *ctrl_intf; /* the audio control interface */ }; +#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...) \ -- 2.30.2