]> Pileus Git - ~andy/linux/commitdiff
usb/core: use bin2bcd() for bcdDevice in RH
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 7 Sep 2012 12:31:45 +0000 (14:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Sep 2012 18:13:16 +0000 (11:13 -0700)
The kernel's version number is used as decimal in the bcdDevice field of
the RH descriptor. For kernel version v3.12 we would see 3.0c in lsusb.
I am not sure how important it is to stick with bcd values since this is
this way since we started git history and nobody complained (however back
then we reported only 2.6).

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hcd.c
include/linux/bcd.h
lib/bcd.c

index bc84106ac057d7affb0e4d7c5c6ce22dcc2b7943..6e4fd28bc2423e85ef2d2ec56429cdc76f07681b 100644 (file)
@@ -22,6 +22,7 @@
  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <linux/bcd.h>
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/kernel.h>
@@ -123,9 +124,8 @@ static inline int is_root_hub(struct usb_device *udev)
  */
 
 /*-------------------------------------------------------------------------*/
-
-#define KERNEL_REL     ((LINUX_VERSION_CODE >> 16) & 0x0ff)
-#define KERNEL_VER     ((LINUX_VERSION_CODE >> 8) & 0x0ff)
+#define KERNEL_REL     bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
+#define KERNEL_VER     bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
 
 /* usb 3.0 root hub device descriptor */
 static const u8 usb3_rh_dev_descriptor[18] = {
index 22ea563ba3eb169f9e04aac1233b404923c42d6e..18fff11fb3eadbe6ebd715a584aa49909d1dd30f 100644 (file)
@@ -3,7 +3,20 @@
 
 #include <linux/compiler.h>
 
-unsigned bcd2bin(unsigned char val) __attribute_const__;
-unsigned char bin2bcd(unsigned val) __attribute_const__;
+#define bcd2bin(x)                                     \
+               (__builtin_constant_p((u8 )(x)) ?       \
+               const_bcd2bin(x) :                      \
+               _bcd2bin(x))
+
+#define bin2bcd(x)                                     \
+               (__builtin_constant_p((u8 )(x)) ?       \
+               const_bin2bcd(x) :                      \
+               _bin2bcd(x))
+
+#define const_bcd2bin(x)       (((x) & 0x0f) + ((x) >> 4) * 10)
+#define const_bin2bcd(x)       ((((x) / 10) << 4) + (x) % 10)
+
+unsigned _bcd2bin(unsigned char val) __attribute_const__;
+unsigned char _bin2bcd(unsigned val) __attribute_const__;
 
 #endif /* _BCD_H */
index 55efaf7423462d9d116aad5e3383e83e0952967e..40d304efe27281151124a874cdbac864f997a7ee 100644 (file)
--- a/lib/bcd.c
+++ b/lib/bcd.c
@@ -1,14 +1,14 @@
 #include <linux/bcd.h>
 #include <linux/export.h>
 
-unsigned bcd2bin(unsigned char val)
+unsigned _bcd2bin(unsigned char val)
 {
        return (val & 0x0f) + (val >> 4) * 10;
 }
-EXPORT_SYMBOL(bcd2bin);
+EXPORT_SYMBOL(_bcd2bin);
 
-unsigned char bin2bcd(unsigned val)
+unsigned char _bin2bcd(unsigned val)
 {
        return ((val / 10) << 4) + val % 10;
 }
-EXPORT_SYMBOL(bin2bcd);
+EXPORT_SYMBOL(_bin2bcd);