From 3f03b64981723b61048ea46642bcaa9b518f3ad3 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 18 May 2020 22:36:17 +0300 Subject: [PATCH] auxdisplay: charlcd: Reuse hex_to_bin() instead of custom code hex_to_bin() may be used to convert hexdecimal digit to its binary representation. Signed-off-by: Andy Shevchenko Signed-off-by: Miguel Ojeda --- drivers/auxdisplay/charlcd.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c index d58278ae9e4a..5aee0f546351 100644 --- a/drivers/auxdisplay/charlcd.c +++ b/drivers/auxdisplay/charlcd.c @@ -485,24 +485,19 @@ static inline int handle_lcd_special_code(struct charlcd *lcd) shift = 0; value = 0; while (*esc && cgoffset < 8) { - 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++; - continue; - } + int half; + shift ^= 4; + + 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));