|
@@ -38,14 +38,21 @@ EXPORT_SYMBOL(hex_to_bin);
|
|
|
* @dst: binary result
|
|
|
* @src: ascii hexadecimal string
|
|
|
* @count: result length
|
|
|
+ *
|
|
|
+ * Return 0 on success, -1 in case of bad input.
|
|
|
*/
|
|
|
-void hex2bin(u8 *dst, const char *src, size_t count)
|
|
|
+int hex2bin(u8 *dst, const char *src, size_t count)
|
|
|
{
|
|
|
while (count--) {
|
|
|
- *dst = hex_to_bin(*src++) << 4;
|
|
|
- *dst += hex_to_bin(*src++);
|
|
|
- dst++;
|
|
|
+ int hi = hex_to_bin(*src++);
|
|
|
+ int lo = hex_to_bin(*src++);
|
|
|
+
|
|
|
+ if ((hi < 0) || (lo < 0))
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ *dst++ = (hi << 4) | lo;
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
EXPORT_SYMBOL(hex2bin);
|
|
|
|