Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp758937imw; Fri, 15 Jul 2022 12:18:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tCtArHviR5e1yMhdLOz6goOnF/TSzCmNj239X2LGtJhIzpp5DrILAbQrfEFPTUXsp05R+B X-Received: by 2002:a17:903:1103:b0:16c:9a6e:d54 with SMTP id n3-20020a170903110300b0016c9a6e0d54mr12360822plh.131.1657912680420; Fri, 15 Jul 2022 12:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657912680; cv=none; d=google.com; s=arc-20160816; b=pBsyf3g0uooXINX1239Hb4E+RWZbYrDyrJ7MibQQ5yPUfzPozpZP2SU+jd6Rlhai4A rAudSaXpjiUjiup8s26ve+vo73uXetWDcGFPXOue1zPP1ZC4JjUy/uzf1DYOLgFj3X+/ QMexsNnrn4INyTB0z/rAC7c1rzRNFkL+BDbSVO1vk1OGxTYP+yC2DqYugEiU+MwEAL2O a+AZTPrjS00UDSyrpZRnEGQgTy6VmRsmnd6pvsFj9sRc9Rm6fps8vbqQFgNn5iJ5vaBQ R+KhPE1E8qOXYacGz923db5ibQONdZgtckmPZk/aV82JSVoDjKwS5jVvrArv/VF+BaYQ hcJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LzY8MD8xZ8+6FqGc8Uuv1CXjyZFzFQ5flT6CmFfNP0w=; b=ogNNQEOqrEINPwRUrhpKqMHRO8Iyx5peAbHiGIUOW24x5E0kXhzBgnxh1JfbiN9fjm Gsl1pwpBTdcilnEZkgfiru28ykMuZmD35TZTfC5QrvonzxfGrHt+JfqYj4rtbSpKWjV5 pS5h1sPaF+WCF1YKn7BusEanjC+Qt/IC5JbkCH4GZ9mA3KxAmQ9LyGv/UhmASyiQSeq+ 6LKWI/W1RVQ58CQy4385Np6BL7nogDvVpv594z3N/RcEaCYm4oCitJ2XtckRLbKKsHwo HKI0xDMWkpqUbhSBj22xW01mEctgXg175V4ANQnCb1nhHT9qTVj1WRnZXvTURqqw6n1t duQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=LK4oZTkk; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc10-20020a17090b3b8a00b001ef800dff4dsi7172047pjb.45.2022.07.15.12.17.44; Fri, 15 Jul 2022 12:18:00 -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 (test mode) header.i=@ideasonboard.com header.s=mail header.b=LK4oZTkk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231163AbiGOTLR (ORCPT + 99 others); Fri, 15 Jul 2022 15:11:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbiGOTLQ (ORCPT ); Fri, 15 Jul 2022 15:11:16 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58FAE402CC; Fri, 15 Jul 2022 12:11:15 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1FA18993; Fri, 15 Jul 2022 21:11:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657912273; bh=c3uyxB2MmrAa8po96PTo2NR+WAA78v7/sF+HW/0PaCg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LK4oZTkkgx+vyCyWQoTl9FqQY/jyo/N1Mg4k0ctYb1jfp9Vdj1I4RKCXk0E72EHqi QafJCG3W2IpyjasxN9K5CImLAdypT+px8YRn+3f2r+q0Gsczzc5fMYk1zVfKHkwMda pDT2B4I5DepIrIaoupMHVeKN0MriUUydRzDqSC+o= Date: Fri, 15 Jul 2022 22:10:41 +0300 From: Laurent Pinchart To: =?utf-8?B?Sm9zw6kgRXhww7NzaXRv?= Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ribalda@chromium.org Subject: Re: [PATCH RESEND v2] media: uvcvideo: Fix memory leak in uvc_gpio_parse Message-ID: References: <20220108170439.49984-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220108170439.49984-1-jose.exposito89@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 Hi José, Thank you for the patch. On Sat, Jan 08, 2022 at 06:04:39PM +0100, José Expósito wrote: I can't believe I've managed to ignore this patch for so long :-( Sorry. > 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 Reviewed-by: Laurent Pinchart > --- > > v2: Add Fixes and Reviewed-by tags > --- > 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 7c007426e082..9e83e2002710 100644 > --- a/drivers/media/usb/uvc/uvc_driver.c > +++ b/drivers/media/usb/uvc/uvc_driver.c > @@ -1533,10 +1533,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) > @@ -1545,6 +1541,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; -- Regards, Laurent Pinchart