[PATCH] mfd: sm501: Fix potential memory leak in sm501_register_gpio_i2c_instance()

Abdun Nihaal <[email protected]>
Newsgroups dev.linux.lists.mfd,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
The memory allocated for pdev in sm501_create_subdev() is not freed in
an error path in sm501_register_gpio_i2c_instance(). Fix that by
releasing the platform dev in the error path.

Fixes: ae7b8eda27b3 ("mfd: sm501: Fix potential NULL pointer dereference")
Cc: [email protected]
Signed-off-by: Abdun Nihaal <[email protected]>
---
Compile tested only. Issue found using static analysis.

 drivers/mfd/sm501.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index b5bda477ebfc..49c6b21a44e8 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -1103,8 +1103,10 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
 	/* Create a gpiod lookup using gpiochip-local offsets */
 	lookup = devm_kzalloc(&pdev->dev, struct_size(lookup, table, 3),
 			      GFP_KERNEL);
-	if (!lookup)
+	if (!lookup) {
+		platform_device_put(pdev);
 		return -ENOMEM;
+	}
 
 	lookup->dev_id = "i2c-gpio";
 	lookup->table[0] = (struct gpiod_lookup)
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.