/* While we find nice hex chars, build a long_val. Return number of chars processed.  */
int kgdb_hex2long(char **ptr, unsigned long *long_val)
/* While we find nice hex chars, build a long_val. Return number of chars processed.  */
int kgdb_hex2long(char **ptr, unsigned long *long_val)
{
	int hex_val;
	int num = 0;
	int negate = 0;
	*long_val = 0;
	if (**ptr == '-') {
		negate = 1;
		(*ptr)++;
	}
	while (**ptr) {
		hex_val = hex(**ptr);
		if (hex_val < 0)
			break;
		*long_val = (*long_val << 4) | hex_val;
		num++;
		(*ptr)++;
	}
	if (negate)
		*long_val = -*long_val;
	return num;
}