Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4623446pxj; Wed, 12 May 2021 09:27:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK+icE5J5pwlEaUmoj0mPz3ZKN1mTOr+5AOh6e/h1CG8mKM4l2A5tuN2Rnc5B/9iyE0rMI X-Received: by 2002:a05:6512:3d17:: with SMTP id d23mr22932147lfv.497.1620836866537; Wed, 12 May 2021 09:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836866; cv=none; d=google.com; s=arc-20160816; b=dYSYokbLKB4T/VaNrR4EtTXFQDxrDtSi3wPAAZwlsT8iWDR4thUM7NDAV1ZPcmU4vm DZ6HEAtBQmEzG0lQD2wZaYSUDLMP9PAb6ESEgTmMlgWV+9ab2NiT8vMGi2/brzoJ4cLv B0iGA2TViAJpdrN5++x+w2wIkz5er3GkwoBafHBxjySIncX6h0PWtbqRLBNcFJwLHZEK 1CO+6g4cDdCIvKYD0YRAkqULZorSfk2Vw1MHSaED7cxTkCaW4W9aDqcGPH0BMqhQ6D5k 0l+ovZ3c9fxTzmK2Dc8eZpl/qBgNqQ7TWvEY5WspYCJiU2UDwrZTqTuVNXgHAkFvrmeK pn0g== 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=pvSEZWV7OS9oKR37OdSuIUdXZRJGeyhl9PQteRF4mgk=; b=MINtIxACyl/LOaQtG8yTjUcZYspVBw5S+G2XVbSY/eQVtiHGO+lZ/PT1R1oyX8phZo ak+pcU+2Hr3E2RjKLsuBGyzTjp7NuNhnqc8PutmI6uiaYOspHiyHPLm08H7X2WZ7VrsC NHm6nkcquoGNoYWZZImlzur4ez5ci8/aN276pvKNez/tojxy118+VpdXHwIcOdsGR2pL 5FT6+8I/A5Oi5CEWfylkOWjEYnAtI4nh0UmoXg34H2anb/IxsAAyRRl+kkEC7pjshwYC B8vP0ZJXcPyGT0AuI1VWFOVskuJXr6w8eulilELUbYD/2YSzgNBcJLX1z5iWptbN5ueY 8d4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oixqpqwi; 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 b7si293380ljr.347.2021.05.12.09.27.08; Wed, 12 May 2021 09:27:46 -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=oixqpqwi; 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 S237012AbhELQYA (ORCPT + 99 others); Wed, 12 May 2021 12:24:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:56846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236166AbhELPhL (ORCPT ); Wed, 12 May 2021 11:37:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92CF961C4C; Wed, 12 May 2021 15:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832720; bh=D88ixJ3TB6aOw3FttnHzw1mcOI+ERkCWaxu5TMw17uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oixqpqwiC+iYLyZonx3Z+bVCBL4DpGld04uCmogfEWsDV6qHsteN+t9SG4ATsysbi IbTrtKJp1Awz0v2y3GFtccSuZJkA/X25MJxPwJWDrtTSA52VtUMf1hW3H2hDG1fTmS FfAmZQCUtXWk9Jp2FK7UyBRlmiETWZruVP4GEfxk= 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 5.10 395/530] ALSA: usb-audio: Add error checks for usb_driver_claim_interface() calls Date: Wed, 12 May 2021 16:48:25 +0200 Message-Id: <20210512144832.754538667@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 fc7c359ae215..258b81b39917 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -182,9 +182,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 && @@ -204,7 +203,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; @@ -864,7 +864,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; @@ -993,7 +993,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++) { @@ -1024,7 +1024,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 5ab2a4580bfb..bddef8ad5778 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -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; @@ -390,8 +394,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 9667060ff92b..e54a98f46549 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -63,6 +63,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...) \ -- 2.30.2