Commit 6af79f7
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>1 parent 8c906cc commit 6af79f7
1 file changed
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
934 | | - | |
935 | | - | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
936 | 937 | | |
937 | 938 | | |
938 | 939 | | |
| |||
970 | 971 | | |
971 | 972 | | |
972 | 973 | | |
973 | | - | |
974 | 974 | | |
975 | 975 | | |
976 | 976 | | |
| |||
982 | 982 | | |
983 | 983 | | |
984 | 984 | | |
| 985 | + | |
985 | 986 | | |
986 | 987 | | |
987 | 988 | | |
| |||
993 | 994 | | |
994 | 995 | | |
995 | 996 | | |
| 997 | + | |
996 | 998 | | |
997 | 999 | | |
998 | 1000 | | |
999 | 1001 | | |
1000 | 1002 | | |
1001 | 1003 | | |
1002 | 1004 | | |
1003 | | - | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
1004 | 1009 | | |
1005 | 1010 | | |
1006 | 1011 | | |
| |||
0 commit comments