* [PATCH] i2c: core: fix reference leak in i2c_register_adapter()
@ 2024-12-11 3:08 Joe Hattori
2025-01-09 10:02 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Joe Hattori @ 2024-12-11 3:08 UTC (permalink / raw)
To: wsa+renesas; +Cc: linux-i2c, Joe Hattori
The reference count of the device incremented in device_initialize() is
not decremented when device_add() fails. Add a put_device() call before
returning from the function.
This bug was found by an experimental static analysis tool that I am
developing.
Fixes: 60f68597024d ("i2c: core: Setup i2c_adapter runtime-pm before calling device_add()")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
drivers/i2c/i2c-core-base.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 7c810893bfa3..75d30861ffe2 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1562,6 +1562,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
res = device_add(&adap->dev);
if (res) {
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
+ put_device(&adap->dev);
goto out_list;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: core: fix reference leak in i2c_register_adapter()
2024-12-11 3:08 [PATCH] i2c: core: fix reference leak in i2c_register_adapter() Joe Hattori
@ 2025-01-09 10:02 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2025-01-09 10:02 UTC (permalink / raw)
To: Joe Hattori; +Cc: linux-i2c
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
On Wed, Dec 11, 2024 at 12:08:03PM +0900, Joe Hattori wrote:
> The reference count of the device incremented in device_initialize() is
> not decremented when device_add() fails. Add a put_device() call before
> returning from the function.
>
> This bug was found by an experimental static analysis tool that I am
> developing.
>
> Fixes: 60f68597024d ("i2c: core: Setup i2c_adapter runtime-pm before calling device_add()")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-09 10:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 3:08 [PATCH] i2c: core: fix reference leak in i2c_register_adapter() Joe Hattori
2025-01-09 10:02 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).