Skip to contentSkip to conversation

HID: sensors: remove some unneeded checks

PATCH In review Dan Carpenter 4 participants 4 messages Sep 14, 2012 – Sep 18, 2012

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

PATCH 2/2 HID: sensors: remove some unneeded checks

"report_id" is unsigned so it's never less than zero. These checks can be removed without any problem.

drivers/hid/hid-sensor-hub.c +0 -9
index 0c93b10..22ec3c6 100644
@@ -214,9 +214,6 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) {
@@ -241,9 +238,6 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) {
@@ -271,9 +265,6 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 	struct hid_report *report;
 	int ret_val = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	memset(&data->pending, 0, sizeof(data->pending));
 	init_completion(&data->pending.ready);
#1 lore raw
Quoted 4 lines · Dan Carpenter

"report_id" is unsigned so it's never less than zero. These checks can be removed without any problem.

Adding Jonathan to CC as well. Thanks.

Quoted 36 lines
drivers/hid/hid-sensor-hub.c +0 -9
index 0c93b10..22ec3c6 100644
@@ -214,9 +214,6 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) {
@@ -241,9 +238,6 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) {
@@ -271,9 +265,6 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 	struct hid_report *report;
 	int ret_val = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	memset(&data->pending, 0, sizeof(data->pending));
 	init_completion(&data->pending.ready);
Signature · 2 lines
Jiri Kosina
SUSE Labs
#2 lore raw

Tested this and it works.

-----Original Message-----
From: Jiri Kosina [mailto:[email protected]]
Sent: Monday, September 17, 2012 4:00 AM
To: Dan Carpenter
Cc: Pandruvada, Srinivas; [email protected]; [email protected]; Jonathan Cameron
Subject: Re: [patch 2/2] HID: sensors: remove some unneeded checks

Quoted 4 lines · Dan Carpenter

"report_id" is unsigned so it's never less than zero. These checks can be removed without any problem.

Adding Jonathan to CC as well. Thanks.

Quoted 26 lines
(quoted diff) +0 -0

b/drivers/hid/hid-sensor-hub.c index 0c93b10..22ec3c6 100644

drivers/hid/hid-sensor-hub.c +1 -6
@@ -214,9 +214,6 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) { @@ -241,9 
+238,6 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) { @@ -271,9 

drivers/hid/hid-sensor-hub.c int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,

Quoted 10 lines
drivers/hid/hid-sensor-hub.c +1 -3
+265,6 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 	struct hid_report *report;
 	int ret_val = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	memset(&data->pending, 0, sizeof(data->pending));
 	init_completion(&data->pending.ready);

--
Jiri Kosina
SUSE Labs

maintainer
#3 lore raw

I've add these both to the togreg branch of

git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Will send onwards in a few days.

Quoted 61 lines

Tested this and it works.

-----Original Message-----
From: Jiri Kosina [mailto:[email protected]]
Sent: Monday, September 17, 2012 4:00 AM
To: Dan Carpenter
Cc: Pandruvada, Srinivas; [email protected]; [email protected]; Jonathan Cameron
Subject: Re: [patch 2/2] HID: sensors: remove some unneeded checks

Quoted 4 lines · Dan Carpenter

"report_id" is unsigned so it's never less than zero. These checks can be removed without any problem.

Adding Jonathan to CC as well. Thanks.

Quoted 26 lines
(quoted diff) +0 -0

b/drivers/hid/hid-sensor-hub.c index 0c93b10..22ec3c6 100644

drivers/hid/hid-sensor-hub.c +1 -6
@@ -214,9 +214,6 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) { @@ -241,9 
+238,6 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
 	int ret = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
 	if (!report || (field_index >=  report->maxfield)) { @@ -271,9 

drivers/hid/hid-sensor-hub.c int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,

Quoted 10 lines
drivers/hid/hid-sensor-hub.c +1 -3
+265,6 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 	struct hid_report *report;
 	int ret_val = 0;
 
-	if (report_id < 0)
-		return -EINVAL;
-
 	mutex_lock(&data->mutex);
 	memset(&data->pending, 0, sizeof(data->pending));
 	init_completion(&data->pending.ready);

--
Jiri Kosina
SUSE Labs