Skip to content

Commit b53d657

Browse files
Sebastian Andrzej Siewiorgregkh
authored andcommitted
usb/core: use bin2bcd() for bcdDevice in RH
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>
1 parent 8a424bf commit b53d657

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎drivers/usb/core/hcd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2323
*/
2424

25+
#include <linux/bcd.h>
2526
#include <linux/module.h>
2627
#include <linux/version.h>
2728
#include <linux/kernel.h>
@@ -123,9 +124,8 @@ static inline int is_root_hub(struct usb_device *udev)
123124
*/
124125

125126
/*-------------------------------------------------------------------------*/
126-
127-
#define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff)
128-
#define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff)
127+
#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
128+
#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
129129

130130
/* usb 3.0 root hub device descriptor */
131131
static const u8 usb3_rh_dev_descriptor[18] = {

‎include/linux/bcd.h‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33

44
#include <linux/compiler.h>
55

6-
unsigned bcd2bin(unsigned char val) __attribute_const__;
7-
unsigned char bin2bcd(unsigned val) __attribute_const__;
6+
#define bcd2bin(x) \
7+
(__builtin_constant_p((u8 )(x)) ? \
8+
const_bcd2bin(x) : \
9+
_bcd2bin(x))
10+
11+
#define bin2bcd(x) \
12+
(__builtin_constant_p((u8 )(x)) ? \
13+
const_bin2bcd(x) : \
14+
_bin2bcd(x))
15+
16+
#define const_bcd2bin(x) (((x) & 0x0f) + ((x) >> 4) * 10)
17+
#define const_bin2bcd(x) ((((x) / 10) << 4) + (x) % 10)
18+
19+
unsigned _bcd2bin(unsigned char val) __attribute_const__;
20+
unsigned char _bin2bcd(unsigned val) __attribute_const__;
821

922
#endif /* _BCD_H */

‎lib/bcd.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <linux/bcd.h>
22
#include <linux/export.h>
33

4-
unsigned bcd2bin(unsigned char val)
4+
unsigned _bcd2bin(unsigned char val)
55
{
66
return (val & 0x0f) + (val >> 4) * 10;
77
}
8-
EXPORT_SYMBOL(bcd2bin);
8+
EXPORT_SYMBOL(_bcd2bin);
99

10-
unsigned char bin2bcd(unsigned val)
10+
unsigned char _bin2bcd(unsigned val)
1111
{
1212
return ((val / 10) << 4) + val % 10;
1313
}
14-
EXPORT_SYMBOL(bin2bcd);
14+
EXPORT_SYMBOL(_bin2bcd);

0 commit comments

Comments
 (0)