linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix
@ 2013-02-12 23:17 Pawel Wieczorkiewicz
  2013-02-20 15:00 ` Jiri Slaby
  0 siblings, 1 reply; 5+ messages in thread
From: Pawel Wieczorkiewicz @ 2013-02-12 23:17 UTC (permalink / raw)
  To: nicolas.ferre, gregkh, grant.likely, jslaby
  Cc: linux-serial, linux-kernel, Pawel Wieczorkiewicz

From: Pawel Wieczorkiewicz <wpawel@gmail.com>

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

Signed-off-by: Pawel Wieczorkiewicz <wpawel@gmail.com>
---
 drivers/tty/serial/atmel_serial.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d4a7c24..3f7586a 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1772,7 +1772,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
 		ret = find_first_zero_bit(&atmel_ports_in_use,
 				sizeof(atmel_ports_in_use));
 
-	if (ret > ATMEL_MAX_UART) {
+	if (!(ret < ATMEL_MAX_UART)) {
 		ret = -ENODEV;
 		goto err;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix
  2013-02-12 23:17 Pawel Wieczorkiewicz
@ 2013-02-20 15:00 ` Jiri Slaby
  0 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2013-02-20 15:00 UTC (permalink / raw)
  To: Pawel Wieczorkiewicz, nicolas.ferre, gregkh, grant.likely
  Cc: linux-serial, linux-kernel

On 02/13/2013 12:17 AM, Pawel Wieczorkiewicz wrote:
> From: Pawel Wieczorkiewicz <wpawel@gmail.com>
> 
> Index of atmel_ports[ATMEL_MAX_UART] should be smaller
> than ATMEL_MAX_UART.
> 
> Signed-off-by: Pawel Wieczorkiewicz <wpawel@gmail.com>
> ---
>  drivers/tty/serial/atmel_serial.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index d4a7c24..3f7586a 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -1772,7 +1772,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
>  		ret = find_first_zero_bit(&atmel_ports_in_use,
>  				sizeof(atmel_ports_in_use));
>  
> -	if (ret > ATMEL_MAX_UART) {
> +	if (!(ret < ATMEL_MAX_UART)) {

Good catch, but the result looks weird. Could you just make it ">="?

And find_first_zero_bit + sizeof above is bogus too. The sizeof returns
4 on 32-bit (the driver is run on 32bit machines exlusively AFAICS). So
the highest possible ret in there is 5. Instead atmel_ports_in_use
should be declared using DECLARE_BITMAP(atmel_ports_in_use,
ATMEL_MAX_UART) and the second parameter here then ATMEL_MAX_UART.

Could you fix that too?

-- 
js
suse labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix
@ 2013-02-20 16:26 Pawel Wieczorkiewicz
  2013-03-15 14:36 ` Nicolas Ferre
  0 siblings, 1 reply; 5+ messages in thread
From: Pawel Wieczorkiewicz @ 2013-02-20 16:26 UTC (permalink / raw)
  To: nicolas.ferre, gregkh, grant.likely, jslaby
  Cc: linux-serial, linux-kernel, Pawel Wieczorkiewicz

From: Pawel Wieczorkiewicz <wpawel@gmail.com>

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

Signed-off-by: Pawel Wieczorkiewicz <wpawel@gmail.com>
---
 drivers/tty/serial/atmel_serial.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d4a7c24..3467462 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -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);
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix
  2013-02-20 16:26 [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix Pawel Wieczorkiewicz
@ 2013-03-15 14:36 ` Nicolas Ferre
  2013-03-15 14:58   ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Ferre @ 2013-03-15 14:36 UTC (permalink / raw)
  To: Pawel Wieczorkiewicz, gregkh, jslaby
  Cc: grant.likely, linux-serial, linux-kernel

On 02/20/2013 05:26 PM, Pawel Wieczorkiewicz :
> From: Pawel Wieczorkiewicz <wpawel@gmail.com>
> 
> Index of atmel_ports[ATMEL_MAX_UART] should be smaller
> than ATMEL_MAX_UART.
> 
> Signed-off-by: Pawel Wieczorkiewicz <wpawel@gmail.com>

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

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 <stable@vger.kernel.org> # 3.2+

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

Thanks, best regards,

> ---
>  drivers/tty/serial/atmel_serial.c |   11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index d4a7c24..3467462 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -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);
>  
> 


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix
  2013-03-15 14:36 ` Nicolas Ferre
@ 2013-03-15 14:58   ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2013-03-15 14:58 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Pawel Wieczorkiewicz, jslaby, grant.likely, linux-serial,
	linux-kernel

On Fri, Mar 15, 2013 at 03:36:38PM +0100, Nicolas Ferre wrote:
> On 02/20/2013 05:26 PM, Pawel Wieczorkiewicz :
> > From: Pawel Wieczorkiewicz <wpawel@gmail.com>
> > 
> > Index of atmel_ports[ATMEL_MAX_UART] should be smaller
> > than ATMEL_MAX_UART.
> > 
> > Signed-off-by: Pawel Wieczorkiewicz <wpawel@gmail.com>
> 
> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> 
> 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 <stable@vger.kernel.org> # 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-15 14:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-20 16:26 [PATCH 1/1] tty: atmel_serial_probe(): index of atmel_ports[] fix Pawel Wieczorkiewicz
2013-03-15 14:36 ` Nicolas Ferre
2013-03-15 14:58   ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2013-02-12 23:17 Pawel Wieczorkiewicz
2013-02-20 15:00 ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).