serial: mxs-auart: Fix potential infinite loop
Subsystems (2)
PATCH 1/1 serial: mxs-auart: Fix potential infinite loop
On the error path of mxs_auart_request_gpio_irq() is performed backward iterating with index i of enum type. Underline enum type may be unsigned char. In this case check (--i >= 0) will be always true and error handling goes into infinite loop.
The patch changes type of index variable to int.
Found by Linux Driver Verification project (linuxtesting.org).
--- drivers/tty/serial/mxs-auart.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/serial/mxs-auart.c +3 -2
@@ -1617,7 +1617,7 @@ static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s)static int mxs_auart_request_gpio_irq (struct mxs_auart_port *s) {int *irq = s->gpio_irq; -enum mctrl_gpio_idx i; +int i;int err =0 ;for (i =0 ; (i <UART_GPIO_MAX ) && !err; i++) {
@@ -1634,8 +1634,9 @@ static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s)/* * If something went wrong, rollback. +* Be careful: i may be unsigned. */ -while (err && (--i >=0 )) +while (err && (i-- >0 ))if (irq[i] >=0 )free_irq (irq[i], s);
Signature · 1 line
2.18.0
PATCH v2 1/1 serial: mxs-auart: Fix potential infinite loop
On the error path of mxs_auart_request_gpio_irq() is performed backward iterating with index i of enum type. Underline enum type may be unsigned char. In this case check (--i >= 0) will be always true and error handling goes into infinite loop.
The patch changes the check so that it is valid for signed and unsigned types.
Found by Linux Driver Verification project (linuxtesting.org).
---
v2: mistype in patch as result of combination of different fixes. Change comment and leave enum type.
--- drivers/tty/serial/mxs-auart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/mxs-auart.c +2 -1
@@ -1634,8 +1634,9 @@ static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s)/* * If something went wrong, rollback. +* Be careful: i may be unsigned. */ -while (err && (--i >=0 )) +while (err && (i-- >0 ))if (irq[i] >=0 )free_irq (irq[i], s);
Signature · 1 line
2.18.0
Quoted 23 lines · Anton Vasilyev
On the error path of
mxs_auart_request_gpio_irq()is performed backward iterating with index i of enum type. Underline enum type may be unsigned char. In this case check (--i >= 0) will be always true and error handling goes into infinite loop.The patch changes the check so that it is valid for signed and unsigned types.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Anton Vasilyev <[email protected]>---
v2: mistype in patch as result of combination of different fixes. Change comment and leave enum type.--- drivers/tty/serial/mxs-auart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tty/serial/mxs-auart.c +0
-0
drivers/tty/serial/mxs-auart.c static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) · line 1641
Quoted 9 lines
drivers/tty/serial/mxs-auart.c +2
-1@@ -1634,8 +1634,9 @@ static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s)/* * If something went wrong, rollback. +* Be careful: i may be unsigned. */ -while (err && (--i >=0 )) +while (err && (i-- >0 ))if (irq[i] >=0 )free_irq (irq[i], s);
I wouldn't have added the comment, but the code change is correct.
Thanks
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |