[PATCH 3/3] staging: speakup: reuse native hex2bin()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
 drivers/staging/speakup/varhandlers.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c
index fb479a5..edb7ff3 100644
--- a/drivers/staging/speakup/varhandlers.c
+++ b/drivers/staging/speakup/varhandlers.c
@@ -333,9 +333,9 @@ char *spk_xlate(char *s)
 {
 	static const char finds[] = "nrtvafe";
 	static const char subs[] = "\n\r\t\013\001\014\033";
-	static const char hx[] = "0123456789abcdefABCDEF";
-	char *p = s, *p1, *p2, c;
+	char *p = s, *p1, *p2;
 	int num;
+
 	while ((p = strchr(p, '\\'))) {
 		p1 = p+1;
 		p2 = strchr(finds, *p1);
@@ -349,24 +349,13 @@ char *spk_xlate(char *s)
 				num = (*p1++)&7;
 			}
 			*p++ = num;
-		} else if (*p1 == 'x' &&
-				strchr(hx, p1[1]) && strchr(hx, p1[2])) {
-			p1++;
-			c = *p1++;
-			if (c > '9')
-				c = (c - '7') & 0x0f;
-			else
-				c -= '0';
-			num = c << 4;
-			c = *p1++;
-			if (c > '9')
-				c = (c-'7')&0x0f;
-			else
-				c -= '0';
-			num += c;
-			*p++ = num;
-		} else
-			*p++ = *p1++;
+		} else {
+			if (*p1 == 'x' && !hex2bin((u8 *)&num, p1 + 1, 1)) {
+				p1 += 3;
+				*p++ = num;
+			} else
+				*p++ = *p1++;
+		}
 		p2 = p;
 		while (*p1)
 			*p2++ = *p1++;
-- 
1.8.2.rc0.22.gb3600c3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux