Return-Path: Received: from mail-sn1nam01on0109.outbound.protection.outlook.com ([104.47.32.109]:45568 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932212AbeAXEPY (ORCPT ); Tue, 23 Jan 2018 23:15:24 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Colin Ian King , Wolfram Sang , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 053/100] i2c: i2c-boardinfo: fix memory leaks on devinfo Date: Wed, 24 Jan 2018 04:14:51 +0000 Message-ID: <20180124041414.32065-53-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Colin Ian King [ Upstream commit 66a7c84d677e8e4a5a2ef4afdb9bd52e1399a866 ] 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: 4124c4eba402 ("i2c: allow attaching IRQ resources to i2c_board_info"= ) Fixes: 0daaf99d8424 ("i2c: copy device properties when using i2c_register_b= oard_info()") Signed-off-by: Colin Ian King Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/i2c-boardinfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c index 31186ead5a40..509a6007cdf6 100644 --- a/drivers/i2c/i2c-boardinfo.c +++ b/drivers/i2c/i2c-boardinfo.c @@ -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 =3D PTR_ERR(devinfo->board_info.properties); + kfree(devinfo); break; } } @@ -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 =3D -ENOMEM; + kfree(devinfo); break; } } --=20 2.11.0