Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp610431pxk; Wed, 2 Sep 2020 10:01:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCuF64QAaE/wA6wANuuH59j5d0SGes2A3G95qhrrzoLPH4P2K929fF695q+3sDSB0Lsmsq X-Received: by 2002:a17:906:2712:: with SMTP id z18mr999765ejc.380.1599066102142; Wed, 02 Sep 2020 10:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599066102; cv=none; d=google.com; s=arc-20160816; b=iQIxYSgS5CZ1KE9vuXhyMNxhICJOYs+ToCHKr4sVc9U3za9DD7xURqsIRRfsEIZHUj ONkGPQiGBcjduuGbTuP+lucDnK7ZqYnHVIyb5zcIYcukUm0y5SYUNbyG7zThOET+sagG z/qD86f/eiMCHxsZLLIdpvdajJ1tchP484HgMJP9G6EyZ1kc38bauvvNt/Ea7GVFp9D+ MMYFGLDa3lpvIFLE45TZfpYLNsO1vnfagdK51j9pwxwYLnSkwE5N+B1BYLGahzXKFLUq tQ6zZV1ZCKvJssU8saOokmNw7byF6n7NdAMlucSFZFk3XhTFB7wVG0tGQvJr5831/NIr pnHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=OZmjOBhWTBWv290y646yvT82MwHhcrOJ79CdqnMLfMQ=; b=KcLke1CoJ+6910034rg6Jy/47wB0bl1yYHFrtqryu8NwgLQkZP93LGXrFHBtNHY2Nx n7W31ag7uxSKm6e/1XUssyLKbXOmfmF2gk96KM9EIcPUvZaDMHYgPDJIpyEIa98CHZeT tFMljlrFkXoT5kg/0RBFDwhJBNHlwHKw+s1BsygCtibe5N5ytC8inrqdip4CSgfHja2B 1mD9bzeb3g/qo/NcpLLu4kWg6K/SHedeXEFUWAG8tEUXlVkeJ0Y+0cxt8xNj05zf2n/S wgRBznidoNLy2o1d616USB8LKhHNjRDQHh5VM2QH2wRJskv+UkLnstzkSBpN3QP5GFyj 3MfQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si60614ejj.626.2020.09.02.10.01.18; Wed, 02 Sep 2020 10:01:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728657AbgIBQ7w (ORCPT + 99 others); Wed, 2 Sep 2020 12:59:52 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:60781 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728048AbgIBQ66 (ORCPT ); Wed, 2 Sep 2020 12:58:58 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kDW60-0000nm-OI; Wed, 02 Sep 2020 16:58:52 +0000 From: Colin King To: Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Linus Walleij , linux-media@vger.kernel.org, devel@driverdev.osuosl.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] staging: media: atomisp: fix memory leak of object flash Date: Wed, 2 Sep 2020 17:58:52 +0100 Message-Id: <20200902165852.201155-1-colin.king@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King 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. Fixes: 9289cdf39992 ("staging: media: atomisp: Convert to GPIO descriptors") Signed-off-by: Colin Ian King --- .../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..5516c98f63bc 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.27.0