aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <swboyd@chromium.org>2018-06-21 22:27:16 -0400
committerJiri Kosina <jkosina@suse.cz>2018-06-25 09:12:42 -0400
commitd6f83894110de247a81392ab7ef89e5498df7e80 (patch)
tree6eaa205278dc4b6cc198cd9eae45b23f3579e19c
parentfdea70d26a471e002f2afc3a48821323b699f1e6 (diff)
HID: i2c-hid: Use devm to allocate i2c_hid struct
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 <benjamin.tissoires@redhat.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Dmitry Torokhov <dtor@chromium.org> Cc: Doug Anderson <dianders@chromium.org> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index c1652bb7bd15..c7d6738dc524 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,
1002 return client->irq; 1002 return client->irq;
1003 } 1003 }
1004 1004
1005 ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); 1005 ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL);
1006 if (!ihid) 1006 if (!ihid)
1007 return -ENOMEM; 1007 return -ENOMEM;
1008 1008
1009 if (client->dev.of_node) { 1009 if (client->dev.of_node) {
1010 ret = i2c_hid_of_probe(client, &ihid->pdata); 1010 ret = i2c_hid_of_probe(client, &ihid->pdata);
1011 if (ret) 1011 if (ret)
1012 goto err; 1012 return ret;
1013 } else if (!platform_data) { 1013 } else if (!platform_data) {
1014 ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 1014 ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
1015 if (ret) 1015 if (ret)
1016 goto err; 1016 return ret;
1017 } else { 1017 } else {
1018 ihid->pdata = *platform_data; 1018 ihid->pdata = *platform_data;
1019 } 1019 }
@@ -1126,7 +1126,6 @@ err_regulator:
1126 1126
1127err: 1127err:
1128 i2c_hid_free_buffers(ihid); 1128 i2c_hid_free_buffers(ihid);
1129 kfree(ihid);
1130 return ret; 1129 return ret;
1131} 1130}
1132 1131
@@ -1150,8 +1149,6 @@ static int i2c_hid_remove(struct i2c_client *client)
1150 1149
1151 regulator_disable(ihid->pdata.supply); 1150 regulator_disable(ihid->pdata.supply);
1152 1151
1153 kfree(ihid);
1154
1155 return 0; 1152 return 0;
1156} 1153}
1157 1154