Skip to contentSkip to conversation

i2c-mxs: fix compile warning in mxs_i2c_xfer()

PATCH New Shawn Guo 7 participants 12 messages Nov 24, 2011 – Dec 2, 2011

Subsystems (2)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mxs.c +1 -1
index 7e78f7c..00f098f 100644
@@ -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++) {
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 5 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

Which compiler? What flags? I don't see that here.

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111124/780636bf/attachment.sig>
#2 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 9 lines · Wolfram Sang
Quoted 5 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

Which compiler? What flags? I don't see that here.

gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu3)

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j 2 zImage
Signature · 2 lines
Regards,
Shawn
#3 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

In reply to Shawn Guo

Hello Shawn,

Quoted 14 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mxs.c +0 -0
index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c) · line 199

Quoted 8 lines
drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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);

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#4 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 24 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 21 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mxs.c +1 -1
index 7e78f7c..00f098f 100644
@@ -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;
 
Quoted 4 lines

drivers/i2c/busses/i2c-mxs.c static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c) · line 199

Quoted 1 line
drivers/i2c/busses/i2c-mxs.c +0 -0
 	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.

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111124/5712290e/attachment.sig>
#5 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 36 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm- kernel-bounces at lists.infradead.org] On Behalf Of Wolfram Sang
Sent: Thursday, November 24, 2011 4:38 PM
To: Uwe Kleine-K?nig
Cc: 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()

Quoted 26 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 23 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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;
 
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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;
        }

        return 0;
}

Regards
Dong Aisheng

#6 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Hello,

Quoted 29 lines · On Thu, Nov 24, 2011 at 09:02:21AM +0000, Dong Aisheng-B29396 wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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;
 
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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)

Quoted 13 lines
{
        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].

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#7 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 53 lines

-----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,

Quoted 29 lines · On Thu, Nov 24, 2011 at 09:02:21AM +0000, Dong Aisheng-B29396 wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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;
 
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 13 lines
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;
        }
Quoted 4 lines

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

#8 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

In reply to Dong Aisheng-B29396

Hi,

Quoted 41 lines · Dong Aisheng-B29396 writes:
Quoted 41 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm- kernel-bounces at lists.infradead.org] On Behalf Of Wolfram Sang
Sent: Thursday, November 24, 2011 4:38 PM
To: Uwe Kleine-K?nig
Cc: 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()

Quoted 30 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 23 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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;
 
Quoted 1 line

for (i = 0; i < len; i++) {

Looks like a stupid compiler. Then better use

	u32 uninitialized_var(data);
Quoted 8 lines
Quoted 3 lines

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.

Only iff you assume that (0 & 3) could be != 0...

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#9 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

In reply to Wolfram Sang
Quoted 25 lines · Wolfram Sang
Quoted 24 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 21 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mxs.c +1 -1
index 7e78f7c..00f098f 100644
@@ -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;
 
Quoted 8 lines
Quoted 4 lines

drivers/i2c/busses/i2c-mxs.c static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c) · line 199

Quoted 1 line
drivers/i2c/busses/i2c-mxs.c +0 -0
 	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.

Ben, do you have an opinion on this, leave it there or fix it?

Signature · 2 lines
Regards,
Shawn
#10 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 29 lines · Shawn Guo
Quoted 28 lines · Wolfram Sang
Quoted 27 lines · Uwe Kleine-K?nig

Hello Shawn,

Quoted 14 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o
drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---
 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mxs.c +0 -0
index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c) · line 199

Quoted 8 lines
drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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

Quoted 6 lines
Quoted 5 lines
Quoted 1 line
	u32 uninitialized_var(data);

Leave it as it is and fix the compiler? Will do another test later to make sure.

Ben, do you have an opinion on this, leave it there or fix it?

Sorry, forgot the tests yesterday. I don't like random annotations because of faulty compilers. Please fix that one. NACK from me.

Signature · 9 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20111125/d660798d/attachment.sig>
#11 lore raw

PATCH 1/1 i2c-mxs: fix compile warning in mxs_i2c_xfer()

Quoted 39 lines · Shawn Guo
Quoted 38 lines · Wolfram Sang
Quoted 37 lines · Uwe Kleine-K?nig
Quoted 35 lines

Hello Shawn,

Quoted 25 lines · Shawn Guo

CC drivers/i2c/busses/i2c-mxs.o

drivers/i2c/busses/i2c-mxs.c: In function ?mxs_i2c_xfer?:
drivers/i2c/busses/i2c-mxs.c:196:6: warning: ?data? may be used uninitialized in this function

---

 drivers/i2c/busses/i2c-mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-mxs.c index 7e78f7c..00f098f 100644

drivers/i2c/busses/i2c-mxs.c +1 -1
@@ -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;
 

drivers/i2c/busses/i2c-mxs.c static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c) · line 199

Quoted 3 lines
drivers/i2c/busses/i2c-mxs.c +0 -0
 	int i;
 
 	for (i = 0; i < len; i++) {

Looks like a stupid compiler. Then better use

	u32 uninitialized_var(data);
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Leave it as it is and fix the compiler? Will do another test later to make sure.

Ben, do you have an opinion on this, leave it there or fix it?

Sorry, forgot the tests yesterday. I don't like random annotations because of faulty compilers. Please fix that one. NACK from me.

Hi,

I hit this with emdebian gcc 4.6.1 ... I'd be for merging this u32 data = 0; stuff, so on my side it's ACK.

M