LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] char: fix sparse shadowed variable warnings in cyclades.c
@ 2008-02-22 18:14 Harvey Harrison
  2008-02-27 23:34 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Harvey Harrison @ 2008-02-22 18:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML

Nested min() macros.
drivers/char/cyclades.c:2750:7: warning: symbol '_x' shadows an earlier one
drivers/char/cyclades.c:2750:7: originally declared here
drivers/char/cyclades.c:2750:7: warning: symbol '_x' shadows an earlier one
drivers/char/cyclades.c:2750:7: originally declared here
drivers/char/cyclades.c:2750:7: warning: symbol '_y' shadows an earlier one
drivers/char/cyclades.c:2750:7: originally declared here

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 drivers/char/cyclades.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index e4f579c..f8f4d54 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -2747,8 +2747,8 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
 
 	spin_lock_irqsave(&info->card->card_lock, flags);
 	while (1) {
-		c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
-				   (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
+		c = min(count, (int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1));
+		c = min(c, (int)(SERIAL_XMIT_SIZE - info->xmit_head));
 
 		if (c <= 0)
 			break;
-- 
1.5.4.2.200.g99e75




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

* Re: [PATCH] char: fix sparse shadowed variable warnings in cyclades.c
  2008-02-22 18:14 [PATCH] char: fix sparse shadowed variable warnings in cyclades.c Harvey Harrison
@ 2008-02-27 23:34 ` Andrew Morton
  2008-02-27 23:40   ` Harvey Harrison
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-02-27 23:34 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: linux-kernel

On Fri, 22 Feb 2008 10:14:15 -0800
Harvey Harrison <harvey.harrison@gmail.com> wrote:

> Nested min() macros.
> drivers/char/cyclades.c:2750:7: warning: symbol '_x' shadows an earlier one
> drivers/char/cyclades.c:2750:7: originally declared here
> drivers/char/cyclades.c:2750:7: warning: symbol '_x' shadows an earlier one
> drivers/char/cyclades.c:2750:7: originally declared here
> drivers/char/cyclades.c:2750:7: warning: symbol '_y' shadows an earlier one
> drivers/char/cyclades.c:2750:7: originally declared here
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
>  drivers/char/cyclades.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
> index e4f579c..f8f4d54 100644
> --- a/drivers/char/cyclades.c
> +++ b/drivers/char/cyclades.c
> @@ -2747,8 +2747,8 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
>  
>  	spin_lock_irqsave(&info->card->card_lock, flags);
>  	while (1) {
> -		c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
> -				   (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
> +		c = min(count, (int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1));
> +		c = min(c, (int)(SERIAL_XMIT_SIZE - info->xmit_head));
>  
>  		if (c <= 0)
>  			break;

Unrelated to your change, but...

We prefer min_t over casts like this (not sure why, but let's be consistent)

The reason for this cast is that all this code is using `int' for the
transfer count (arguably wrong - should use size_t, but that propagates all
the way to tty_operations.write) but cyclades has

#define SERIAL_XMIT_SIZE        (min(PAGE_SIZE, 4096))

which is unsigned on most architectures.

A possibly-sane fix for all of this is to use min_t in the above then nuke
the casts.


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

* Re: [PATCH] char: fix sparse shadowed variable warnings in cyclades.c
  2008-02-27 23:34 ` Andrew Morton
@ 2008-02-27 23:40   ` Harvey Harrison
  0 siblings, 0 replies; 3+ messages in thread
From: Harvey Harrison @ 2008-02-27 23:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On Wed, 2008-02-27 at 15:34 -0800, Andrew Morton wrote:
> On Fri, 22 Feb 2008 10:14:15 -0800
> Harvey Harrison <harvey.harrison@gmail.com> wrote:
> 
> Unrelated to your change, but...
> 
> We prefer min_t over casts like this (not sure why, but let's be consistent)
> 
> The reason for this cast is that all this code is using `int' for the
> transfer count (arguably wrong - should use size_t, but that propagates all
> the way to tty_operations.write) but cyclades has
> 
> #define SERIAL_XMIT_SIZE        (min(PAGE_SIZE, 4096))
> 
> which is unsigned on most architectures.
> 
> A possibly-sane fix for all of this is to use min_t in the above then nuke
> the casts.
> 

I'll trace this through and get you a patch.

Harvey




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

end of thread, other threads:[~2008-02-27 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-22 18:14 [PATCH] char: fix sparse shadowed variable warnings in cyclades.c Harvey Harrison
2008-02-27 23:34 ` Andrew Morton
2008-02-27 23:40   ` Harvey Harrison

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).