Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp557914pxj; Thu, 20 May 2021 16:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ9q99mo/cHA7hWWoVYDSdW6GmeTfFMGEIFAdKPNop/Oe6rlKaPnBzZSw9BMnmDLsjezo5 X-Received: by 2002:a17:906:7f8a:: with SMTP id f10mr6764175ejr.12.1621552264351; Thu, 20 May 2021 16:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552264; cv=none; d=google.com; s=arc-20160816; b=LiG0BqTyYAePrNUviAGFzItGg+sTZzBHDv5F8dRAZPMwm/SJQaLtbenHAdNU33+qLB RlLoV5GW6+ka2kjwQ58LjvKE6EZztPWFxiPloSy9Bh/wk1gGgkTybV4+Sll81Yb2qbm6 GjyXbsbWbypuAOP2O6/bfz2iwUeX8RO8sB5ni0c9w1xsCzshypZmUKVL7xvNPNh5YWsu KSJZ020yUlTWqytPTlpUO8f3M2NNW8sYxE0CLBemnJBX0srdYavvFDrmCVq98EBLoWHz zQcy/tyRtaHSItCz95oASUxwoiRNA4IRgAJ/E7tcMHGqkaQtsMlr7Fl90Lf///IS0fw2 7chw== 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=pEK1WDixsmbYKixaWFZ0TO8WC2j2rCXIADD2UyhWbp4=; b=LpaoDftZrb2Yz29YjsWyvoE3diPdow2UaTiLx4EXm5GD/f0cTZQgD5QCWfbRF0yXfM lKaZqurqOMCv0Kx8c4PjIuZdbfPY2V+E9hyxWSw7x3+UkNh4g2DxLlg62oVUzXOXbBCK IXhfN4hxUj+zepgEBENln9wDz4I0I1lWcpcH0ikUxR+PjInr9urpCjy33KMVVsOXmY72 z/vI/euI1bSF31aGvWWaH0zOYtOvH+7K2J4PaPKUButQ/arTyVMEc3NzRnaVy/0rEztF R6ffwn/ZuK1FgEK8HW/KaiWHhrFW/EmXMsXpZtPzLzzkFbV51S3U4t0JKgfn8oMZ1huA WWug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uKPzm43x; 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 bx19si3860319ejb.481.2021.05.20.16.10.38; Thu, 20 May 2021 16:11:04 -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=uKPzm43x; 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 S241092AbhETLVe (ORCPT + 99 others); Thu, 20 May 2021 07:21:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:56930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238887AbhETLBX (ORCPT ); Thu, 20 May 2021 07:01:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 36C34613BA; Thu, 20 May 2021 10:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505020; bh=E1W809uyxogZSo9nx0pCrvRwzInkqb4XT3Jul+EicyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uKPzm43xyQkRGdEGXPyqfwiEGsjEex9/9LlX9MEKIEYuNzeYqOYoysmBren19dYEZ MJw6j80VrM8rc049VI9wS+k0LL4sZmhPigY87bexmq1LEOehWosj+rLqAmY7NjxOsb crucg8JTQ3gcvkFmNKPmGn4pq5ARuLyhfb73G3I8= 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.9 143/240] ALSA: usb-audio: Add error checks for usb_driver_claim_interface() calls Date: Thu, 20 May 2021 11:22:15 +0200 Message-Id: <20210520092113.451337959@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 023a36a4922b..6c5be4e3cb9d 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -183,9 +183,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 && @@ -205,7 +204,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; @@ -665,7 +665,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; @@ -765,7 +765,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++) { @@ -795,7 +795,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 6b9e6b57d58d..02b4d0638e00 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; @@ -399,8 +403,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 f4ee83c8e0b2..62456a806bb4 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -63,6 +63,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