From patchwork Wed Oct 19 08:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp215710wrs; Wed, 19 Oct 2022 02:16:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4pwn2VRXTJmsDMMZ5Q8wxYdmLZ//ksm6aSYgiS3HK7FZ+QDEvpqx2T8XfiGZtrsbxh5BQO X-Received: by 2002:a17:907:1b12:b0:72f:9b44:f9e with SMTP id mp18-20020a1709071b1200b0072f9b440f9emr5823661ejc.653.1666170986327; Wed, 19 Oct 2022 02:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170986; cv=none; d=google.com; s=arc-20160816; b=jm0FIFcr3EgkNv5AjEmvZDlm0oam9BWpWXdkX3M7TZFBO+/3NSV4AE4m7M1KdU7QMP T7gs3xtLdS5NAmQ4+fEvk97+4TGTFjayzTv8mIGUpzuPDCa0vOPvT6M23LuzNCo5J8eG 1J6Pf/gLJDIJI36WbLx4GTTdhL1BQ3nLol6E9GVz2yOgKSTnfOnYyuIYbPLRfSn+9zZD til/d+k3Qypd7wVzwjedNJi1FkaSyqFatDDXuYaarZx066dC2VJo6c/Apiakq7i1Ug3o FrYasOWMqxyYoDAhJ0EmB+i1Dp/AAooPkSM2Ei+jL7ogNuHfPjuO+QEvcoJbIJzn4Tvd JqHQ== 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=83DeWd0ZwpmvYfyS6ZBRkGkPhDiDs5QZWZa8ouDzNvM=; b=zyVbmTa7aceaUJhN80gUNZf0KrJNQo7pfl8sHq8znAF9wuIrwK1biMLrfIuhhAkgSY bF+pcwbd+tqP2ccJMy2KF3rSwDQdE23EiKXU6YngO4Sn9xyCyMOb/qnoNi2lDbdSlIeJ CIJrSGcHUbJJ+XGQ7YuqvqTmXs/pdxVzoB66hbUBU62U07B9z9oKoQ3XTS5dOmIRbQJu FzAfbUEoxJrCDyQA/WkY3ARfSNgWk4L12ePGWf2yTWc3AQiWBHQpXeRHAMiUOTTAFBMu S2mYWHxbY9ZWLCb2EzGty7JpKzxGn8t35YEAGRtIaivYPD5oEAgRHx3lRsr/wIR1KF2E KsMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UAa9DoDS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn20-20020a17090794d400b007123952b00dsi14032067ejc.100.2022.10.19.02.16.01; Wed, 19 Oct 2022 02:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UAa9DoDS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232819AbiJSJNa (ORCPT + 99 others); Wed, 19 Oct 2022 05:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232624AbiJSJK4 (ORCPT ); Wed, 19 Oct 2022 05:10:56 -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 D859595AD1; Wed, 19 Oct 2022 02:02:43 -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 13AF76170D; Wed, 19 Oct 2022 09:00:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27A5DC433C1; Wed, 19 Oct 2022 09:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170014; bh=f/k+s/t67tIsDk8B10xjJn1qqErzlt/ZonE+Si3m5Fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAa9DoDSSngy4K/RSKbTc96wFZv32ubHGDTt8u7EpWEP5pEn/VosRy+KyaHomW8H8 H77UYFl6pF9Rye4RAWilLx8QylhXhNpQILgt+M1QF05X8ABHwWxjsWz5mDAE/pN1kU w4xNarh+CdjMjUjHujQiuxwP1Uj6TReM6sfMrASk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= , Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 6.0 495/862] media: uvcvideo: Fix memory leak in uvc_gpio_parse Date: Wed, 19 Oct 2022 10:29:42 +0200 Message-Id: <20221019083311.844751745@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747106907891766626?= X-GMAIL-MSGID: =?utf-8?q?1747106907891766626?= From: José Expósito [ 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é Expósito 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 d509a4a2f08e..822e9694f092 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1553,10 +1553,6 @@ static int uvc_gpio_parse(struct uvc_device *dev) if (IS_ERR_OR_NULL(gpio_privacy)) return PTR_ERR_OR_ZERO(gpio_privacy); - unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); - if (!unit) - return -ENOMEM; - irq = gpiod_to_irq(gpio_privacy); if (irq < 0) { if (irq != EPROBE_DEFER) @@ -1565,6 +1561,10 @@ static int uvc_gpio_parse(struct uvc_device *dev) return irq; } + unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); + if (!unit) + return -ENOMEM; + unit->gpio.gpio_privacy = gpio_privacy; unit->gpio.irq = irq; unit->gpio.bControlSize = 1;