From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-by2nam03on0129.outbound.protection.outlook.com ([104.47.42.129]:47904 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729483AbeIQI14 (ORCPT ); Mon, 17 Sep 2018 04:27:56 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Stephen Boyd , Benjamin Tissoires , Hans de Goede , Andy Shevchenko , Dmitry Torokhov , Doug Anderson , Jiri Kosina , Sasha Levin Subject: [PATCH AUTOSEL 4.18 103/136] HID: i2c-hid: Use devm to allocate i2c_hid struct Date: Mon, 17 Sep 2018 03:01:17 +0000 Message-ID: <20180917030006.245495-103-alexander.levin@microsoft.com> References: <20180917030006.245495-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030006.245495-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: Stephen Boyd [ Upstream commit d6f83894110de247a81392ab7ef89e5498df7e80 ] Use devm here to save some lines and prepare for bulk regulator usage in this driver. Otherwise, when we devm bulk get regulators we'll free the containing i2c_hid structure and try to put regulator pointers from freed memory. Cc: Benjamin Tissoires Cc: Hans de Goede Cc: Andy Shevchenko Cc: Dmitry Torokhov Cc: Doug Anderson Signed-off-by: Stephen Boyd Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/i2c-hid/i2c-hid.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index eae0cb3ddec6..3d1506f1c590 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -1002,18 +1002,18 @@ static int i2c_hid_probe(struct i2c_client *client, return client->irq; } =20 - ihid =3D kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); + ihid =3D devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); if (!ihid) return -ENOMEM; =20 if (client->dev.of_node) { ret =3D i2c_hid_of_probe(client, &ihid->pdata); if (ret) - goto err; + return ret; } else if (!platform_data) { ret =3D i2c_hid_acpi_pdata(client, &ihid->pdata); if (ret) - goto err; + return ret; } else { ihid->pdata =3D *platform_data; } @@ -1126,7 +1126,6 @@ static int i2c_hid_probe(struct i2c_client *client, =20 err: i2c_hid_free_buffers(ihid); - kfree(ihid); return ret; } =20 @@ -1150,8 +1149,6 @@ static int i2c_hid_remove(struct i2c_client *client) =20 regulator_disable(ihid->pdata.supply); =20 - kfree(ihid); - return 0; } =20 --=20 2.17.1