iio: hid-sensor-attributes: Fix sensor property setting failure.

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>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by Song Hongyan and committed by Jonathan Cameron bba6d9e4 862d1d89

+10
+10
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
··· 379 { 380 381 struct hid_sensor_hub_attribute_info timestamp; 382 383 hid_sensor_get_reporting_interval(hsdev, usage_id, st); 384 ··· 418 st->power_state.index, st->power_state.report_id, 419 st->sensitivity.index, st->sensitivity.report_id, 420 timestamp.index, timestamp.report_id); 421 422 return 0; 423 }
··· 379 { 380 381 struct hid_sensor_hub_attribute_info timestamp; 382 + s32 value; 383 + int ret; 384 385 hid_sensor_get_reporting_interval(hsdev, usage_id, st); 386 ··· 416 st->power_state.index, st->power_state.report_id, 417 st->sensitivity.index, st->sensitivity.report_id, 418 timestamp.index, timestamp.report_id); 419 + 420 + ret = sensor_hub_get_feature(hsdev, 421 + st->power_state.report_id, 422 + st->power_state.index, sizeof(value), &value); 423 + if (ret < 0) 424 + return ret; 425 + if (value < 0) 426 + return -EINVAL; 427 428 return 0; 429 }