From nobody Fri Dec 19 20:06:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 378ECC04A95 for ; Sat, 22 Oct 2022 09:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231582AbiJVJFw (ORCPT ); Sat, 22 Oct 2022 05:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235182AbiJVJD7 (ORCPT ); Sat, 22 Oct 2022 05:03:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983142DCB14; Sat, 22 Oct 2022 01:19:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E54360B46; Sat, 22 Oct 2022 07:52:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F278C433D6; Sat, 22 Oct 2022 07:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425131; bh=2YJw/yBjlgev6diveFfBgF/728Fx9jneejbWKbbzwbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbdR4liLH00bcVwx/JynChDwrr4CJn7r5tbbj2Z1Z+tTWwcyWIZMjbm0A0fWfcRv9 X4RF/BlthOOLZQ53PUAZrl/aFYTnd8M2/FTS7VrVtZq8jm24p1qmIgSlcW0rAsF2Bn HaD6MHLc8v1aaRAYzXWthw6lZjeVztOSn7ReonKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.19 401/717] media: uvcvideo: Fix memory leak in uvc_gpio_parse Date: Sat, 22 Oct 2022 09:24:40 +0200 Message-Id: <20221022072515.606512137@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jos=C3=A9 Exp=C3=B3sito [ Upstream commit f0f078457f18f10696888f8d0e6aba9deb9cde92 ] Previously the unit buffer was allocated before checking the IRQ for privacy GPIO. In case of error, the unit buffer was leaked. Allocate the unit buffer after the IRQ to avoid it. Addresses-Coverity-ID: 1474639 ("Resource leak") Fixes: 2886477ff987 ("media: uvcvideo: Implement UVC_EXT_GPIO_UNIT") Signed-off-by: Jos=C3=A9 Exp=C3=B3sito Reviewed-by: Ricardo Ribalda Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_driver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index 6c86faecbea2..28ee45e879ff 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1538,10 +1538,6 @@ static int uvc_gpio_parse(struct uvc_device *dev) if (IS_ERR_OR_NULL(gpio_privacy)) return PTR_ERR_OR_ZERO(gpio_privacy); =20 - unit =3D uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); - if (!unit) - return -ENOMEM; - irq =3D gpiod_to_irq(gpio_privacy); if (irq < 0) { if (irq !=3D EPROBE_DEFER) @@ -1550,6 +1546,10 @@ static int uvc_gpio_parse(struct uvc_device *dev) return irq; } =20 + unit =3D uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); + if (!unit) + return -ENOMEM; + unit->gpio.gpio_privacy =3D gpio_privacy; unit->gpio.irq =3D irq; unit->gpio.bControlSize =3D 1; --=20 2.35.1