Wolfram Sang 6af79f7fe7 i2c: fix memleak in i2c_new_client_device()
Yang Yingliang reported a memleak:
===

I got memory leak as follows when doing fault injection test:

unreferenced object 0xffff888014aec078 (size 8):
  comm "xrun", pid 356, jiffies 4294910619 (age 16.332s)
  hex dump (first 8 bytes):
    31 2d 30 30 31 63 00 00                          1-001c..
  backtrace:
    [<00000000eb56c0a9>] __kmalloc_track_caller+0x1a6/0x300
    [<000000000b220ea3>] kvasprintf+0xad/0x140
    [<00000000b83203e5>] kvasprintf_const+0x62/0x190
    [<000000002a5eab37>] kobject_set_name_vargs+0x56/0x140
    [<00000000300ac279>] dev_set_name+0xb0/0xe0
    [<00000000b66ebd6f>] i2c_new_client_device+0x7e4/0x9a0

If device_register() returns error in i2c_new_client_device(),
the name allocated by i2c_dev_set_name() need be freed. As
comment of device_register() says, it should use put_device()
to give up the reference in the error path.

===
I think this solution is less intrusive and more robust than he
originally proposed solutions, though.

Reported-by: Yang Yingliang <yangyingliang@huawei.com>
Closes: http://patchwork.ozlabs.org/project/linux-i2c/patch/20221124085448.3620240-1-yangyingliang@huawei.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
2023-10-23 17:25:43 +02:00
..
2023-09-08 06:36:36 +10:00
2023-08-22 15:50:57 +02:00
2023-08-30 13:34:34 -07:00
2023-09-08 21:39:54 -07:00
2023-09-01 09:53:54 -07:00
Hi,
2023-09-13 11:44:20 -07:00
2023-09-04 13:47:59 -07:00
2023-08-31 12:43:10 -07:00
2023-08-24 16:20:30 -07:00
2023-09-03 10:49:42 -07:00
2023-08-30 13:34:34 -07:00
2023-08-30 19:23:00 -07:00
2023-09-15 12:13:01 +10:00
2023-09-01 12:31:44 -07:00
2023-09-04 11:26:29 -07:00
2023-08-28 16:35:01 -07:00
2023-09-01 09:53:54 -07:00
2023-09-02 12:02:41 -07:00
2023-09-06 09:24:25 -07:00
2023-09-01 16:54:25 -07:00
2023-09-04 13:52:58 -07:00
2023-08-31 12:43:10 -07:00
2023-09-01 09:38:00 -07:00
2023-09-04 13:47:59 -07:00
2023-08-30 18:32:24 -07:00
2023-09-14 16:20:31 -06:00
2023-08-30 16:59:03 -07:00
2023-09-09 11:35:28 -07:00
2023-09-08 12:48:37 -07:00
2023-09-03 10:38:02 -07:00
2023-09-07 18:05:58 -07:00
2023-09-07 15:51:07 -07:00
2023-09-04 15:12:26 -07:00
2023-09-04 15:08:52 -07:00
2023-09-07 16:07:35 -07:00
2023-09-08 21:39:54 -07:00
2023-09-03 10:20:57 -07:00
2023-09-07 15:49:20 -07:00
2023-09-01 09:38:00 -07:00
2023-09-04 10:43:44 -07:00
2023-08-30 20:41:37 -07:00
2023-09-06 09:00:37 -07:00
2023-08-24 16:20:18 -07:00
2023-09-06 09:19:12 -07:00
2023-08-29 20:32:10 -07:00
2023-08-21 13:27:44 +02:00