From: Stephen Boyd Date: Fri, 22 Jun 2018 02:27:16 +0000 (-0700) Subject: HID: i2c-hid: Use devm to allocate i2c_hid struct X-Git-Tag: v4.18.12~131 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d0f7fbdb1cf98e37b3c61b503d41578517cede1c;p=users%2Fdwmw2%2Flinux.git HID: i2c-hid: Use devm to allocate i2c_hid struct [ 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 5fd1159fc0956..64773433b947b 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -1004,18 +1004,18 @@ static int i2c_hid_probe(struct i2c_client *client, return client->irq; } - ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); + ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); if (!ihid) return -ENOMEM; if (client->dev.of_node) { ret = i2c_hid_of_probe(client, &ihid->pdata); if (ret) - goto err; + return ret; } else if (!platform_data) { ret = i2c_hid_acpi_pdata(client, &ihid->pdata); if (ret) - goto err; + return ret; } else { ihid->pdata = *platform_data; } @@ -1128,7 +1128,6 @@ err_regulator: err: i2c_hid_free_buffers(ihid); - kfree(ihid); return ret; } @@ -1152,8 +1151,6 @@ static int i2c_hid_remove(struct i2c_client *client) regulator_disable(ihid->pdata.supply); - kfree(ihid); - return 0; }