Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp817116rwi; Wed, 19 Oct 2022 03:24:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bDuIKvWWb6sUHCOz+upgp72udhYg/Tyh/NODtOa1/LV11TV4SgbQ4vh+fnP1RK+dYoLXe X-Received: by 2002:a17:906:8a61:b0:78d:9d00:c906 with SMTP id hy1-20020a1709068a6100b0078d9d00c906mr6107408ejc.321.1666175090291; Wed, 19 Oct 2022 03:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666175090; cv=none; d=google.com; s=arc-20160816; b=zpTzilekN98ji7AswXvQuzUahr6k3gm1IxEbI8G0SvMTua1sibOro+DhfglWRfL1i5 bgVWNGWIuXx+OeFqpGY/J9lL0dDf4YRvXExZUGfaXVSAtXzySc47D5rl9sXXFn5WlhRi Si9W7t9tFX6VB9tzeTPbFaO3TJbqJrqXuQvdr0JenbFFQQ9ZSy0UfL0if11b3BlbvTvy kJS+x+nY9EOzVTP4UiFmd/dsIcuPubukkk5b10TNj+M+v48G03CPOxlNY8Jzw96NtDXG ns9AxZJlj98kEd7whIc5tL1Fx2KFuM9iEn+hNe58Ov8hzuAy5W6Wxu63O5earYHW4umT 0r4Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a170906c20600b0078d27c1c8f4si11299919ejz.696.2022.10.19.03.24.24; Wed, 19 Oct 2022 03:24:50 -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?q?Jos=C3=A9=20Exp=C3=B3sito?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; -- 2.35.1