Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1006875pxb; Thu, 28 Jan 2021 06:05:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkMifrpDXZYqw+xs+wdHkrRQd141KURHNtSWlrlkrJC8RLy76Zos+GIPN13qEtBFg/ilIE X-Received: by 2002:a7b:c0d8:: with SMTP id s24mr9080826wmh.4.1611842715373; Thu, 28 Jan 2021 06:05:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611842715; cv=none; d=google.com; s=arc-20160816; b=ErkDb6HlCyL4an/aTBlJXIEzypI1HtR2YCxFH1pbEl3UgLwhtsVlKjEjO8YRTum/BA 1yCXyiUvUKyMBkvhFLY862DDCH20ie3/27jEpvNAmu1yfjUUKMTfdah+lupDd6UJ7Jr+ oEuzAo8qT9NoKQ5l8TtNIRXEQnTIlCP9ySfznYzgeTZBFgartLg8KnWaOqlYhlwz+qtD LLKcOITXsyzac+2padZCCt8a1T784T4Xzam89IPkw4av63ec7IVCm2Fc6j8+nfKeHigF tLU9e2J+WER1nPs5iwIM71Go7XkznDiyOaD4hwNxBfrxmpg+5t6uBx2XRHcMtLe1mkRf FghA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=C80bQsEcnaePuA0JEDUFX5G4Fu9IWpgz8bhre8oY+Wk=; b=onhFFVgolLYNnirY37c2G0oyEEv29mCuYR76WPwc2Bs2QVszrQeC0u5CqoWlvTSHT3 GxU8RtrJB3DVnW85Dmq14vEfBRw/iejuDfmThxO25cfSBsxFG9TGQau8BRYgQ3vfJSu8 B161Q9lLk3vfT2qPywDUwcEMXDx8xyYoZfZh8z/SrVBLp/YDXJk0hkmzSeNKQk61PPMo eSsI30k+XHA4KDlJj7FhQQwLLvAVw4EjSEeZQ6SXdV0URUK3gzCTo2N1p6RlhSCtzoaB imDDLMMaRQx4HXUBAuBwH7lXZBRjq3TvqU6aNPIbt33gr1u7cBgnbahv6c9pOX1KHgMT 1gvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YJRB0NzO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y38si3024644ede.59.2021.01.28.06.04.47; Thu, 28 Jan 2021 06:05:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YJRB0NzO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231258AbhA1OCf (ORCPT + 99 others); Thu, 28 Jan 2021 09:02:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbhA1OCe (ORCPT ); Thu, 28 Jan 2021 09:02:34 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79C9C061574 for ; Thu, 28 Jan 2021 06:01:53 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id a1so5278940ilr.5 for ; Thu, 28 Jan 2021 06:01:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=C80bQsEcnaePuA0JEDUFX5G4Fu9IWpgz8bhre8oY+Wk=; b=YJRB0NzOhuGIf7X/tpXVaLJ11JAIZH+y9CtgerkGasPD16ONKCfqbohJb2Vygv2NTn NnBiuE387xCBQHg6+gtLKYOMLro6+nm2Yq5+maax5YJcYItKdXE4tz9bUCO1A2uPEp/v daBigDPnSc/JlCr7O+/eee/TNIiYXK5tUuJ1Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C80bQsEcnaePuA0JEDUFX5G4Fu9IWpgz8bhre8oY+Wk=; b=pYTSe4SsauHaS5fXVLvQWbT/II19jvwT47NZZl6cHBMKkhPSr2RdrUpOqsmACFK7ey S+7bjFAx+FOEqPBVtO0p3VyKWGFpRITC8GvcTodA2V9cDC5qh/Pe4f7K0JSbeSQF+eZp r9I+KgTRytcdmHwqhOYGI4dcr1mPnkStGmj/a2vIqgUpwF0Iu7HAJo0hVoSQnjzOu8OG roDIlN+eY2Zp6v+DOAWiSSXexyHYCTGFkKZTFmcHxdbrGSJFAakq4EOPXeeucQjBglQC E3POTN/B45hXzxQSwAtX6FL0ZfYcLwAVZUN+d5BRCRfYhawiHIqXgGXG6LPPCCL2WjMp jYCw== X-Gm-Message-State: AOAM531y5Y/CQKave+/eRx83RBBd6E0fkQAB915jwaMjT/C4hRUSrXuk gRcjtthEX9ImDmGF1eR9M++EXAVn4OHzBZM5 X-Received: by 2002:a92:ca81:: with SMTP id t1mr12574723ilo.139.1611842513092; Thu, 28 Jan 2021 06:01:53 -0800 (PST) Received: from mail-io1-f49.google.com (mail-io1-f49.google.com. [209.85.166.49]) by smtp.gmail.com with ESMTPSA id l187sm2883532ill.84.2021.01.28.06.01.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Jan 2021 06:01:52 -0800 (PST) Received: by mail-io1-f49.google.com with SMTP id n2so5637467iom.7 for ; Thu, 28 Jan 2021 06:01:52 -0800 (PST) X-Received: by 2002:a05:6602:20c9:: with SMTP id 9mr11194877ioz.51.1611842511627; Thu, 28 Jan 2021 06:01:51 -0800 (PST) MIME-Version: 1.0 References: <20210128135923.638480-1-colin.king@canonical.com> In-Reply-To: <20210128135923.638480-1-colin.king@canonical.com> From: Ricardo Ribalda Date: Thu, 28 Jan 2021 15:01:40 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH][V2][next] media: uvcvideo: Fix memory leak when gpiod_to_irq fails To: Colin King Cc: Laurent Pinchart , Mauro Carvalho Chehab , Linux Media Mailing List , kernel-janitors@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for the fix! On Thu, Jan 28, 2021 at 2:59 PM Colin King wrote: > > From: Colin Ian King > > Currently when the call to gpiod_to_irq fails the error return > path does not kfree the recently allocated object 'unit'. Fix this > swapping the order of the irq call and the allocation of unit. > > Thanks to Ricardo Ribalda for suggesting this fix. > > Addresses-Coverity: ("Resource leak") > Fixes: 2886477ff987 ("media: uvcvideo: Implement UVC_EXT_GPIO_UNIT") > Signed-off-by: Colin Ian King Reviewed-by: Ricardo Ribalda > --- > > V2: swap order of gpiod_to_irq call and allocation of unit to simplify > error cleanup. > > --- > 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 1abc122a0977..f62e6cb66daf 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; > -- > 2.29.2 > -- Ricardo Ribalda