Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2720413pxy; Mon, 3 May 2021 06:37:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyL2Ea4xqHqYOZ960KjSZwoPAweQ8zwj6LZBGuTLtKrX/l6j2qDV4aqLx3jYKzdh8dmerj X-Received: by 2002:a62:170e:0:b029:1fa:7161:fd71 with SMTP id 14-20020a62170e0000b02901fa7161fd71mr18538419pfx.35.1620049078997; Mon, 03 May 2021 06:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620049078; cv=none; d=google.com; s=arc-20160816; b=A1LpVP4KW2X98IlrmZvASQg6z0qp6Ud7zS+nhZDlSMMj2XTlMp9YkWMATFY6QW/CqU wo4kxInvlpL7fz696EGBDglIcjO6FQYuFb0sHQSFW9nJiyh9qVQpnqcLznBGHWZglya1 aubf6Yoz1XiMGLx23H9ePqKWhXmQUmiM+mq+LW80liqOPj6NUJQZxI9/YxgiE8NHC/xD 42h45F4Y08i41ZKhAi2sOuDQNFBRp0nsGk4WkZ6HdGHXeAgV+6RVWK9e5d/VqQLnFHza ZjW3K1ptq449uBhx33SIkz2JKEUySwiKH647N9Ngijs/M0PK+fI8wC3Sfoc1FoHCvDJX jd0Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2V6Qpy9S+N88MxMtNFDPlP+hPI+c7ble0RpGjUdoGC0=; b=BjRPjYEOyyghpKPMD3zDt31RufIxHx3EfLijIH76Q2zyfb8ou6JSYtguhqRMRwzBlt 9eQlPzF5o6X1hAWeYOfepQU9+MfnhXJkiRx6MxqQUD0e09fnmOzZQLxCFuSOF4ii+HDg uNgBNuyUt/N8fUoQg1Y8WjJ1ouQE0D6wn5DIkXo7szJyqMjNmqIQyjkXyh+rRO9vJoT/ 0xxsXJfKO2q14Hv4jn/MMTqxlV+irHIKdfPtuLXzwISEzgXwi4fJ+4YBaHd5vR9jSiV0 Pp1nBJ8f65PnbL93dZop+VpORV6++MbeIXTrLx9oavE98fWZgHolWNeysTvNtgMLML95 +z7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eXil3EOp; 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 z4si17385834pgu.473.2021.05.03.06.37.46; Mon, 03 May 2021 06:37:58 -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=eXil3EOp; 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 S234233AbhECMDS (ORCPT + 99 others); Mon, 3 May 2021 08:03:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:36216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233847AbhECMB7 (ORCPT ); Mon, 3 May 2021 08:01:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A92B56135F; Mon, 3 May 2021 12:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620043266; bh=pXUEDcWhibUjxVw0FrtdRnk9h/zPgVPVi1p0eh0J+DI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXil3EOpOhHhdBxUMFD74Bb+WqGLsodpjQqt/H6qfZOuNr4W5F1wggW5nZv4MMEf7 xGMvElcxOZtuiOu+AGRomOUYzYRv3SoNES3pLn4bNzr7QCeu1XuSv2Rk+aCuF7nFS8 CFfBsIaOCRlxI5YMu5uTekwCkdrKe63hRehMj/UY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Takashi Iwai , Jaroslav Kysela Subject: [PATCH 37/69] ALSA: usx2y: check for failure of usb_alloc_urb() Date: Mon, 3 May 2021 13:57:04 +0200 Message-Id: <20210503115736.2104747-38-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503115736.2104747-1-gregkh@linuxfoundation.org> References: <20210503115736.2104747-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While it is almost impossible to hit an error calling usb_alloc_urb(), to make systems like syzbot which does error injection, and some static analysis tools happy, properly handle errors on this path by unwinding the previously allocated urbs and freeing them. Cc: Takashi Iwai Cc: Jaroslav Kysela Signed-off-by: Greg Kroah-Hartman --- sound/usb/usx2y/usb_stream.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c index 6bba17bf689a..1091ea96a29a 100644 --- a/sound/usb/usx2y/usb_stream.c +++ b/sound/usb/usx2y/usb_stream.c @@ -88,18 +88,35 @@ static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, sizeof(struct usb_stream_packet) * s->inpackets; int u; + int i; + int err = -ENOMEM; for (u = 0; u < USB_STREAM_NURBS; ++u) { + sk->outurb[u] = NULL; sk->inurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL); + if (!sk->inurb[u]) + goto error; sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL); + if (!sk->outurb[u]) + goto error; } + u--; if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) || init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev, - out_pipe)) - return -EINVAL; + out_pipe)) { + err = -EINVAL; + goto error; + } return 0; + +error: + for (i = 0; i <= u; ++i) { + usb_free_urb(sk->inurb[i]); + usb_free_urb(sk->outurb[i]); + } + return err; } -- 2.31.1