From patchwork Sat Oct 22 07:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1121172wrr; Sat, 22 Oct 2022 02:27:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QhJ3XYWXUXny3WgpOW9hpYc37DN7bYCvd7oMR7rkYi1WraBgdcX2QkyPaI4E9M07bC2kj X-Received: by 2002:a17:902:8549:b0:178:6399:3e0f with SMTP id d9-20020a170902854900b0017863993e0fmr23776030plo.35.1666430862609; Sat, 22 Oct 2022 02:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430862; cv=none; d=google.com; s=arc-20160816; b=xhoXcCWynt1dvEdxUBsg3XbQQFnVpV4JjcFl66/WUOGFB78htsCKnW/2iumRgzYqk8 RZvzW8GKS5VhQBNz+Erp+GCBtfjk2e31DW4zADDt8cP60ofeBg0ycHs8Hn9YzZKd5Kuw 8UiWbI3yOI+XsC9u5DMUS4AZJnrOvZwStHsf+XnixNryrU2Ev6yy6gE2zWYzikQ3MrGw znkoO1ubqotz1XCzCwpjYOH4cSoYBJxFXUE5DJGhf5ma906hbxW8KkubOZKP7AM5waTF DSLOksxeMGVSfeEWqsR6AGcW1pEDN30qVV6DtbtLa+7mONx0dfZ5aZtnRiUQJT9Eyc1C Pmxw== 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=vPmUZR37KVt48WYO+HoY6W2LnkjmmRglasnRjQn55o8=; b=xmEpAvV+sJE44MkKhB+khZY3rCk5XnQBP3rNybVb8DGwDoC1d3/CAE11vT0oDxChMu 6CozHEQmP+N6etKoIctierhbZekZV9OSfSsD7LZTNh/4bQD7n3D0xppcphBa5l4u3L3d 3USm2L5jhaR3cDiLuvED+88UyLO0Wa8v6hLnlWkiiYckjSPPEz6UYyAhrfERQB5ti3A9 swQWg3GjhmYN3ljJYXYsQpb7vZnIqBJrywFl2jDb79jUOUC1FTKKjuP1kzVO6pVF1KOh ZhMAFZwv4eS1GsleH1I+QBMzlAj4mkChQU4Kj76YuXR9gSuQu+w3z2V4Fd2P2NuMj+xs cuHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IbdR4liL; 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 j197-20020a636ece000000b004625c2dbc5csi28056310pgc.718.2022.10.22.02.27.30; Sat, 22 Oct 2022 02:27:42 -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=IbdR4liL; 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 S229728AbiJVJFv (ORCPT + 99 others); Sat, 22 Oct 2022 05:05:51 -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?b?Sm9zw6kgRXhww7NzaXRv?= , 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 X-Spam-Status: No, score=-7.3 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?1747379408259403047?= X-GMAIL-MSGID: =?utf-8?q?1747379408259403047?= 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 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); - 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) @@ -1550,6 +1546,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;