Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4725142pxj; Wed, 12 May 2021 11:47:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxieFsHQ7lVuqSZpIt4q6kDKcjUoYXAZJ15c9a1rfmUed6KEla2v4OHps21QVJ5vfzgx58m X-Received: by 2002:a17:906:4ad0:: with SMTP id u16mr39191169ejt.19.1620845234530; Wed, 12 May 2021 11:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620845234; cv=none; d=google.com; s=arc-20160816; b=m1AvUDTSrJ6FBpMTQ84a5PJ30aVXpEt1lnSOAeh5NgoevqlcRHoJORHVsZF6JjNn+V Elobq20H3titDohwnlVjp2qmWQQxsEhtIQvlrRUBmdWCxJcr/iZubhIEGYkMOJhdTax6 ykvOk9npHGRLhMX1GNWy/8bl8Q3MlV5W/4LI1/b133RCyJz4Ye5ewQjzGTL1ccyVa66a MakaIbYgofhaZWeHix+jXr2Hok1qm9PmJtPm7Qb5vajPNFh+Oq+Ipqf0V0Mjaivtp+EK /G2OdKU1gKgk29hk/Y7V0rtVyvpuYXiJfyTOkuFr/bDd18bD1eyersQDvRVzQyHPQzPI ejcA== 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=CRIFCGqW0KLu+877v0/lW/xYh4g19YBNat0kXZsbJzY=; b=muHgdUf7CJmPgURQgAV4dtaqdhOF6ExhKnh6U0eUzPmedDAd2m7L0XM8GtNJ8gKRY9 Ho2spa+mr/6kuxM4svsrcdXHHB0VISKc7EsOa7nZ0z5k1FmhyC3fmZwq3Q2EOVlPl3BZ mYC1/fBPUN1AmgsAjrfDyAFdMA9M8Nbshfri7knd+AlGxkmaNNpKIzI5Epk/SjOhGbNU LRMjONhESkhkguteua3C2VLLOUxqw/Z0VwIQWIyhz3no3Kr50B02aUyBNd6EIn6M84O0 n1j5xusCMAwhH4bQ4/WyrFsJG3/n31biGMgqZAdb2rCfR68uQ0v/RILa6xgUx0EjgvGS X20Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zG9TYQ/C"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si842024ejb.448.2021.05.12.11.46.49; Wed, 12 May 2021 11:47:14 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zG9TYQ/C"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358278AbhELSnc (ORCPT + 99 others); Wed, 12 May 2021 14:43:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243558AbhELQlc (ORCPT ); Wed, 12 May 2021 12:41:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D916061E4A; Wed, 12 May 2021 16:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835490; bh=1hIczK2c9Pe72dJN4nztRkRbHwsTEgqEsGcUjmlRvfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zG9TYQ/CFUYPAp3RRZhR0FKiRAg1FEoTQW2UeYW+8h/Fr2WCo7cmPn0c0aTUo+NlR pmXPfKRBoWJwj0/r5ZwaYk0cVBSHyacjF38x9PINLuZt7Hvp3neXpp62Zx6DiL2BmV rIeEv+yesNPe+Xyr3LV2aiqcgFui8ngKarSIXK/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.12 364/677] media: [next] staging: media: atomisp: fix memory leak of object flash Date: Wed, 12 May 2021 16:46:50 +0200 Message-Id: <20210512144849.424745199@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 6045b01dd0e3cd3759eafe7f290ed04c957500b1 ] In the case where the call to lm3554_platform_data_func returns an error there is a memory leak on the error return path of object flash. Fix this by adding an error return path that will free flash and rename labels fail2 to fail3 and fail1 to fail2. Link: https://lore.kernel.org/linux-media/20200902165852.201155-1-colin.king@canonical.com Fixes: 9289cdf39992 ("staging: media: atomisp: Convert to GPIO descriptors") Signed-off-by: Colin Ian King Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- .../media/atomisp/i2c/atomisp-lm3554.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c b/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c index 7ca7378b1859..0ab67b2aec67 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c @@ -843,8 +843,10 @@ static int lm3554_probe(struct i2c_client *client) return -ENOMEM; flash->pdata = lm3554_platform_data_func(client); - if (IS_ERR(flash->pdata)) - return PTR_ERR(flash->pdata); + if (IS_ERR(flash->pdata)) { + err = PTR_ERR(flash->pdata); + goto fail1; + } v4l2_i2c_subdev_init(&flash->sd, client, &lm3554_ops); flash->sd.internal_ops = &lm3554_internal_ops; @@ -856,7 +858,7 @@ static int lm3554_probe(struct i2c_client *client) ARRAY_SIZE(lm3554_controls)); if (ret) { dev_err(&client->dev, "error initialize a ctrl_handler.\n"); - goto fail2; + goto fail3; } for (i = 0; i < ARRAY_SIZE(lm3554_controls); i++) @@ -865,14 +867,14 @@ static int lm3554_probe(struct i2c_client *client) if (flash->ctrl_handler.error) { dev_err(&client->dev, "ctrl_handler error.\n"); - goto fail2; + goto fail3; } flash->sd.ctrl_handler = &flash->ctrl_handler; err = media_entity_pads_init(&flash->sd.entity, 0, NULL); if (err) { dev_err(&client->dev, "error initialize a media entity.\n"); - goto fail1; + goto fail2; } flash->sd.entity.function = MEDIA_ENT_F_FLASH; @@ -884,14 +886,15 @@ static int lm3554_probe(struct i2c_client *client) err = lm3554_gpio_init(client); if (err) { dev_err(&client->dev, "gpio request/direction_output fail"); - goto fail2; + goto fail3; } return atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH); -fail2: +fail3: media_entity_cleanup(&flash->sd.entity); v4l2_ctrl_handler_free(&flash->ctrl_handler); -fail1: +fail2: v4l2_device_unregister_subdev(&flash->sd); +fail1: kfree(flash); return err; -- 2.30.2