Skip to content

Commit

Permalink
i2c: i2c-boardinfo: fix memory leaks on devinfo
Browse files Browse the repository at this point in the history
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: 4124c4e ("i2c: allow attaching IRQ resources to i2c_board_info")
Fixes: 0daaf99 ("i2c: copy device properties when using i2c_register_board_info()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Colin Ian King authored and Wolfram Sang committed Nov 27, 2017
1 parent 6e0c950 commit 66a7c84
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/i2c/i2c-boardinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig
property_entries_dup(info->properties);
if (IS_ERR(devinfo->board_info.properties)) {
status = PTR_ERR(devinfo->board_info.properties);
kfree(devinfo);
break;
}
}
Expand All @@ -98,6 +99,7 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig
GFP_KERNEL);
if (!devinfo->board_info.resources) {
status = -ENOMEM;
kfree(devinfo);
break;
}
}
Expand Down

0 comments on commit 66a7c84

Please sign in to comment.