Skip to contentSkip to conversation

HID: hid-sensor-custom: remove useless variable

PATCH In review Jiapeng Chong 4 participants 6 messages Apr 9, 2021 – Apr 12, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: hid-sensor-custom: remove useless variable

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable].

---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid-sensor-custom.c +2 -3
index 2628bc5..e430673 100644
@@ -397,15 +397,14 @@ static ssize_t store_value(struct device *dev, struct device_attribute *attr,
 
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst->fields[field_index].attribute.
 								report_id;
-		ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id,
-					     index, sizeof(value), &value);
+		sensor_hub_set_feature(sensor_inst->hsdev, report_id, index,
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;
 
Signature · 1 line
1.8.3.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jiapeng Chong

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’ set but
not used [-Wunused-but-set-variable].

Quoted 32 lines
---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid- renamed from drivers/hid/hid-sensor-custom.c +0 -0

sensor-custom.c
index 2628bc5..e430673 100644

drivers/hid/hid-sensor-custom.c +0 -3
@@ -397,15 +397,14 @@ static ssize_t store_value(struct device *dev,
 struct device_attribute *attr,
 
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst->fields[field_index].attribute.
 								report_
 id;
-		ret = sensor_hub_set_feature(sensor_inst->hsdev,
 report_id,
-					     index, sizeof(value),

&value);

drivers/hid/hid-sensor-custom.c +1 -0
+		sensor_hub_set_feature(sensor_inst->hsdev, report_id,

index,

drivers/hid/hid-sensor-custom.c +1 -0
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;
maintainer
#2 lore raw
Quoted 10 lines · On Fri, 09 Apr 2021 11:19:12 -0700 Srinivas Pandruvada…
Quoted 8 lines · Jiapeng Chong

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’ set but
not used [-Wunused-but-set-variable].

Perhaps better to return ret if it is non zero?
I can't immediately figure out if there is a reason we know that can't happen.

Jonathan

Quoted 34 lines
Quoted 33 lines
---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid- renamed from drivers/hid/hid-sensor-custom.c +0 -0

sensor-custom.c
index 2628bc5..e430673 100644

drivers/hid/hid-sensor-custom.c +0 -3
@@ -397,15 +397,14 @@ static ssize_t store_value(struct device *dev,
 struct device_attribute *attr,
 
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst->fields[field_index].attribute.
 								report_
 id;
-		ret = sensor_hub_set_feature(sensor_inst->hsdev,
 report_id,
-					     index, sizeof(value),

&value);

drivers/hid/hid-sensor-custom.c +1 -0
+		sensor_hub_set_feature(sensor_inst->hsdev, report_id,

index,

drivers/hid/hid-sensor-custom.c +1 -0
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;
#3 lore raw
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 09 Apr 2021 11:19:12 -0700 Srinivas Pandruvada…
Quoted 7 lines · Jiapeng Chong

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’ set
but
not used [-Wunused-but-set-variable].

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Perhaps better to return ret if it is non zero?
I can't immediately figure out if there is a reason we know that can't
happen.

Only time it can fail when there is no report descriptor or the field index is >= report->maxfield.
But since the attribute is registered from the report descriptor and index, this can't happen.
But we can enhance sensor_hub_set_feature() to fail when
hid_set_field() fails. There is one case where field->logical_minimum
< 0 and value is out of range.

Thanks,
Srinivas

Quoted 36 lines

Jonathan

Quoted 33 lines
Quoted 33 lines
---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid- renamed from drivers/hid/hid-sensor-custom.c +0 -0

sensor-custom.c
index 2628bc5..e430673 100644

drivers/hid/hid-sensor-custom.c +0 -3
@@ -397,15 +397,14 @@ static ssize_t store_value(struct device
 *dev,
 struct device_attribute *attr,
 
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst->fields[field_index].attribute.
 								report_
 id;
-		ret = sensor_hub_set_feature(sensor_inst->hsdev,
 report_id,
-					     index, sizeof(value),

&value);

drivers/hid/hid-sensor-custom.c +1 -0
+		sensor_hub_set_feature(sensor_inst->hsdev, report_id,

index,

drivers/hid/hid-sensor-custom.c +1 -0
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;
#4 lore raw
Quoted 20 lines · On Sun, 11 Apr 2021 09:06:35 -0700 Srinivas Pandruvada…
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 09 Apr 2021 11:19:12 -0700 Srinivas Pandruvada…
Quoted 7 lines · Jiapeng Chong

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’ set
but
not used [-Wunused-but-set-variable].

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Perhaps better to return ret if it is non zero?
I can't immediately figure out if there is a reason we know that can't
happen.

Quoted 7 lines

Only time it can fail when there is no report descriptor or the field index is >= report->maxfield.
But since the attribute is registered from the report descriptor and index, this can't happen.
But we can enhance sensor_hub_set_feature() to fail when
hid_set_field() fails. There is one case where field->logical_minimum
< 0 and value is out of range.

I'll go with what you think. Apply as is, or handle the return value because we might at some later date return an error that can actually happen from here?

Jonathan

Quoted 42 lines

Thanks,
Srinivas

Quoted 36 lines

Jonathan

Quoted 33 lines
Quoted 33 lines
---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid- renamed from drivers/hid/hid-sensor-custom.c +0 -0

sensor-custom.c
index 2628bc5..e430673 100644

drivers/hid/hid-sensor-custom.c +0 -3
@@ -397,15 +397,14 @@ static ssize_t store_value(struct device
 *dev,
 struct device_attribute *attr,
 
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst->fields[field_index].attribute.
 								report_
 id;
-		ret = sensor_hub_set_feature(sensor_inst->hsdev,
 report_id,
-					     index, sizeof(value),

&value);

drivers/hid/hid-sensor-custom.c +1 -0
+		sensor_hub_set_feature(sensor_inst->hsdev, report_id,

index,

drivers/hid/hid-sensor-custom.c +1 -0
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;
#5 lore raw
Quoted 34 lines · Jonathan Cameron
Quoted 31 lines · On Sun, 11 Apr 2021 09:06:35 -0700 Srinivas Pandruvada…
Quoted 15 lines · Jonathan Cameron
Quoted 12 lines · On Fri, 09 Apr 2021 11:19:12 -0700 Srinivas Pandruvada…
Quoted 11 lines · Jiapeng Chong

Fix the following gcc warning:

drivers/hid/hid-sensor-custom.c:400:7: warning: variable ‘ret’
set
but
not used [-Wunused-but-set-variable].

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Acked-by: Srinivas Pandruvada <
[email protected]

Perhaps better to return ret if it is non zero?
I can't immediately figure out if there is a reason we know that can't
happen.

Only time it can fail when there is no report descriptor or the field
index is >= report->maxfield.
But since the attribute is registered from the report descriptor and
index, this can't happen.
But we can enhance sensor_hub_set_feature() to fail when
hid_set_field() fails. There is one case where field-

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

logical_minimum

< 0 and value is out of range.

I'll go with what you think. Apply as is, or handle the return value because we might at some later date return an error that can actually happen from here?

I will send you a patch this week to handle error condition.

Thanks,
Srinivas

Quoted 48 lines

Jonathan

Quoted 46 lines

Thanks,
Srinivas

Quoted 42 lines

Jonathan

Quoted 40 lines
Quoted 40 lines
---
 drivers/hid/hid-sensor-custom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid- renamed from drivers/hid/hid-sensor-custom.c +0 -0

sensor-custom.c
index 2628bc5..e430673 100644

drivers/hid/hid-sensor-custom.c +0 -0
@@ -397,15 +397,14 @@ static ssize_t store_value(struct

device
*dev,
struct device_attribute *attr,

drivers/hid/hid-sensor-custom.c +0 -1
 	if (!strncmp(name, "value", strlen("value"))) {
 		u32 report_id;
-		int ret;
 
 		if (kstrtoint(buf, 0, &value) != 0)
 			return -EINVAL;
 
 		report_id = sensor_inst-
Quoted 1 line

fields[field_index].attribute.

report_
id;

drivers/hid/hid-sensor-custom.c +0 -1
-		ret = sensor_hub_set_feature(sensor_inst-
Quoted 1 line

hsdev,

report_id,

drivers/hid/hid-sensor-custom.c +0 -1
-					     index,

sizeof(value),
&value);

drivers/hid/hid-sensor-custom.c +1 -0
+		sensor_hub_set_feature(sensor_inst->hsdev,

report_id,
index,

drivers/hid/hid-sensor-custom.c +1 -0
+				       sizeof(value), &value);
 	} else
 		return -EINVAL;