Skip to content

Commit 4ccc28f

Browse files
RoelKluinJean Delvare
authored andcommitted
i2c: Timeouts off by 1
with while (timeout++ < MAX_TIMEOUT); timeout reaches MAX_TIMEOUT + 1 after the loop, so the tests below are off by one. Signed-off-by: Roel Kluin <roel.kluin@gmail.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
1 parent b4348f3 commit 4ccc28f

9 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎drivers/i2c/busses/i2c-ali1535.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
284284
&& (timeout++ < MAX_TIMEOUT));
285285

286286
/* If the SMBus is still busy, we give up */
287-
if (timeout >= MAX_TIMEOUT) {
287+
if (timeout > MAX_TIMEOUT) {
288288
result = -ETIMEDOUT;
289289
dev_err(&adap->dev, "SMBus Timeout!\n");
290290
}

‎drivers/i2c/busses/i2c-ali15x3.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
306306
&& (timeout++ < MAX_TIMEOUT));
307307

308308
/* If the SMBus is still busy, we give up */
309-
if (timeout >= MAX_TIMEOUT) {
309+
if (timeout > MAX_TIMEOUT) {
310310
result = -ETIMEDOUT;
311311
dev_err(&adap->dev, "SMBus Timeout!\n");
312312
}

‎drivers/i2c/busses/i2c-amd756.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int amd756_transaction(struct i2c_adapter *adap)
126126
} while ((temp & (GS_HST_STS | GS_SMB_STS)) &&
127127
(timeout++ < MAX_TIMEOUT));
128128
/* If the SMBus is still busy, we give up */
129-
if (timeout >= MAX_TIMEOUT) {
129+
if (timeout > MAX_TIMEOUT) {
130130
dev_dbg(&adap->dev, "Busy wait timeout (%04x)\n", temp);
131131
goto abort;
132132
}
@@ -143,7 +143,7 @@ static int amd756_transaction(struct i2c_adapter *adap)
143143
} while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT));
144144

145145
/* If the SMBus is still busy, we give up */
146-
if (timeout >= MAX_TIMEOUT) {
146+
if (timeout > MAX_TIMEOUT) {
147147
dev_dbg(&adap->dev, "Completion timeout!\n");
148148
goto abort;
149149
}

‎drivers/i2c/busses/i2c-i801.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static int i801_transaction(int xact)
237237
status = inb_p(SMBHSTSTS);
238238
} while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
239239

240-
result = i801_check_post(status, timeout >= MAX_TIMEOUT);
240+
result = i801_check_post(status, timeout > MAX_TIMEOUT);
241241
if (result < 0)
242242
return result;
243243

@@ -257,9 +257,9 @@ static void i801_wait_hwpec(void)
257257
} while ((!(status & SMBHSTSTS_INTR))
258258
&& (timeout++ < MAX_TIMEOUT));
259259

260-
if (timeout >= MAX_TIMEOUT) {
260+
if (timeout > MAX_TIMEOUT)
261261
dev_dbg(&I801_dev->dev, "PEC Timeout!\n");
262-
}
262+
263263
outb_p(status, SMBHSTSTS);
264264
}
265265

@@ -344,7 +344,7 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
344344
while ((!(status & SMBHSTSTS_BYTE_DONE))
345345
&& (timeout++ < MAX_TIMEOUT));
346346

347-
result = i801_check_post(status, timeout >= MAX_TIMEOUT);
347+
result = i801_check_post(status, timeout > MAX_TIMEOUT);
348348
if (result < 0)
349349
return result;
350350

‎drivers/i2c/busses/i2c-isch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int sch_transaction(void)
112112
} while ((temp & 0x08) && (timeout++ < MAX_TIMEOUT));
113113

114114
/* If the SMBus is still busy, we give up */
115-
if (timeout >= MAX_TIMEOUT) {
115+
if (timeout > MAX_TIMEOUT) {
116116
dev_err(&sch_adapter.dev, "SMBus Timeout!\n");
117117
result = -ETIMEDOUT;
118118
}

‎drivers/i2c/busses/i2c-nforce2.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int nforce2_check_status(struct i2c_adapter *adap)
173173
temp = inb_p(NVIDIA_SMB_STS);
174174
} while ((!temp) && (timeout++ < MAX_TIMEOUT));
175175

176-
if (timeout >= MAX_TIMEOUT) {
176+
if (timeout > MAX_TIMEOUT) {
177177
dev_dbg(&adap->dev, "SMBus Timeout!\n");
178178
if (smbus->can_abort)
179179
nforce2_abort(adap);

‎drivers/i2c/busses/i2c-sis5595.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
256256
} while (!(temp & 0x40) && (timeout++ < MAX_TIMEOUT));
257257

258258
/* If the SMBus is still busy, we give up */
259-
if (timeout >= MAX_TIMEOUT) {
259+
if (timeout > MAX_TIMEOUT) {
260260
dev_dbg(&adap->dev, "SMBus Timeout!\n");
261261
result = -ETIMEDOUT;
262262
}

‎drivers/i2c/busses/i2c-sis630.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int sis630_transaction_wait(struct i2c_adapter *adap, int size)
173173
} while (!(temp & 0x0e) && (timeout++ < MAX_TIMEOUT));
174174

175175
/* If the SMBus is still busy, we give up */
176-
if (timeout >= MAX_TIMEOUT) {
176+
if (timeout > MAX_TIMEOUT) {
177177
dev_dbg(&adap->dev, "SMBus Timeout!\n");
178178
result = -ETIMEDOUT;
179179
}

‎drivers/i2c/busses/i2c-sis96x.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int sis96x_transaction(int size)
132132
} while (!(temp & 0x0e) && (timeout++ < MAX_TIMEOUT));
133133

134134
/* If the SMBus is still busy, we give up */
135-
if (timeout >= MAX_TIMEOUT) {
135+
if (timeout > MAX_TIMEOUT) {
136136
dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp);
137137
result = -ETIMEDOUT;
138138
}

0 commit comments

Comments
 (0)