lkml.org 
[lkml]   [2011]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] net: can: remove custom hex_to_bin()
From
Date
On Mon, 2011-07-18 at 20:41 +0900, Tetsuo Handa wrote: 
> Andy Shevchenko wrote:
> > for (i = 0, dlc_pos++; i < cf.can_dlc; i++) {
> > -
> > - tmp = asc2nibble(sl->rbuff[dlc_pos++]);
> > - if (tmp > 0x0F)
> > + tmp = hex_to_bin(sl->rbuff[dlc_pos++]);
> > + if (tmp < 0)
> > return;
> > cf.data[i] = (tmp << 4);
> > - tmp = asc2nibble(sl->rbuff[dlc_pos++]);
> > - if (tmp > 0x0F)
> > + tmp = hex_to_bin(sl->rbuff[dlc_pos++]);
> > + if (tmp < 0)
> > return;
> > cf.data[i] |= tmp;
> > }
>
> What about changing
>
> void hex2bin(u8 *dst, const char *src, size_t count)
>
> to
>
> bool hex2bin(u8 *dst, const char *src, size_t count)
>
> in order to do error checks like
>
> bool hex2bin_with_validation(u8 *dst, const char *src, size_t count)
> {
> while (count--) {
> int c = hex_to_bin(*src++);
> int d;
> if (c < 0)
> return false;
> d = hex_to_bin(*src++)
> if (d < 0)
> return false;
> *dst++ = (c << 4) | d;
> }
> return true;
> }
>
> and use hex2bin() rather than hex_to_bin()?
Perhaps, good idea. Could you submit a patch?

--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy


\
 
 \ /
  Last update: 2011-07-18 14:25    [W:0.090 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site