Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1089519pxb; Fri, 3 Sep 2021 23:22:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxg0EF9PmJQf7vSvaKsaU28lQVSey1gcSH8iWxHSpVJN7vSDIKt7Xw0sRM62mYLijoqJ0X/ X-Received: by 2002:a05:6402:51c9:: with SMTP id r9mr2821233edd.65.1630736555116; Fri, 03 Sep 2021 23:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630736555; cv=none; d=google.com; s=arc-20160816; b=yf+C/12pg274qRuq/iPW4JS8HEIvE/arjGR1NOs8xEsscfq6SeyMMDKVK7YYJHHp8R Ggk4ESghGY6+Ert7Wp3kDEVIvPwKDcDiEqPWg6Nw3MnYqRyDZ064EabWXA3nfMDRjpKL GMliTuPJ5jhgF11WH2gz+0imMwnBeZMtnnUAxd/Q9qRLst5frIsoyysUAzLOVt0LnAtY s4M6ddxCb/GJP+vLdE+vEUPv12xusLsFwG0hoCXBolOlMhKeMmPh02HAqDpHue/X7PZU IzLo2QWm+Xk56wh04Zps1xybgVHG2manByl2/Hm0Wk8WZQOOiVl9zeBKCZTcW6AVdzHL eiNg== 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 :message-id:date:subject:cc:to:from; bh=LP2mNjioRWiXbcomI0nio22pjnNHkvWybPfUYNNCLOY=; b=vI+2JOBVGxuUMFwFUDb7XOQAGQI0aS0o5DmV0ma9m65QtnXHai8SKP8T0q8yVy4ZcO 2C4Redu3zq3W6pQ/503XdipsQ4gILhCu7U55PIS6N7atpqJ8ossA/011AlVHx+SCx9h1 eAoilVjymJVn1pEFhGGYyh5clqB5qKRLAdQJvhy0I2j9l+6hV+skYw1QTg/DzEUXvuYu t/K259OSOJQmp8zbI9SSDNe0u08YIhIVCSF9XS+Zo0T/ehI1GDrN9/sQngthZ8Klu0dd +wLlY4J0M5NkvvOMk/ZjkHu3PBvIR6txPYlOgRsX/kt63FfHSdIdmlZ5l4jts8tYBiF1 Eg2w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si1396192ejc.168.2021.09.03.23.22.11; Fri, 03 Sep 2021 23:22:35 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbhIDGVZ (ORCPT + 99 others); Sat, 4 Sep 2021 02:21:25 -0400 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:18280 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbhIDGVZ (ORCPT ); Sat, 4 Sep 2021 02:21:25 -0400 Received: from pop-os.home ([90.126.253.178]) by mwinf5d24 with ME id piLL2500Y3riaq203iLLfp; Sat, 04 Sep 2021 08:20:21 +0200 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 04 Sep 2021 08:20:21 +0200 X-ME-IP: 90.126.253.178 From: Christophe JAILLET To: laurent.pinchart@ideasonboard.com, mchehab@kernel.org, ribalda@chromium.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] media: uvcvideo: Fix a memory leak in error handling code in 'uvc_gpio_parse()' Date: Sat, 4 Sep 2021 08:20:18 +0200 Message-Id: <4c96691f21293dea1c3584f80a58138e2a2f9219.1630736273.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory allocated in 'uvc_alloc_entity()' should be freed if an error occurs after it. Reorder the code in order to avoid the leak. Fixes: 2886477ff987 ("media: uvcvideo: Implement UVC_EXT_GPIO_UNIT") Signed-off-by: Christophe JAILLET --- 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 b1b055784f8d..a4c45424ba7e 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; -- 2.30.2