All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: hid-sensor-attributes: Fix sensor property setting failure.
@ 2017-03-28 14:23 ` Song Hongyan
  0 siblings, 0 replies; 4+ messages in thread
From: Song Hongyan @ 2017-03-28 14:23 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA, linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: jikos-DgEjT+Ai2ygdnm+yROfE0A, jic23-DgEjT+Ai2ygdnm+yROfE0A,
	srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w, Song Hongyan

When system bootup without get sensor property, set sensor
property will be fail.

If no get_feature operation done before set_feature, the sensor
properties will all be the initialized value, which is not the
same with sensor real properties. When set sensor property it will
write back to sensor the changed perperty data combines with other
sensor properties data, it is not right and may be dangerous.

In order to get all sensor properties, choose to read one of the sensor
properties(no matter read any sensor peroperty, driver will get all
the peroperties and return the requested one).

Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
Signed-off-by: Song Hongyan <hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7afdac42..01e02b9 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -379,6 +379,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 {
 
 	struct hid_sensor_hub_attribute_info timestamp;
+	s32 value;
+	int ret;
 
 	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
 
@@ -417,6 +419,14 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 		st->sensitivity.index, st->sensitivity.report_id,
 		timestamp.index, timestamp.report_id);
 
+	ret = sensor_hub_get_feature(hsdev,
+				st->power_state.report_id,
+				st->power_state.index, sizeof(value), &value);
+	if (ret < 0)
+		return ret;
+	if (value < 0)
+		return -EINVAL;
+
 	return 0;
 }
 EXPORT_SYMBOL(hid_sensor_parse_common_attributes);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] iio: hid-sensor-attributes: Fix sensor property setting failure.
@ 2017-03-28 14:23 ` Song Hongyan
  0 siblings, 0 replies; 4+ messages in thread
From: Song Hongyan @ 2017-03-28 14:23 UTC (permalink / raw)
  To: linux-input, linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

When system bootup without get sensor property, set sensor
property will be fail.

If no get_feature operation done before set_feature, the sensor
properties will all be the initialized value, which is not the
same with sensor real properties. When set sensor property it will
write back to sensor the changed perperty data combines with other
sensor properties data, it is not right and may be dangerous.

In order to get all sensor properties, choose to read one of the sensor
properties(no matter read any sensor peroperty, driver will get all
the peroperties and return the requested one).

Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
Signed-off-by: Song Hongyan <hongyan.song@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7afdac42..01e02b9 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -379,6 +379,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 {
 
 	struct hid_sensor_hub_attribute_info timestamp;
+	s32 value;
+	int ret;
 
 	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
 
@@ -417,6 +419,14 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 		st->sensitivity.index, st->sensitivity.report_id,
 		timestamp.index, timestamp.report_id);
 
+	ret = sensor_hub_get_feature(hsdev,
+				st->power_state.report_id,
+				st->power_state.index, sizeof(value), &value);
+	if (ret < 0)
+		return ret;
+	if (value < 0)
+		return -EINVAL;
+
 	return 0;
 }
 EXPORT_SYMBOL(hid_sensor_parse_common_attributes);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: hid-sensor-attributes: Fix sensor property setting failure.
  2017-03-28 14:23 ` Song Hongyan
@ 2017-04-02 10:44     ` Jonathan Cameron
  -1 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-04-02 10:44 UTC (permalink / raw)
  To: Song Hongyan, linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: jikos-DgEjT+Ai2ygdnm+yROfE0A, srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w

On 28/03/17 15:23, Song Hongyan wrote:
> When system bootup without get sensor property, set sensor
> property will be fail.
> 
> If no get_feature operation done before set_feature, the sensor
> properties will all be the initialized value, which is not the
> same with sensor real properties. When set sensor property it will
> write back to sensor the changed perperty data combines with other
> sensor properties data, it is not right and may be dangerous.
> 
> In order to get all sensor properties, choose to read one of the sensor
> properties(no matter read any sensor peroperty, driver will get all
> the peroperties and return the requested one).
> 
> Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
> Signed-off-by: Song Hongyan <hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
Nicely presented patch.  One slight improvement for next time would be
to put what the changes from v1 to v2 are here in the comments section.
Saves reviewers having to find the previous version to see what needed
addressing (very little here!)

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
>  drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 7afdac42..01e02b9 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -379,6 +379,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  {
>  
>  	struct hid_sensor_hub_attribute_info timestamp;
> +	s32 value;
> +	int ret;
>  
>  	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
>  
> @@ -417,6 +419,14 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  		st->sensitivity.index, st->sensitivity.report_id,
>  		timestamp.index, timestamp.report_id);
>  
> +	ret = sensor_hub_get_feature(hsdev,
> +				st->power_state.report_id,
> +				st->power_state.index, sizeof(value), &value);
> +	if (ret < 0)
> +		return ret;
> +	if (value < 0)
> +		return -EINVAL;
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL(hid_sensor_parse_common_attributes);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: hid-sensor-attributes: Fix sensor property setting failure.
@ 2017-04-02 10:44     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-04-02 10:44 UTC (permalink / raw)
  To: Song Hongyan, linux-input, linux-iio; +Cc: jikos, srinivas.pandruvada

On 28/03/17 15:23, Song Hongyan wrote:
> When system bootup without get sensor property, set sensor
> property will be fail.
> 
> If no get_feature operation done before set_feature, the sensor
> properties will all be the initialized value, which is not the
> same with sensor real properties. When set sensor property it will
> write back to sensor the changed perperty data combines with other
> sensor properties data, it is not right and may be dangerous.
> 
> In order to get all sensor properties, choose to read one of the sensor
> properties(no matter read any sensor peroperty, driver will get all
> the peroperties and return the requested one).
> 
> Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
> Signed-off-by: Song Hongyan <hongyan.song@intel.com>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
Nicely presented patch.  One slight improvement for next time would be
to put what the changes from v1 to v2 are here in the comments section.
Saves reviewers having to find the previous version to see what needed
addressing (very little here!)

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
>  drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 7afdac42..01e02b9 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -379,6 +379,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  {
>  
>  	struct hid_sensor_hub_attribute_info timestamp;
> +	s32 value;
> +	int ret;
>  
>  	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
>  
> @@ -417,6 +419,14 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>  		st->sensitivity.index, st->sensitivity.report_id,
>  		timestamp.index, timestamp.report_id);
>  
> +	ret = sensor_hub_get_feature(hsdev,
> +				st->power_state.report_id,
> +				st->power_state.index, sizeof(value), &value);
> +	if (ret < 0)
> +		return ret;
> +	if (value < 0)
> +		return -EINVAL;
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL(hid_sensor_parse_common_attributes);
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-02 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-28 14:23 [PATCH v2] iio: hid-sensor-attributes: Fix sensor property setting failure Song Hongyan
2017-03-28 14:23 ` Song Hongyan
     [not found] ` <1490711035-19852-1-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-04-02 10:44   ` Jonathan Cameron
2017-04-02 10:44     ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.