From patchwork Mon Oct 24 11:30:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp643945wru; Mon, 24 Oct 2022 13:43:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7789ZK1nmLbkaEzuydq5V0pMhh38kQCfAh8eELOyXXELMpT831el06O/OqJGoPBmL/yepV X-Received: by 2002:a17:90a:e606:b0:212:f100:22e3 with SMTP id j6-20020a17090ae60600b00212f10022e3mr13211712pjy.83.1666644205192; Mon, 24 Oct 2022 13:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666644205; cv=none; d=google.com; s=arc-20160816; b=zzuX5UcgVvKiCAT/j0pZkjPsm9LxY2uE9Ea/lBuRp2YsENJHMPYkSW+xiXte4iDL/B pdET0FyHjV/CFK6fDVDD4sh5g85AenZSrFnK6hKyIS1Xm/FALp+5WbMp3QYTW62ZOtPA wVKjJ1kVN4y1cZDhpIcRNKVc9f8gr4096SIrQBuoq/Iorv5XCfME8+WwhjXivCwCn33E OqssvCSgP4RHegq3TPmdD3OR78lg39y3cCMF3DGnntKTsZoJpjJQ6QnO93f9XZDVA3Qq Mn5HZuwoxTorzZCbeLRYIgIxMaV2OMZaw0HJua2YV4+ViW6wpN4aXeV2E97f1Z/rER/m 2xjw== 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=cSn2OLTOfi/Y+UvE5m+ZCYBNLcby/iKKConSFn14yYQ=; b=PqDT0n6ou2AfxYlacSLmk2MSQsvUIt61dxqsab9AKKuT5dIgustuUiYHnAuqyFyuAD hR1t8twuOMhk1DK8OjuQ0/rzMMnxG3xlMwepV5tHU5IOccNsijBVazcM1On4uOab1zr8 AASS0uuVG1SlamhfeDoQXKQwg14sniWOJAHG+rB7N+ETJ+L0sLYFRPy6gQW3VKf+IdVT 8ZyiJsGTivDFH711cR2r/4RyZdaWeBrjg8FCdKjiZYvNrhyry/0RlNbhLQzyNttVHAqP 1m2UjzBUOCuTqWpAuw/NVdhnBaJXbykt+JAThoBQNPshHjzTyMEZgZi+Oz2zDPgr2YAA g1yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tiOmOuAD; 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 i3-20020a170902cf0300b00178a4067331si548767plg.295.2022.10.24.13.43.10; Mon, 24 Oct 2022 13:43:25 -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=tiOmOuAD; 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 S234926AbiJXUmk (ORCPT + 99 others); Mon, 24 Oct 2022 16:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbiJXUlt (ORCPT ); Mon, 24 Oct 2022 16:41:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AF9217F664; Mon, 24 Oct 2022 11:50:44 -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 ams.source.kernel.org (Postfix) with ESMTPS id 219CCB819AD; Mon, 24 Oct 2022 12:45:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7941AC433C1; Mon, 24 Oct 2022 12:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615533; bh=de93994sNvEfasj0JU76mGj23QzHTw6KLverZZxUaC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tiOmOuADgLtyQNrfSfQiNn3y249wGp6NQABguOVeisS4zVneVqKH1G7qaiiWXXB+Y HIOHubIWMBKO9V/7x7vAh+AAGCJvVLZmH2t9rxMVhq9I46oFubqO7khPkMziAzazPV +hqlfFnuSLFqEz62itswIulS5mIXuIr9ejKbrL3M= 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.15 287/530] media: uvcvideo: Fix memory leak in uvc_gpio_parse Date: Mon, 24 Oct 2022 13:30:31 +0200 Message-Id: <20221024113058.047779137@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747603114461677414?= X-GMAIL-MSGID: =?utf-8?q?1747603114461677414?= 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 9a791d8ef200..72fff7264b54 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1534,10 +1534,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) @@ -1546,6 +1542,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;