Patchwork [U-Boot,1/1] Fix min/max macros in include/common.h

login
register
mail settings
Submitter Aaron Williams
Date Feb. 1, 2011, 3:55 a.m.
Message ID <201101311955.50902.Aaron.Williams@caviumnetworks.com>
Download mbox | patch
Permalink /patch/81265/
State Accepted
Headers show

Comments

Aaron Williams - Feb. 1, 2011, 3:55 a.m.
There is a bug in the min and max macros in common.h which occurs if
Y is a larger type than X. For example, if Y is a 64-bit value and X
is a 32-bit value then Y will be truncated to 32-bits.  This fix
matches what is done in the Linux kernel but without the additional
type checking present in the kernel version.

Signed-off-by: Aaron Williams <aaron.williams@caviumnetworks.com>

 include/common.h |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
Wolfgang Denk - Feb. 1, 2011, 7:51 a.m.
Dear Aaron Williams,

In message <201101311955.50902.Aaron.Williams@caviumnetworks.com> you wrote:
> There is a bug in the min and max macros in common.h which occurs if
> Y is a larger type than X. For example, if Y is a 64-bit value and X
> is a 32-bit value then Y will be truncated to 32-bits.  This fix
> matches what is done in the Linux kernel but without the additional
> type checking present in the kernel version.

Please stick to the rules.  When resubmitting a patch you are supposed
to mark it as a reposting, and to keep the message references in place
so mails get threaded properly.  Please make sure and read
http://www.denx.de/wiki/view/U-Boot/Patches#Sending_updated_patch_versions


Best regards,

Wolfgang Denk
Wolfgang Denk - April 12, 2011, 6:56 p.m.
Dear Aaron Williams,

In message <201101311955.50902.Aaron.Williams@caviumnetworks.com> you wrote:
> There is a bug in the min and max macros in common.h which occurs if
> Y is a larger type than X. For example, if Y is a 64-bit value and X
> is a 32-bit value then Y will be truncated to 32-bits.  This fix
> matches what is done in the Linux kernel but without the additional
> type checking present in the kernel version.
> 
> Signed-off-by: Aaron Williams <aaron.williams@caviumnetworks.com>
> 
>  include/common.h |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)

Applied, after manually fixing the bad patch format ("---" separator
line missing).  I recommend to use "git format-patch" and "git
send-email"!

Thanks.

Wolfgang Denk

Patch

diff --git a/include/common.h b/include/common.h
index d8c912d..cf5c076 100644
--- a/include/common.h
+++ b/include/common.h
@@ -180,11 +180,13 @@  typedef void (interrupt_handler_t)(void *);
  * General Purpose Utilities
  */
 #define min(X, Y)				\
-	({ typeof (X) __x = (X), __y = (Y);	\
+	({ typeof (X) __x = (X);		\
+		typeof (Y) __y = (Y);		\
 		(__x < __y) ? __x : __y; })

 #define max(X, Y)				\
-	({ typeof (X) __x = (X), __y = (Y);	\
+	({ typeof (X) __x = (X);		\
+		typeof (Y) __y = (Y);		\
 		(__x > __y) ? __x : __y; })

 #define MIN(x, y)  min(x, y)