summaryrefslogtreecommitdiff
path: root/lib/bcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bcd.c')
-rw-r--r--lib/bcd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/bcd.c b/lib/bcd.c
index 40d304efe272..c5e79ba9cd7b 100644
--- a/lib/bcd.c
+++ b/lib/bcd.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
#include <linux/bcd.h>
#include <linux/export.h>
@@ -9,6 +10,8 @@ EXPORT_SYMBOL(_bcd2bin);
unsigned char _bin2bcd(unsigned val)
{
- return ((val / 10) << 4) + val % 10;
+ const unsigned int t = (val * 103) >> 10;
+
+ return (t << 4) | (val - t * 10);
}
EXPORT_SYMBOL(_bin2bcd);