[PATCH v2] fsi: i2cr-scom: Fix device reference leak in cdev_device_add() error path

From: Guangshuo Li

Date: Mon Apr 13 2026 - 10:16:19 EST


After device_initialize(), the embedded struct device in struct
i2cr_scom is expected to be released through the device core with
put_device().

In i2cr_scom_probe(), the cdev_device_add() failure path frees the
allocated minor but does not drop the device reference, which bypasses
the normal device core lifetime handling and leaks the reference held on
the embedded struct device.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fix this by calling put_device() after freeing the minor in the
cdev_device_add() error path.

Fixes: c0b34bed0bbf7 ("fsi: Add I2C Responder SCOM driver")
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
v2:
- note that the issue was identified by my static analysis tool
- and confirmed by manual review

drivers/fsi/i2cr-scom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c
index cb7e02213032..3de3f0194d10 100644
--- a/drivers/fsi/i2cr-scom.c
+++ b/drivers/fsi/i2cr-scom.c
@@ -109,8 +109,10 @@ static int i2cr_scom_probe(struct device *dev)
dev_set_name(&scom->dev, "scom%d", didx);
cdev_init(&scom->cdev, &i2cr_scom_fops);
ret = cdev_device_add(&scom->cdev, &scom->dev);
- if (ret)
+ if (ret) {
fsi_free_minor(scom->dev.devt);
+ put_device(&scom->dev);
+ }

return ret;
}
--
2.43.0