Commit ec7f68e0 authored by Srinivas Pandruvada's avatar Srinivas Pandruvada Committed by Jonathan Cameron

iio: hid_Sensors: fix crash during trigger unregister

We can't store the trigger instance created by iio_trigger_alloc, in
trig field of iio_device structure. This needs to be stored in the
driver private data. Othewise it can result in crash during module
unload. Hence created a trig_ptr in the common data structure
for each HID sensor IIO driver and storing here.
Signed-off-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 00582bf8
...@@ -350,7 +350,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) ...@@ -350,7 +350,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
error_iio_unreg: error_iio_unreg:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
error_remove_trigger: error_remove_trigger:
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&accel_state->common_attributes);
error_unreg_buffer_funcs: error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem: error_free_dev_mem:
...@@ -363,10 +363,11 @@ static int hid_accel_3d_remove(struct platform_device *pdev) ...@@ -363,10 +363,11 @@ static int hid_accel_3d_remove(struct platform_device *pdev)
{ {
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct accel_3d_state *accel_state = iio_priv(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D); sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&accel_state->common_attributes);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->channels); kfree(indio_dev->channels);
......
...@@ -55,11 +55,10 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, ...@@ -55,11 +55,10 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
return 0; return 0;
} }
void hid_sensor_remove_trigger(struct iio_dev *indio_dev) void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
{ {
iio_trigger_unregister(indio_dev->trig); iio_trigger_unregister(attrb->trigger);
iio_trigger_free(indio_dev->trig); iio_trigger_free(attrb->trigger);
indio_dev->trig = NULL;
} }
EXPORT_SYMBOL(hid_sensor_remove_trigger); EXPORT_SYMBOL(hid_sensor_remove_trigger);
...@@ -90,7 +89,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, ...@@ -90,7 +89,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
dev_err(&indio_dev->dev, "Trigger Register Failed\n"); dev_err(&indio_dev->dev, "Trigger Register Failed\n");
goto error_free_trig; goto error_free_trig;
} }
indio_dev->trig = trig; indio_dev->trig = attrb->trigger = trig;
return ret; return ret;
......
...@@ -21,6 +21,6 @@ ...@@ -21,6 +21,6 @@
int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
struct hid_sensor_common *attrb); struct hid_sensor_common *attrb);
void hid_sensor_remove_trigger(struct iio_dev *indio_dev); void hid_sensor_remove_trigger(struct hid_sensor_common *attrb);
#endif #endif
...@@ -348,7 +348,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) ...@@ -348,7 +348,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
error_iio_unreg: error_iio_unreg:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
error_remove_trigger: error_remove_trigger:
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&gyro_state->common_attributes);
error_unreg_buffer_funcs: error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem: error_free_dev_mem:
...@@ -361,10 +361,11 @@ static int hid_gyro_3d_remove(struct platform_device *pdev) ...@@ -361,10 +361,11 @@ static int hid_gyro_3d_remove(struct platform_device *pdev)
{ {
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D); sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&gyro_state->common_attributes);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->channels); kfree(indio_dev->channels);
......
...@@ -314,7 +314,7 @@ static int hid_als_probe(struct platform_device *pdev) ...@@ -314,7 +314,7 @@ static int hid_als_probe(struct platform_device *pdev)
error_iio_unreg: error_iio_unreg:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
error_remove_trigger: error_remove_trigger:
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&als_state->common_attributes);
error_unreg_buffer_funcs: error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem: error_free_dev_mem:
...@@ -327,10 +327,11 @@ static int hid_als_remove(struct platform_device *pdev) ...@@ -327,10 +327,11 @@ static int hid_als_remove(struct platform_device *pdev)
{ {
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct als_state *als_state = iio_priv(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS); sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&als_state->common_attributes);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->channels); kfree(indio_dev->channels);
......
...@@ -351,7 +351,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev) ...@@ -351,7 +351,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
error_iio_unreg: error_iio_unreg:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
error_remove_trigger: error_remove_trigger:
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&magn_state->common_attributes);
error_unreg_buffer_funcs: error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem: error_free_dev_mem:
...@@ -364,10 +364,11 @@ static int hid_magn_3d_remove(struct platform_device *pdev) ...@@ -364,10 +364,11 @@ static int hid_magn_3d_remove(struct platform_device *pdev)
{ {
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct magn_3d_state *magn_state = iio_priv(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D); sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
hid_sensor_remove_trigger(indio_dev); hid_sensor_remove_trigger(&magn_state->common_attributes);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->channels); kfree(indio_dev->channels);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/hid.h> #include <linux/hid.h>
#include <linux/hid-sensor-ids.h> #include <linux/hid-sensor-ids.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>
/** /**
* struct hid_sensor_hub_attribute_info - Attribute info * struct hid_sensor_hub_attribute_info - Attribute info
...@@ -184,6 +186,7 @@ struct hid_sensor_common { ...@@ -184,6 +186,7 @@ struct hid_sensor_common {
struct platform_device *pdev; struct platform_device *pdev;
unsigned usage_id; unsigned usage_id;
bool data_ready; bool data_ready;
struct iio_trigger *trigger;
struct hid_sensor_hub_attribute_info poll; struct hid_sensor_hub_attribute_info poll;
struct hid_sensor_hub_attribute_info report_state; struct hid_sensor_hub_attribute_info report_state;
struct hid_sensor_hub_attribute_info power_state; struct hid_sensor_hub_attribute_info power_state;
......
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