Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4611827pxj; Wed, 12 May 2021 09:13:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQxR5G7rSlHSOgfMhL2pVyXd38cmr+raxfXTIJbrY1wtCmdhB/EoeVj9K1+cz7tobxD9aQ X-Received: by 2002:a17:906:640c:: with SMTP id d12mr10039940ejm.70.1620836007530; Wed, 12 May 2021 09:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836007; cv=none; d=google.com; s=arc-20160816; b=ebIxg+x1qVA2jZa2fjnhOeV2KomqsjZUyataqfX86N2zQGdvHAjmVMZj2j0C43aInW D94hJzS4Lks69Ss8lBeqgCniiq7erEI3AbzFMJX9YF1RKb3FL1soSi02uQwOJYPzeAym 4FGMhdXapZKYBztMFUUVeBUo7j+3BuwC9QF3HEcNtVaqMeespMfKTm5iiovcevayli7g Jju1hLwpgZ2JABaw/k0uMHa7sXEpAcdVcNiN0eFl/AtzXjMK4zAC1nvdzZ59ouHAVIt1 XbeTBf6vQjrC+IMJqV0NDIupuuhaW2uSZDBZYBVrwGzsKw3aL1jgYnJc9+r94sj6srga 0t/A== 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=zeld6NPtsNUqvScz4Box9JkpqqfmyReFKwS3IFQHFKovWX7xETv7Dlhph9DXcaJ4Hj PKvpPVYB2O9Y70aV3bI+CCJ6b5Yvx1JXluT7+ckvX3LQx/hScnHiXf8qa7E+3Q+2y4YU bDUvd8ayKXDvsKdBlLV0KbUmV/UiTF27teSqEyljsV/1lx3CNCgL6YlmqUoaoqyQXeb6 xDTY1JKQEennHZ7YoTjNjcksSHOPkopQw6JgDhzzCZ/xYTwSAovW2+TyP5zA7KPRk6v+ AsWHTC+OJaNqvshbkHHqd9AQwk9JYha9lrytsHSUTaMN3ex5AOs8K0rf0fRiiZayvZ4t gZ4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wAcM0Hc3; 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 i17si85986edt.91.2021.05.12.09.13.03; Wed, 12 May 2021 09:13:27 -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=wAcM0Hc3; 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 S234508AbhELQLQ (ORCPT + 99 others); Wed, 12 May 2021 12:11:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:46830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235739AbhELP36 (ORCPT ); Wed, 12 May 2021 11:29:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E24FF61949; Wed, 12 May 2021 15:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832542; bh=1hIczK2c9Pe72dJN4nztRkRbHwsTEgqEsGcUjmlRvfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wAcM0Hc3zkWhxKnpkIvMTcTagp6NMnQTRUC40wx5eaA50ZUlZIac+V9V3y6QuWomu J/sJThkReGP14PSV6iO71y2abr+GQQI39R+CilLK8eIIEMn1KmKrv9AuYl1zlRFvgX L6n96RdZYSF3/hnQ0y1owB1Tr4fbgGjQJRn4HlXM= 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.10 295/530] media: [next] staging: media: atomisp: fix memory leak of object flash Date: Wed, 12 May 2021 16:46:45 +0200 Message-Id: <20210512144829.499183963@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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