Netdev List
 help / color / mirror / Atom feed
* [bug report] net: dsa: yt921x: Add support for Motorcomm YT921x
@ 2025-10-24  6:57 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2025-10-24  6:57 UTC (permalink / raw)
  To: David Yang; +Cc: netdev

Hello David Yang,

Commit 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm
YT921x") from Oct 17, 2025 (linux-next), leads to 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)'

drivers/net/dsa/yt921x.c
    671 static int yt921x_read_mib(struct yt921x_priv *priv, int port)
    672 {
    673         struct yt921x_port *pp = &priv->ports[port];
    674         struct device *dev = to_device(priv);
    675         struct yt921x_mib *mib = &pp->mib;
    676         int res = 0;
    677 
    678         /* Reading of yt921x_port::mib is not protected by a lock and it's vain
    679          * to keep its consistency, since we have to read registers one by one
    680          * and there is no way to make a snapshot of MIB stats.
    681          *
    682          * Writing (by this function only) is and should be protected by
    683          * reg_lock.
    684          */
    685 
    686         for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) {
    687                 const struct yt921x_mib_desc *desc = &yt921x_mib_descs[i];
    688                 u32 reg = YT921X_MIBn_DATA0(port) + desc->offset;
    689                 u64 *valp = &((u64 *)mib)[i];
    690                 u64 val = *valp;
    691                 u32 val0;
    692                 u32 val1;
    693 
    694                 res = yt921x_reg_read(priv, reg, &val0);
    695                 if (res)
    696                         break;
    697 
    698                 if (desc->size <= 1) {
    699                         if (val < (u32)val)
    700                                 /* overflow */
    701                                 val += (u64)U32_MAX + 1;
--> 702                         val &= ~U32_MAX;

~U32_MAX is zero so this is just "val = 0;"  Perhaps the intent
was "val &= ~(u64)U32_MAX;"?

    703                         val |= val0;
    704                 } else {
    705                         res = yt921x_reg_read(priv, reg + 4, &val1);
    706                         if (res)
    707                                 break;
    708                         val = ((u64)val0 << 32) | val1;
    709                 }
    710 
    711                 WRITE_ONCE(*valp, val);
    712         }
    713 

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-24  6:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24  6:57 [bug report] net: dsa: yt921x: Add support for Motorcomm YT921x Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox