auxdisplay: charlcd: Reuse hex_to_bin() instead of custom code
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 18 May 2020 19:36:17 +0000 (22:36 +0300)
committerMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Fri, 29 May 2020 21:33:50 +0000 (23:33 +0200)
hex_to_bin() may be used to convert hexdecimal digit to its binary
representation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
drivers/auxdisplay/charlcd.c

index d58278a..5aee0f5 100644 (file)
@@ -485,24 +485,19 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
                shift = 0;
                value = 0;
                while (*esc && cgoffset < 8) {
+                       int half;
+
                        shift ^= 4;
-                       if (*esc >= '0' && *esc <= '9') {
-                               value |= (*esc - '0') << shift;
-                       } else if (*esc >= 'A' && *esc <= 'F') {
-                               value |= (*esc - 'A' + 10) << shift;
-                       } else if (*esc >= 'a' && *esc <= 'f') {
-                               value |= (*esc - 'a' + 10) << shift;
-                       } else {
-                               esc++;
+
+                       half = hex_to_bin(*esc++);
+                       if (half < 0)
                                continue;
-                       }
 
+                       value |= half << shift;
                        if (shift == 0) {
                                cgbytes[cgoffset++] = value;
                                value = 0;
                        }
-
-                       esc++;
                }
 
                lcd->ops->write_cmd(lcd, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));