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

Abdun Nihaal posted 1 patch 4 days, 14 hours ago
drivers/mfd/sm501.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] mfd: sm501: Fix potential memory leak in sm501_register_gpio_i2c_instance()
Posted by Abdun Nihaal 4 days, 14 hours ago
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: stable@vger.kernel.org
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
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