Commit e3d6a599 authored by Basavaraj Natikar's avatar Basavaraj Natikar Committed by Jiri Kosina

HID: amd_sfh: Use devm_kzalloc() instead of kzalloc()

Replace kzalloc with devm_kzalloc in driver initialization sequence. The
allocation can be tied to the lifetime of the amd_sfh driver. This cleans
up an exit & error paths, since the objects does not need to be
explicitly freed anymore.

Fixes: 4b2c53d9 ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)")
Reviewed-by: default avatarShyam Sundar S K <Shyam-sundar.S-k@amd.com>
Signed-off-by: default avatarBasavaraj Natikar <Basavaraj.Natikar@amd.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 82f09a63
...@@ -142,7 +142,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -142,7 +142,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
int rc, i; int rc, i;
dev = &privdata->pdev->dev; dev = &privdata->pdev->dev;
cl_data = kzalloc(sizeof(*cl_data), GFP_KERNEL); cl_data = devm_kzalloc(dev, sizeof(*cl_data), GFP_KERNEL);
if (!cl_data) if (!cl_data)
return -ENOMEM; return -ENOMEM;
...@@ -175,12 +175,12 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -175,12 +175,12 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
rc = -EINVAL; rc = -EINVAL;
goto cleanup; goto cleanup;
} }
cl_data->feature_report[i] = kzalloc(feature_report_size, GFP_KERNEL); cl_data->feature_report[i] = devm_kzalloc(dev, feature_report_size, GFP_KERNEL);
if (!cl_data->feature_report[i]) { if (!cl_data->feature_report[i]) {
rc = -ENOMEM; rc = -ENOMEM;
goto cleanup; goto cleanup;
} }
cl_data->input_report[i] = kzalloc(input_report_size, GFP_KERNEL); cl_data->input_report[i] = devm_kzalloc(dev, input_report_size, GFP_KERNEL);
if (!cl_data->input_report[i]) { if (!cl_data->input_report[i]) {
rc = -ENOMEM; rc = -ENOMEM;
goto cleanup; goto cleanup;
...@@ -189,7 +189,8 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -189,7 +189,8 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
info.sensor_idx = cl_idx; info.sensor_idx = cl_idx;
info.dma_address = cl_data->sensor_dma_addr[i]; info.dma_address = cl_data->sensor_dma_addr[i];
cl_data->report_descr[i] = kzalloc(cl_data->report_descr_sz[i], GFP_KERNEL); cl_data->report_descr[i] =
devm_kzalloc(dev, cl_data->report_descr_sz[i], GFP_KERNEL);
if (!cl_data->report_descr[i]) { if (!cl_data->report_descr[i]) {
rc = -ENOMEM; rc = -ENOMEM;
goto cleanup; goto cleanup;
...@@ -214,11 +215,11 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -214,11 +215,11 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
cl_data->sensor_virt_addr[i], cl_data->sensor_virt_addr[i],
cl_data->sensor_dma_addr[i]); cl_data->sensor_dma_addr[i]);
} }
kfree(cl_data->feature_report[i]); devm_kfree(dev, cl_data->feature_report[i]);
kfree(cl_data->input_report[i]); devm_kfree(dev, cl_data->input_report[i]);
kfree(cl_data->report_descr[i]); devm_kfree(dev, cl_data->report_descr[i]);
} }
kfree(cl_data); devm_kfree(dev, cl_data);
return rc; return rc;
} }
...@@ -241,6 +242,5 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) ...@@ -241,6 +242,5 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
cl_data->sensor_dma_addr[i]); cl_data->sensor_dma_addr[i]);
} }
} }
kfree(cl_data);
return 0; return 0;
} }
...@@ -162,9 +162,6 @@ void amdtp_hid_remove(struct amdtp_cl_data *cli_data) ...@@ -162,9 +162,6 @@ void amdtp_hid_remove(struct amdtp_cl_data *cli_data)
int i; int i;
for (i = 0; i < cli_data->num_hid_devices; ++i) { for (i = 0; i < cli_data->num_hid_devices; ++i) {
kfree(cli_data->feature_report[i]);
kfree(cli_data->input_report[i]);
kfree(cli_data->report_descr[i]);
if (cli_data->hid_sensor_hubs[i]) { if (cli_data->hid_sensor_hubs[i]) {
kfree(cli_data->hid_sensor_hubs[i]->driver_data); kfree(cli_data->hid_sensor_hubs[i]->driver_data);
hid_destroy_device(cli_data->hid_sensor_hubs[i]); hid_destroy_device(cli_data->hid_sensor_hubs[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment