Skip to contentSkip to conversation

fix i2c_pca_pf_waitforcompletion() return value

PATCH Superseded Yegor Yefremov 2 participants 5 messages Sep 20, 2010 – Sep 22, 2010 4 messages not in the archive I2C subsystem host drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix i2c_pca_pf_waitforcompletion() return value

ret is still -1, if during the polling read_byte() returns at once with I2C_PCA_CON_SI set. So ret > 0 would lead i2c_pca_pf_waitforcompletion() to return 0, in spite of the proper behavior. That's why only ret should be returned.

drivers/i2c/busses/i2c-pca-platform.c +1 -1
Index: b/drivers/i2c/busses/i2c-pca-platform.c
===================================================================
@@ -96,7 +96,7 @@
 			udelay(100);
 	}
 
-	return ret > 0;
+	return ret;
 }
 
 static void i2c_pca_pf_dummyreset(void *pd)
#2 lore raw
In reply to a message not in the archive
Quoted 6 lines · Yegor Yefremov

ret is still -1, if during the polling read_byte() returns at once with I2C_PCA_CON_SI set. So ret > 0 would lead i2c_pca_pf_waitforcompletion() to return 0, in spite of the proper behavior. That's why only ret should be returned.

Thanks for reporting. In deed, this needs to be corrected. However, I think we should clean up the code some more and get rid of the initialization of ret altogether (and hopefully make it more readable with this). Do you have time for this, otherwise I'll have a look later.

Regards,

Wolfram

Quoted 19 lines

Index: b/drivers/i2c/busses/i2c-pca-platform.c
===================================================================

drivers/i2c/busses/i2c-pca-platform.c +1 -2
@@ -96,7 +96,7 @@
 			udelay(100);
 	}
 
-	return ret > 0;
+	return ret;
 }
 
 static void i2c_pca_pf_dummyreset(void *pd)
 
--

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

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#4 lore raw
In reply to a message not in the archive
Quoted 6 lines

Thanks for reporting. In deed, this needs to be corrected. However, I think we should clean up the code some more and get rid of the initialization of ret altogether (and hopefully make it more readable with this). Do you have time for this, otherwise I'll have a look later.

This is a fix of a problem discussed in this thread http://www.spinics.net/lists/linux-i2c/msg02861.html.

Best regards,
Yegor

#6 lore raw
In reply to a message not in the archive
drivers/i2c/busses/i2c-pca-platform.c +7 -4
Index: b/drivers/i2c/busses/i2c-pca-platform.c
===================================================================
@@ -80,8 +80,8 @@
 static int i2c_pca_pf_waitforcompletion(void *pd)
 {
 	struct i2c_pca_pf_data *i2c = pd;
-	long ret = ~0;
 	unsigned long timeout;
+	long ret;
 
 	if (i2c->irq) {
 		ret = wait_event_timeout(i2c->wait,
@@ -90,10 +90,13 @@
 	} else {
 		/* Do polling */
 		timeout = jiffies + i2c->adap.timeout;
-		while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
-				& I2C_PCA_CON_SI) == 0)
-				&& (ret = time_before(jiffies, timeout)))
+		do {
+			ret = time_before(jiffies, timeout);
+			if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
+				& I2C_PCA_CON_SI)
+				break;
 			udelay(100);
+		} while (ret);
 	}
 
 	return ret > 0;
drivers/i2c/busses/i2c-pca-isa.c +8 -4
Index: b/drivers/i2c/busses/i2c-pca-isa.c
===================================================================
@@ -71,8 +71,8 @@
 
 static int pca_isa_waitforcompletion(void *pd)
 {
-	long ret = ~0;
 	unsigned long timeout;
+	long ret;
 
 	if (irq > -1) {
 		ret = wait_event_timeout(pca_wait,
@@ -81,11 +81,15 @@
 	} else {
 		/* Do polling */
 		timeout = jiffies + pca_isa_ops.timeout;
-		while (((pca_isa_readbyte(pd, I2C_PCA_CON)
-				& I2C_PCA_CON_SI) == 0)
-				&& (ret = time_before(jiffies, timeout)))
+		do {
+			ret = time_before(jiffies, timeout);
+			if (pca_isa_readbyte(pd, I2C_PCA_CON)
+				& I2C_PCA_CON_SI)
+				break;
 			udelay(100);
+		}while(ret);
 	}
+
 	return ret > 0;
 }
 
Reviewed-by
#8 lore raw
In reply to a message not in the archive

Hi Yegor,

looks good in general. Just a few whitespace issues. When you fixed them you can send a proper patch with the renamed patch description and my

Quoted 15 lines · Yegor Yefremov

Index: b/drivers/i2c/busses/i2c-pca-platform.c
===================================================================

drivers/i2c/busses/i2c-pca-platform.c +1 -1
@@ -80,8 +80,8 @@
 static int i2c_pca_pf_waitforcompletion(void *pd)
 {
 	struct i2c_pca_pf_data *i2c = pd;
-	long ret = ~0;
 	unsigned long timeout;
+	long ret;
 
 	if (i2c->irq) {
 		ret = wait_event_timeout(i2c->wait,

drivers/i2c/busses/i2c-pca-platform.c line 96

Quoted 10 lines
drivers/i2c/busses/i2c-pca-platform.c +4 -3
@@ -90,10 +90,13 @@
 	} else {
 		/* Do polling */
 		timeout = jiffies + i2c->adap.timeout;
-		while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
-				& I2C_PCA_CON_SI) == 0)
-				&& (ret = time_before(jiffies, timeout)))
+		do {
+			ret = time_before(jiffies, timeout);
+			if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
+					& I2C_PCA_CON_SI)

Add one or two tabs to the above line. I missed that, too. It looks strange if this line is on the same indentation level as the 'break' below.

Quoted 21 lines
drivers/i2c/busses/i2c-pca-platform.c +2 -0
+				break;
 			udelay(100);
+		} while (ret);
 	}
 
 	return ret > 0;

Index: b/drivers/i2c/busses/i2c-pca-isa.c
===================================================================

drivers/i2c/busses/i2c-pca-isa.c +1 -1
@@ -71,8 +71,8 @@
 
 static int pca_isa_waitforcompletion(void *pd)
 {
-	long ret = ~0;
 	unsigned long timeout;
+	long ret;
 
 	if (irq > -1) {
 		ret = wait_event_timeout(pca_wait,

drivers/i2c/busses/i2c-pca-isa.c line 87

Quoted 10 lines
drivers/i2c/busses/i2c-pca-isa.c +4 -3
@@ -81,11 +81,15 @@
 	} else {
 		/* Do polling */
 		timeout = jiffies + pca_isa_ops.timeout;
-		while (((pca_isa_readbyte(pd, I2C_PCA_CON)
-				& I2C_PCA_CON_SI) == 0)
-				&& (ret = time_before(jiffies, timeout)))
+		do {
+			ret = time_before(jiffies, timeout);
+			if (pca_isa_readbyte(pd, I2C_PCA_CON)
+				& I2C_PCA_CON_SI)

ditto.

drivers/i2c/busses/i2c-pca-isa.c line 90

Quoted 3 lines
drivers/i2c/busses/i2c-pca-isa.c +2 -0
+				break;
 			udelay(100);
+		}while(ret);

Missing space.

Quoted 6 lines
drivers/i2c/busses/i2c-pca-isa.c +1 -0
 	}
+
 	return ret > 0;
 }
 
Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |