Skip to contentSkip to conversation

bus: moxtet: fix reference count leak in moxtet_add_device()

PATCH In review Salah Triki 2 participants 2 messages Jan 31 – Feb 2 Arm/cz.nic turris support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: moxtet: fix reference count leak in moxtet_add_device()

If device_add() fails, the reference count of the device is not dropped. This leads to a memory leak of the device and its associated resources.

put_device() must be called if device_add() fails to properly clean up the device structure.

Fixes 5bc7f990cd98f ("bus: Add support for Moxtet bus")
---
 drivers/bus/moxtet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/moxtet.c +3 -1
index 7ce61d629a87..35795deba2a9 100644
@@ -179,9 +179,11 @@ static int moxtet_add_device(struct moxtet_device *dev)
 		goto done;
 
 	ret = device_add(&dev->dev);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(dev->moxtet->dev, "can't add %s, status %d\n",
 			dev_name(dev->moxtet->dev), ret);
+		put_device(&dev->dev);
+	}
 
 done:
 	mutex_unlock(&add_mutex);
Signature · 1 line
2.43.0