Skip to content

Commit 55b218c

Browse files
andy-shevdavem330
authored andcommitted
bnx2x: Replace custom scnprintf()
Use scnprintf() when printing version instead of custom open coded variants. Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Yuval Mintz <Yuval.Mintz@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4750c7b commit 55b218c

File tree

1 file changed

+9
-70
lines changed

1 file changed

+9
-70
lines changed

drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6163,94 +6163,33 @@ static void bnx2x_link_int_ack(struct link_params *params,
61636163

61646164
static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
61656165
{
6166-
u8 *str_ptr = str;
6167-
u32 mask = 0xf0000000;
6168-
u8 shift = 8*4;
6169-
u8 digit;
6170-
u8 remove_leading_zeros = 1;
6166+
u16 ret;
6167+
61716168
if (*len < 10) {
61726169
/* Need more than 10chars for this format */
6173-
*str_ptr = '\0';
6170+
*str = '\0';
61746171
(*len)--;
61756172
return -EINVAL;
61766173
}
6177-
while (shift > 0) {
61786174

6179-
shift -= 4;
6180-
digit = ((num & mask) >> shift);
6181-
if (digit == 0 && remove_leading_zeros) {
6182-
*str_ptr = '0';
6183-
} else {
6184-
if (digit < 0xa)
6185-
*str_ptr = digit + '0';
6186-
else
6187-
*str_ptr = digit - 0xa + 'a';
6188-
6189-
remove_leading_zeros = 0;
6190-
str_ptr++;
6191-
(*len)--;
6192-
}
6193-
mask = mask >> 4;
6194-
if (shift == 4*4) {
6195-
if (remove_leading_zeros) {
6196-
str_ptr++;
6197-
(*len)--;
6198-
}
6199-
*str_ptr = '.';
6200-
str_ptr++;
6201-
(*len)--;
6202-
remove_leading_zeros = 1;
6203-
}
6204-
}
6205-
if (remove_leading_zeros)
6206-
(*len)--;
6175+
ret = scnprintf(str, *len, "%hx.%hx", num >> 16, num);
6176+
*len -= ret;
62076177
return 0;
62086178
}
62096179

62106180
static int bnx2x_3_seq_format_ver(u32 num, u8 *str, u16 *len)
62116181
{
6212-
u8 *str_ptr = str;
6213-
u32 mask = 0x00f00000;
6214-
u8 shift = 8*3;
6215-
u8 digit;
6216-
u8 remove_leading_zeros = 1;
6182+
u16 ret;
62176183

62186184
if (*len < 10) {
62196185
/* Need more than 10chars for this format */
6220-
*str_ptr = '\0';
6186+
*str = '\0';
62216187
(*len)--;
62226188
return -EINVAL;
62236189
}
62246190

6225-
while (shift > 0) {
6226-
shift -= 4;
6227-
digit = ((num & mask) >> shift);
6228-
if (digit == 0 && remove_leading_zeros) {
6229-
*str_ptr = '0';
6230-
} else {
6231-
if (digit < 0xa)
6232-
*str_ptr = digit + '0';
6233-
else
6234-
*str_ptr = digit - 0xa + 'a';
6235-
6236-
remove_leading_zeros = 0;
6237-
str_ptr++;
6238-
(*len)--;
6239-
}
6240-
mask = mask >> 4;
6241-
if ((shift == 4*4) || (shift == 4*2)) {
6242-
if (remove_leading_zeros) {
6243-
str_ptr++;
6244-
(*len)--;
6245-
}
6246-
*str_ptr = '.';
6247-
str_ptr++;
6248-
(*len)--;
6249-
remove_leading_zeros = 1;
6250-
}
6251-
}
6252-
if (remove_leading_zeros)
6253-
(*len)--;
6191+
ret = scnprintf(str, *len, "%hhx.%hhx.%hhx", num >> 16, num >> 8, num);
6192+
*len -= ret;
62546193
return 0;
62556194
}
62566195

0 commit comments

Comments
 (0)