Skip to content

Commit 709bbb0

Browse files
yangflkuba-moo
authored andcommitted
net: dsa: yt921x: Fix MIB overflow wraparound routine
Reported by the following Smatch static checker warning: drivers/net/dsa/yt921x.c:702 yt921x_read_mib() warn: was expecting a 64 bit value instead of '(~0)' Fixes: 186623f ("net: dsa: yt921x: Add support for Motorcomm YT921x") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Suggested-by: David Laight <[email protected]> Signed-off-by: David Yang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ca12c4a commit 709bbb0

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/net/dsa/yt921x.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -682,21 +682,22 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)
682682
const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i];
683683
u32 reg = YT921X_MIBn_DATA0(port) + desc->offset;
684684
u64 *valp = &((u64 *)mib)[i];
685-
u64 val = *valp;
686685
u32 val0;
687-
u32 val1;
686+
u64 val;
688687

689688
res = yt921x_reg_read(priv, reg, &val0);
690689
if (res)
691690
break;
692691

693692
if (desc->size <= 1) {
694-
if (val < (u32)val)
695-
/* overflow */
696-
val += (u64)U32_MAX + 1;
697-
val &= ~U32_MAX;
698-
val |= val0;
693+
u64 old_val = *valp;
694+
695+
val = (old_val & ~(u64)U32_MAX) | val0;
696+
if (val < old_val)
697+
val += 1ull << 32;
699698
} else {
699+
u32 val1;
700+
700701
res = yt921x_reg_read(priv, reg + 4, &val1);
701702
if (res)
702703
break;

0 commit comments

Comments
 (0)