Commit 55b218c1 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by David S. Miller

bnx2x: Replace custom scnprintf()

Use scnprintf() when printing version instead of custom open coded variants.
Signed-off-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: default avatarYuval Mintz <Yuval.Mintz@cavium.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4750c7be
...@@ -6163,94 +6163,33 @@ static void bnx2x_link_int_ack(struct link_params *params, ...@@ -6163,94 +6163,33 @@ static void bnx2x_link_int_ack(struct link_params *params,
static int bnx2x_format_ver(u32 num, u8 *str, u16 *len) static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
{ {
u8 *str_ptr = str; u16 ret;
u32 mask = 0xf0000000;
u8 shift = 8*4;
u8 digit;
u8 remove_leading_zeros = 1;
if (*len < 10) { if (*len < 10) {
/* Need more than 10chars for this format */ /* Need more than 10chars for this format */
*str_ptr = '\0'; *str = '\0';
(*len)--; (*len)--;
return -EINVAL; return -EINVAL;
} }
while (shift > 0) {
shift -= 4; ret = scnprintf(str, *len, "%hx.%hx", num >> 16, num);
digit = ((num & mask) >> shift); *len -= ret;
if (digit == 0 && remove_leading_zeros) {
*str_ptr = '0';
} else {
if (digit < 0xa)
*str_ptr = digit + '0';
else
*str_ptr = digit - 0xa + 'a';
remove_leading_zeros = 0;
str_ptr++;
(*len)--;
}
mask = mask >> 4;
if (shift == 4*4) {
if (remove_leading_zeros) {
str_ptr++;
(*len)--;
}
*str_ptr = '.';
str_ptr++;
(*len)--;
remove_leading_zeros = 1;
}
}
if (remove_leading_zeros)
(*len)--;
return 0; return 0;
} }
static int bnx2x_3_seq_format_ver(u32 num, u8 *str, u16 *len) static int bnx2x_3_seq_format_ver(u32 num, u8 *str, u16 *len)
{ {
u8 *str_ptr = str; u16 ret;
u32 mask = 0x00f00000;
u8 shift = 8*3;
u8 digit;
u8 remove_leading_zeros = 1;
if (*len < 10) { if (*len < 10) {
/* Need more than 10chars for this format */ /* Need more than 10chars for this format */
*str_ptr = '\0'; *str = '\0';
(*len)--; (*len)--;
return -EINVAL; return -EINVAL;
} }
while (shift > 0) { ret = scnprintf(str, *len, "%hhx.%hhx.%hhx", num >> 16, num >> 8, num);
shift -= 4; *len -= ret;
digit = ((num & mask) >> shift);
if (digit == 0 && remove_leading_zeros) {
*str_ptr = '0';
} else {
if (digit < 0xa)
*str_ptr = digit + '0';
else
*str_ptr = digit - 0xa + 'a';
remove_leading_zeros = 0;
str_ptr++;
(*len)--;
}
mask = mask >> 4;
if ((shift == 4*4) || (shift == 4*2)) {
if (remove_leading_zeros) {
str_ptr++;
(*len)--;
}
*str_ptr = '.';
str_ptr++;
(*len)--;
remove_leading_zeros = 1;
}
}
if (remove_leading_zeros)
(*len)--;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment