Skip to content

Commit 5374ce8

Browse files
authored
Merge pull request #22 from DHowett/dh/bug/21/hx20
mchp: Remove undefined behavior in espi msvw handlers
2 parents 7d4dcbd + 23d6a81 commit 5374ce8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

chip/mchp/espi.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,13 +1238,12 @@ void espi_mswv1_interrupt(void)
12381238
girq24_result = MCHP_INT_RESULT(24);
12391239
MCHP_INT_SOURCE(24) = girq24_result;
12401240

1241-
bpos = __builtin_ctz(girq24_result); /* rbit, clz sequence */
1242-
while (bpos != 32) {
1241+
while (girq24_result) {
1242+
bpos = __builtin_ctz(girq24_result); /* rbit, clz sequence */
12431243
d = *(uint8_t *)(MCHP_ESPI_MSVW_BASE + 8 +
12441244
(12 * (bpos >> 2)) + (bpos & 0x03)) & 0x01;
12451245
(girq24_vw_handlers[bpos])(d, bpos);
12461246
girq24_result &= ~(1ul << bpos);
1247-
bpos = __builtin_ctz(girq24_result);
12481247
}
12491248
}
12501249
DECLARE_IRQ(MCHP_IRQ_GIRQ24, espi_mswv1_interrupt, 2);
@@ -1259,13 +1258,12 @@ void espi_msvw2_interrupt(void)
12591258
girq25_result = MCHP_INT_RESULT(25);
12601259
MCHP_INT_SOURCE(25) = girq25_result;
12611260

1262-
bpos = __builtin_ctz(girq25_result); /* rbit, clz sequence */
1263-
while (bpos != 32) {
1261+
while (girq25_result) {
1262+
bpos = __builtin_ctz(girq25_result); /* rbit, clz sequence */
12641263
d = *(uint8_t *)(MCHP_ESPI_MSVW_BASE + (12 * 7) + 8 +
12651264
(12 * (bpos >> 2)) + (bpos & 0x03)) & 0x01;
12661265
(girq25_vw_handlers[bpos])(d, bpos);
12671266
girq25_result &= ~(1ul << bpos);
1268-
bpos = __builtin_ctz(girq25_result);
12691267
}
12701268
}
12711269
DECLARE_IRQ(MCHP_IRQ_GIRQ25, espi_msvw2_interrupt, 2);

0 commit comments

Comments
 (0)