Commit 66a7c84d authored by Colin Ian King's avatar Colin Ian King Committed by Wolfram Sang

i2c: i2c-boardinfo: fix memory leaks on devinfo

Currently when an error occurs devinfo is still allocated but is
unused when the error exit paths break out of the for-loop. Fix
this by kfree'ing devinfo to avoid the leak.

Detected by CoverityScan, CID#1416590 ("Resource Leak")

Fixes: 4124c4eb ("i2c: allow attaching IRQ resources to i2c_board_info")
Fixes: 0daaf99d ("i2c: copy device properties when using i2c_register_board_info()")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 6e0c9507
...@@ -86,6 +86,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig ...@@ -86,6 +86,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig
property_entries_dup(info->properties); property_entries_dup(info->properties);
if (IS_ERR(devinfo->board_info.properties)) { if (IS_ERR(devinfo->board_info.properties)) {
status = PTR_ERR(devinfo->board_info.properties); status = PTR_ERR(devinfo->board_info.properties);
kfree(devinfo);
break; break;
} }
} }
...@@ -98,6 +99,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig ...@@ -98,6 +99,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig
GFP_KERNEL); GFP_KERNEL);
if (!devinfo->board_info.resources) { if (!devinfo->board_info.resources) {
status = -ENOMEM; status = -ENOMEM;
kfree(devinfo);
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment