Patchwork [U-Boot,3/3] usb: common: Use a global definition for 'min3'

login
register
mail settings
Submitter Vivek Gautam
Date April 24, 2013, 12:50 p.m.
Message ID <1366807813-10481-4-git-send-email-gautam.vivek@samsung.com>
Download mbox | patch
Permalink /patch/239200/
State Accepted
Delegated to: Marek Vasut
Headers show

Comments

Vivek Gautam - April 24, 2013, 12:50 p.m.
We can use a common global method for calculating minimum of
3 numbers. Put the same in 'common header' and let 'ehci'
use it.

Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
---
 drivers/usb/host/ehci-hcd.c |   10 ----------
 include/common.h            |   25 +++++++++++++++++++++----
 2 files changed, 21 insertions(+), 14 deletions(-)
Vivek Gautam - April 24, 2013, 1:51 p.m.
CC: Tom Rini


On Wed, Apr 24, 2013 at 6:20 PM, Vivek Gautam <gautam.vivek@samsung.com> wrote:
> We can use a common global method for calculating minimum of
> 3 numbers. Put the same in 'common header' and let 'ehci'
> use it.
>
> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
> ---
>  drivers/usb/host/ehci-hcd.c |   10 ----------
>  include/common.h            |   25 +++++++++++++++++++++----
>  2 files changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> index 19d4352..e0f3e4b 100644
> --- a/drivers/usb/host/ehci-hcd.c
> +++ b/drivers/usb/host/ehci-hcd.c
> @@ -603,16 +603,6 @@ fail:
>         return -1;
>  }
>
> -static inline int min3(int a, int b, int c)
> -{
> -
> -       if (b < a)
> -               a = b;
> -       if (c < a)
> -               a = c;
> -       return a;
> -}
> -
>  int
>  ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
>                  int length, struct devrequest *req)
> diff --git a/include/common.h b/include/common.h
> index 0cfa6a8..b0258a0 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -199,18 +199,35 @@ typedef void (interrupt_handler_t)(void *);
>   * General Purpose Utilities
>   */
>  #define min(X, Y)                              \
> -       ({ typeof (X) __x = (X);                \
> -               typeof (Y) __y = (Y);           \
> +       ({ typeof(X) __x = (X);                 \
> +               typeof(Y) __y = (Y);            \
>                 (__x < __y) ? __x : __y; })
>
>  #define max(X, Y)                              \
> -       ({ typeof (X) __x = (X);                \
> -               typeof (Y) __y = (Y);           \
> +       ({ typeof(X) __x = (X);                 \
> +               typeof(Y) __y = (Y);            \
>                 (__x > __y) ? __x : __y; })
>
>  #define MIN(x, y)  min(x, y)
>  #define MAX(x, y)  max(x, y)
>
> +#define min3(X, Y, Z)                          \
> +       ({ typeof(X) __x = (X);                 \
> +               typeof(Y) __y = (Y);            \
> +               typeof(Z) __z = (Z);            \
> +               __x < __y ? (__x < __z ? __x : __z) :   \
> +               (__y < __z ? __y : __z); })
> +
> +#define max3(X, Y, Z)                          \
> +       ({ typeof(X) __x = (X);                 \
> +               typeof(Y) __y = (Y);            \
> +               typeof(Z) __z = (Z);            \
> +               __x > __y ? (__x > __z ? __x : __z) :   \
> +               (__y > __z ? __y : __z); })
> +
> +#define MIN3(x, y, z)  min3(x, y, z)
> +#define MAX3(x, y, z)  max3(x, y, z)
> +
>  /*
>   * Return the absolute value of a number.
>   *
> --
> 1.7.6.5
Tom Rini - April 25, 2013, 12:21 p.m.
On Wed, Apr 24, 2013 at 06:20:13PM +0530, Vivek Gautam wrote:

> We can use a common global method for calculating minimum of
> 3 numbers. Put the same in 'common header' and let 'ehci'
> use it.
> 
> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>

Acked-by: Tom Rini <trini@ti.com>

Patch

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 19d4352..e0f3e4b 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -603,16 +603,6 @@  fail:
 	return -1;
 }
 
-static inline int min3(int a, int b, int c)
-{
-
-	if (b < a)
-		a = b;
-	if (c < a)
-		a = c;
-	return a;
-}
-
 int
 ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
 		 int length, struct devrequest *req)
diff --git a/include/common.h b/include/common.h
index 0cfa6a8..b0258a0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -199,18 +199,35 @@  typedef void (interrupt_handler_t)(void *);
  * General Purpose Utilities
  */
 #define min(X, Y)				\
-	({ typeof (X) __x = (X);		\
-		typeof (Y) __y = (Y);		\
+	({ typeof(X) __x = (X);			\
+		typeof(Y) __y = (Y);		\
 		(__x < __y) ? __x : __y; })
 
 #define max(X, Y)				\
-	({ typeof (X) __x = (X);		\
-		typeof (Y) __y = (Y);		\
+	({ typeof(X) __x = (X);			\
+		typeof(Y) __y = (Y);		\
 		(__x > __y) ? __x : __y; })
 
 #define MIN(x, y)  min(x, y)
 #define MAX(x, y)  max(x, y)
 
+#define min3(X, Y, Z)				\
+	({ typeof(X) __x = (X);			\
+		typeof(Y) __y = (Y);		\
+		typeof(Z) __z = (Z);		\
+		__x < __y ? (__x < __z ? __x : __z) :	\
+		(__y < __z ? __y : __z); })
+
+#define max3(X, Y, Z)				\
+	({ typeof(X) __x = (X);			\
+		typeof(Y) __y = (Y);		\
+		typeof(Z) __z = (Z);		\
+		__x > __y ? (__x > __z ? __x : __z) :	\
+		(__y > __z ? __y : __z); })
+
+#define MIN3(x, y, z)  min3(x, y, z)
+#define MAX3(x, y, z)  max3(x, y, z)
+
 /*
  * Return the absolute value of a number.
  *