Skip to contentSkip to conversation

tty: atmel_serial_probe(): index of atmel_ports[] fix

PATCH In review Pawel Wieczorkiewicz 3 participants 3 messages Feb 20, 2013 – Mar 15, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: atmel_serial_probe(): index of atmel_ports[] fix

From: Pawel Wieczorkiewicz <[email protected]>

Index of atmel_ports[ATMEL_MAX_UART] should be smaller than ATMEL_MAX_UART.

---
 drivers/tty/serial/atmel_serial.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/tty/serial/atmel_serial.c +5 -6
index d4a7c24..3467462 100644
@@ -158,7 +158,7 @@ struct atmel_uart_port {
 };
 
 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
-static unsigned long atmel_ports_in_use;
+static DECLARE_BITMAP(atmel_ports_in_use, ATMEL_MAX_UART);
 
 #ifdef SUPPORT_SYSRQ
 static struct console atmel_console;
@@ -1769,15 +1769,14 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	if (ret < 0)
 		/* port id not found in platform data nor device-tree aliases:
 		 * auto-enumerate it */
-		ret = find_first_zero_bit(&atmel_ports_in_use,
-				sizeof(atmel_ports_in_use));
+		ret = find_first_zero_bit(atmel_ports_in_use, ATMEL_MAX_UART);
 
-	if (ret > ATMEL_MAX_UART) {
+	if (ret >= ATMEL_MAX_UART) {
 		ret = -ENODEV;
 		goto err;
 	}
 
-	if (test_and_set_bit(ret, &atmel_ports_in_use)) {
+	if (test_and_set_bit(ret, atmel_ports_in_use)) {
 		/* port already in use */
 		ret = -EBUSY;
 		goto err;
@@ -1857,7 +1856,7 @@ static int atmel_serial_remove(struct platform_device *pdev)
 
 	/* "port" is allocated statically, so we shouldn't free it */
 
-	clear_bit(port->line, &atmel_ports_in_use);
+	clear_bit(port->line, atmel_ports_in_use);
 
 	clk_put(atmel_port->clk);
 
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw

On 02/20/2013 05:26 PM, Pawel Wieczorkiewicz :

Quoted 6 lines

From: Pawel Wieczorkiewicz <[email protected]>

Index of atmel_ports[ATMEL_MAX_UART] should be smaller than ATMEL_MAX_UART.

It can be good to include this one in 3.9-rc.

I also would like to add the "stable" tag to it:

Cc stable <[email protected]> # 3.2+

Greg, can you take this one or do I need to re-send it with appropriate "stable" line?

Thanks, best regards,

Quoted 46 lines
---
 drivers/tty/serial/atmel_serial.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/tty/serial/atmel_serial.c +5 -6
index d4a7c24..3467462 100644
@@ -158,7 +158,7 @@ struct atmel_uart_port {
 };
 
 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
-static unsigned long atmel_ports_in_use;
+static DECLARE_BITMAP(atmel_ports_in_use, ATMEL_MAX_UART);
 
 #ifdef SUPPORT_SYSRQ
 static struct console atmel_console;
@@ -1769,15 +1769,14 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	if (ret < 0)
 		/* port id not found in platform data nor device-tree aliases:
 		 * auto-enumerate it */
-		ret = find_first_zero_bit(&atmel_ports_in_use,
-				sizeof(atmel_ports_in_use));
+		ret = find_first_zero_bit(atmel_ports_in_use, ATMEL_MAX_UART);
 
-	if (ret > ATMEL_MAX_UART) {
+	if (ret >= ATMEL_MAX_UART) {
 		ret = -ENODEV;
 		goto err;
 	}
 
-	if (test_and_set_bit(ret, &atmel_ports_in_use)) {
+	if (test_and_set_bit(ret, atmel_ports_in_use)) {
 		/* port already in use */
 		ret = -EBUSY;
 		goto err;
@@ -1857,7 +1856,7 @@ static int atmel_serial_remove(struct platform_device *pdev)
 
 	/* "port" is allocated statically, so we shouldn't free it */
 
-	clear_bit(port->line, &atmel_ports_in_use);
+	clear_bit(port->line, atmel_ports_in_use);
 
 	clk_put(atmel_port->clk);
 
Signature · 1 line
Nicolas Ferre
maintainer
#2 lore raw
Quoted 10 lines · Nicolas Ferre

On 02/20/2013 05:26 PM, Pawel Wieczorkiewicz :

Quoted 6 lines

From: Pawel Wieczorkiewicz <[email protected]>

Index of atmel_ports[ATMEL_MAX_UART] should be smaller than ATMEL_MAX_UART.

Quoted 8 lines

It can be good to include this one in 3.9-rc.

I also would like to add the "stable" tag to it:

Cc stable <[email protected]> # 3.2+

Greg, can you take this one or do I need to re-send it with appropriate "stable" line?

I can add it, thanks.

greg k-h