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

From: Abdun Nihaal

Date: Mon Jul 20 2026 - 07:35:02 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Abdun Nihaal <nihaal@xxxxxxxxxxxxxx>
---
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