Skip to contentSkip to conversation

Input: bcm5974.c initialize raw_w, raw_x and raw_y before it get used

PATCH In review Jaswinder Singh Rajput 3 participants 7 messages Sep 12, 2009 – Sep 15, 2009

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

PATCH 1/1 Input: bcm5974.c initialize raw_w, raw_x and raw_y before it get used

raw_w, raw_x and raw_y is used uninitialized for !raw_n

This also fixed these compilation warnings :

CC [M] drivers/input/mouse/bcm5974.o
drivers/input/mouse/bcm5974.c: In function ‘report_tp_state’:
drivers/input/mouse/bcm5974.c:319: warning: ‘raw_y’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_x’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_w’ may be used uninitialized in this function

---
 drivers/input/mouse/bcm5974.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/input/mouse/bcm5974.c +2 -1
index 2d8fc0b..171f345 100644
@@ -345,7 +345,8 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 		/* set the integrated button if applicable */
 		if (c->tp_type == TYPE2)
 			ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
-	}
+	} else
+		raw_w = raw_x = raw_y = 0;
 
 	/* while tracking finger still valid, count all fingers */
 	if (ptest > PRESSURE_LOW && origin) {
Signature · 7 lines
1.6.4.2


--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#1 lore raw
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Quoted 18 lines

This also fixed these compilation warnings :

CC [M] drivers/input/mouse/bcm5974.o
drivers/input/mouse/bcm5974.c: In function ‘report_tp_state’:
drivers/input/mouse/bcm5974.c:319: warning: ‘raw_y’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_x’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_w’ may be used uninitialized in this function

---
 drivers/input/mouse/bcm5974.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/input/mouse/bcm5974.c +0 -0
index 2d8fc0b..171f345 100644

drivers/input/mouse/bcm5974.c static int report_tp_state(struct bcm5974 *dev, int size) · line 352

Quoted 9 lines
drivers/input/mouse/bcm5974.c +2 -1
@@ -345,7 +345,8 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 		/* set the integrated button if applicable */
 		if (c->tp_type == TYPE2)
 			ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
-	}
+	} else
+		raw_w = raw_x = raw_y = 0;
 
 	/* while tracking finger still valid, count all fingers */
 	if (ptest > PRESSURE_LOW && origin) {

I would prefer treating raw_p on the same footing here, completing the set of non-obviously initialized variables. It might also make sense to utilize the same initialization technique already used in the code, thus:

drivers/input/mouse/bcm5974.c +1 -1
index 2d8fc0b..2f85876 100644
@@ -316,7 +316,7 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 	const struct bcm5974_config *c = &dev->cfg;
 	const struct tp_finger *f;
 	struct input_dev *input = dev->input;
-	int raw_p, raw_w, raw_x, raw_y, raw_n;
+	int raw_p = 0, raw_w = 0, raw_x = 0, raw_y = 0, raw_n;
 	int ptest = 0, origin = 0, ibt = 0, nmin = 0, nmax = 0;
 	int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
 

I wonder how many cpu cycles in the world are spent making compilers happy.

Cheers,
Henrik
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Henrik Rydberg
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Then can we move 'if (ptest > PRESSURE_LOW && origin)' stuff to 'if (raw_n)'. If not then my patch is correct.

Quoted 25 lines
Quoted 25 lines

This also fixed these compilation warnings :

CC [M] drivers/input/mouse/bcm5974.o
drivers/input/mouse/bcm5974.c: In function ‘report_tp_state’:
drivers/input/mouse/bcm5974.c:319: warning: ‘raw_y’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_x’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_w’ may be used uninitialized in this function

---
 drivers/input/mouse/bcm5974.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/input/mouse/bcm5974.c +2 -1
index 2d8fc0b..171f345 100644
@@ -345,7 +345,8 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 		/* set the integrated button if applicable */
 		if (c->tp_type == TYPE2)
 			ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
-	}
+	} else
+		raw_w = raw_x = raw_y = 0;
 
Quoted 7 lines

drivers/input/mouse/bcm5974.c static int report_tp_state(struct bcm5974 *dev, int size) · line 352

Quoted 2 lines
drivers/input/mouse/bcm5974.c +0 -0
 	/* while tracking finger still valid, count all fingers */
 	if (ptest > PRESSURE_LOW && origin) {

I would prefer treating raw_p on the same footing here, completing the set of non-obviously initialized variables. It might also make sense to utilize the same initialization technique already used in the code, thus:

No, then you are wasting cpu cycles and doing double initialization for some cases.

Quoted 14 lines
drivers/input/mouse/bcm5974.c +1 -1
index 2d8fc0b..2f85876 100644
@@ -316,7 +316,7 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 	const struct bcm5974_config *c = &dev->cfg;
 	const struct tp_finger *f;
 	struct input_dev *input = dev->input;
-	int raw_p, raw_w, raw_x, raw_y, raw_n;
+	int raw_p = 0, raw_w = 0, raw_x = 0, raw_y = 0, raw_n;
 	int ptest = 0, origin = 0, ibt = 0, nmin = 0, nmax = 0;
 	int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
 
Quoted 2 lines

I wonder how many cpu cycles in the world are spent making compilers happy.

It is not compiler mistake it is programming/logic mistakes. We should be thankful to compiler to pointing mistakes made by us.

Thanks,
--
JSR

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#3 lore raw
Quoted 9 lines · Jaswinder Singh Rajput
Quoted 5 lines · Henrik Rydberg
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Then can we move 'if (ptest > PRESSURE_LOW && origin)' stuff to 'if (raw_n)'. If not then my patch is correct.

Yes, that's it, thanks. So this patch ought to solve the warning cleanly:

drivers/input/mouse/bcm5974.c +15 -14
index 2d8fc0b..3b598de 100644
@@ -345,21 +345,22 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 		/* set the integrated button if applicable */
 		if (c->tp_type == TYPE2)
 			ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
-	}
 
-	/* while tracking finger still valid, count all fingers */
-	if (ptest > PRESSURE_LOW && origin) {
-		abs_p = ptest;
-		abs_w = int2bound(&c->w, raw_w);
-		abs_x = int2bound(&c->x, raw_x - c->x.devmin);
-		abs_y = int2bound(&c->y, c->y.devmax - raw_y);
-		while (raw_n--) {
-			ptest = int2bound(&c->p, raw2int(f->force_major));
-			if (ptest > PRESSURE_LOW)
-				nmax++;
-			if (ptest > PRESSURE_HIGH)
-				nmin++;
-			f++;
+		/* while tracking finger still valid, count all fingers */
+		if (ptest > PRESSURE_LOW && origin) {
+			abs_p = ptest;
+			abs_w = int2bound(&c->w, raw_w);
+			abs_x = int2bound(&c->x, raw_x - c->x.devmin);
+			abs_y = int2bound(&c->y, c->y.devmax - raw_y);
+			while (raw_n--) {
+				ptest = int2bound(&c->p,
+						  raw2int(f->force_major));
+				if (ptest > PRESSURE_LOW)
+					nmax++;
+				if (ptest > PRESSURE_HIGH)
+					nmin++;
+				f++;
+			}
 		}
 	}
 
Quoted 50 lines
Quoted 26 lines
Quoted 26 lines

This also fixed these compilation warnings :

CC [M] drivers/input/mouse/bcm5974.o
drivers/input/mouse/bcm5974.c: In function ‘report_tp_state’:
drivers/input/mouse/bcm5974.c:319: warning: ‘raw_y’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_x’ may be used uninitialized in this function drivers/input/mouse/bcm5974.c:319: warning: ‘raw_w’ may be used uninitialized in this function

---
 drivers/input/mouse/bcm5974.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/input/mouse/bcm5974.c +2 -1
index 2d8fc0b..171f345 100644
@@ -345,7 +345,8 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 		/* set the integrated button if applicable */
 		if (c->tp_type == TYPE2)
 			ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
-	}
+	} else
+		raw_w = raw_x = raw_y = 0;
 
Quoted 6 lines

drivers/input/mouse/bcm5974.c static int report_tp_state(struct bcm5974 *dev, int size) · line 352

Quoted 2 lines
drivers/input/mouse/bcm5974.c +0 -0
 	/* while tracking finger still valid, count all fingers */
 	if (ptest > PRESSURE_LOW && origin) {

I would prefer treating raw_p on the same footing here, completing the set of non-obviously initialized variables. It might also make sense to utilize the same initialization technique already used in the code, thus:

No, then you are wasting cpu cycles and doing double initialization for some cases.

Quoted 14 lines
drivers/input/mouse/bcm5974.c +1 -1
index 2d8fc0b..2f85876 100644
@@ -316,7 +316,7 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 	const struct bcm5974_config *c = &dev->cfg;
 	const struct tp_finger *f;
 	struct input_dev *input = dev->input;
-	int raw_p, raw_w, raw_x, raw_y, raw_n;
+	int raw_p = 0, raw_w = 0, raw_x = 0, raw_y = 0, raw_n;
 	int ptest = 0, origin = 0, ibt = 0, nmin = 0, nmax = 0;
 	int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
 
Quoted 5 lines
Quoted 2 lines

I wonder how many cpu cycles in the world are spent making compilers happy.

It is not compiler mistake it is programming/logic mistakes. We should be thankful to compiler to pointing mistakes made by us.

The uninitialized-variable warnings have certainly proved their value many times over. I was merely reflecting over the fact that the enclosing space of all such errors could be made smaller by deduction at compile time.

Cheers,
Henrik

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw
Quoted 4 lines · Henrik Rydberg
Quoted 3 lines · Jaswinder Singh Rajput
Quoted 2 lines · Henrik Rydberg
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Then can we move 'if (ptest > PRESSURE_LOW && origin)' stuff to 'if (raw_n)'. If not then my patch is correct.

Yes, that's it, thanks. So this patch ought to solve the warning cleanly:

Yes, I like this one much better, applied.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I wonder how many cpu cycles in the world are spent making compilers happy.

It is not compiler mistake it is programming/logic mistakes. We should be thankful to compiler to pointing mistakes made by us.

Except in cases when the compiler is wrong...

Quoted 4 lines

The uninitialized-variable warnings have certainly proved their value many times over. I was merely reflecting over the fact that the enclosing space of all such errors could be made smaller by deduction at compile time.

Signature · 1 line
Dmitry
#5 lore raw
In reply to Henrik Rydberg

Hello Henrik,

Quoted 4 lines · Henrik Rydberg
Quoted 3 lines · Jaswinder Singh Rajput
Quoted 2 lines · Henrik Rydberg
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Then can we move 'if (ptest > PRESSURE_LOW && origin)' stuff to 'if (raw_n)'. If not then my patch is correct.

Yes, that's it, thanks. So this patch ought to solve the warning cleanly:

hmm, even then there is room for improvement and save some cpu cycles :

drivers/input/mouse/bcm5974.c +4 -2
index 2d8fc0b..21ea2e3 100644
@@ -316,8 +316,7 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 	const struct bcm5974_config *c = &dev->cfg;
 	const struct tp_finger *f;
 	struct input_dev *input = dev->input;
-	int raw_p, raw_w, raw_x, raw_y, raw_n;
-	int ptest = 0, origin = 0, ibt = 0, nmin = 0, nmax = 0;
+	int raw_n, ibt = 0, nmin = 0, nmax = 0;
 	int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
 
 	if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0)
@@ -329,6 +328,9 @@ static int report_tp_state(struct bcm5974 *dev, int size)
 
 	/* always track the first finger; when detached, start over */
 	if (raw_n) {
+		int raw_p, raw_w, raw_x, raw_y;
+		int ptest, origin;
+
 		raw_p = raw2int(f->force_major);
 		raw_w = raw2int(f->size_major);
 		raw_x = raw2int(f->abs_x);

And by changing little bit programming logic you can also reduce variable count and save some more cpu cycles.

Thanks,
--
JSR

maintainer
#6 lore raw
Quoted 7 lines · Jaswinder Singh Rajput

Hello Henrik,

Quoted 4 lines · Henrik Rydberg
Quoted 3 lines · Jaswinder Singh Rajput
Quoted 2 lines · Henrik Rydberg
Quoted 1 line · Jaswinder Singh Rajput

raw_w, raw_x and raw_y is used uninitialized for !raw_n

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Thanks for the heads up, but actually not, since !raw_n also implies !(ptest > PRESSURE_LOW).

Then can we move 'if (ptest > PRESSURE_LOW && origin)' stuff to 'if (raw_n)'. If not then my patch is correct.

Yes, that's it, thanks. So this patch ought to solve the warning cleanly:

hmm, even then there is room for improvement and save some cpu cycles :

Thanks, ill keep this one in reserve.

Henrik