Thread (12 messages) 12 messages, 7 authors, 2011-12-02
STALE5337d

[PATCH] i2c-mxs: fix compile warning in mxs_i2c_xfer()

From: Dong Aisheng-B29396 <hidden>
Date: 2011-11-24 09:09:15
Also in: linux-i2c

-----Original Message-----
From: Uwe Kleine-K?nig [mailto:u.kleine-koenig at pengutronix.de]
Sent: Thursday, November 24, 2011 5:07 PM
To: Dong Aisheng-B29396
Cc: Wolfram Sang; Shawn Guo; linux-arm-kernel at lists.infradead.org; Ben
Dooks; linux-i2c at vger.kernel.org
Subject: Re: [PATCH] i2c-mxs: fix compile warning in mxs_i2c_xfer()

Hello,

On Thu, Nov 24, 2011 at 09:02:21AM +0000, Dong Aisheng-B29396 wrote:
quoted
quoted
quoted
quoted
diff --git a/drivers/i2c/busses/i2c-mxs.c
b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -193,7 +193,7 @@ static int mxs_i2c_wait_for_data(struct
mxs_i2c_dev *i2c)

 static int mxs_i2c_finish_read(struct mxs_i2c_dev *i2c, u8
*buf, int len)  {
-	u32 data;
+	u32 data = 0;
 	int i;

 	for (i = 0; i < len; i++) {
Looks like a stupid compiler. Then better use

	u32 uninitialized_var(data);
Leave it as it is and fix the compiler? Will do another test later
to make sure.
Compiler is wrong?
Just from the code that it seems to be right the 'data' might be used
uninitialized.

Something I missed?

static int mxs_i2c_finish_read(struct mxs_i2c_dev *i2c, u8 *buf, int
len) {
        u32 data;
        int i;

        for (i = 0; i < len; i++) {
                if ((i & 3) == 0) {
                        if (mxs_i2c_wait_for_data(i2c))
                                return -ETIMEDOUT;
                        data = readl(i2c->regs + MXS_I2C_QUEUEDATA);
                }
                buf[i] = data & 0xff;
                data >>= 8;
        }
When data is used the first time, i is 0, so it went through the body of
the if above before which assigned data. So no, data is initialized when
used to assign buf[i].
Ok, Thanks for the info.
So the compiler should do intelligent checking.

Regards
Dong Aisheng
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help