From patchwork Sun Sep 13 11:39:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 47142 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8DBdVbw004584 for ; Sun, 13 Sep 2009 11:39:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751627AbZIMLj0 (ORCPT ); Sun, 13 Sep 2009 07:39:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752418AbZIMLj0 (ORCPT ); Sun, 13 Sep 2009 07:39:26 -0400 Received: from csmtp2.one.com ([195.47.247.206]:58119 "EHLO csmtp2.one.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751627AbZIMLj0 (ORCPT ); Sun, 13 Sep 2009 07:39:26 -0400 Received: from [192.168.1.100] (host-90-237-157-89.mobileonline.telia.com [90.237.157.89]) by csmtp2.one.com (Postfix) with ESMTP id 3AFDC1B00300F; Sun, 13 Sep 2009 11:39:25 +0000 (UTC) Message-ID: <4AACD9E9.4000702@bitmath.org> Date: Sun, 13 Sep 2009 13:39:21 +0200 From: Henrik Rydberg User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Jaswinder Singh Rajput CC: Dmitry Torokhov , linux-input@vger.kernel.org Subject: Re: [PATCH] Input: bcm5974.c initialize raw_w, raw_x and raw_y before it get used References: <1252775770.3687.7.camel@ht.satnam> <4AAC2DBE.9040303@bitmath.org> <1252830690.3440.5.camel@ht.satnam> In-Reply-To: <1252830690.3440.5.camel@ht.satnam> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Jaswinder Singh Rajput wrote: > On Sun, 2009-09-13 at 01:24 +0200, Henrik Rydberg wrote: >> Jaswinder Singh Rajput wrote: >>> 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: > >>> 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 >>> >>> Signed-off-by: Jaswinder Singh Rajput >>> --- >>> drivers/input/mouse/bcm5974.c | 3 ++- >>> 1 files changed, 2 insertions(+), 1 deletions(-) >>> >>> diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c >>> index 2d8fc0b..171f345 100644 >>> --- a/drivers/input/mouse/bcm5974.c >>> +++ b/drivers/input/mouse/bcm5974.c >>> @@ -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: >> > > No, then you are wasting cpu cycles and doing double initialization for > some cases. > >> diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c >> index 2d8fc0b..2f85876 100644 >> --- a/drivers/input/mouse/bcm5974.c >> +++ b/drivers/input/mouse/bcm5974.c >> @@ -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. >> > > 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c index 2d8fc0b..3b598de 100644 --- a/drivers/input/mouse/bcm5974.c +++ b/drivers/input/mouse/bcm5974.c @@ -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++; + } } }