[bug report] bootcount: add a new driver with syscon as backend

Dan Carpenter dan.carpenter at linaro.org
Thu Jul 27 09:17:32 CEST 2023


Hello Nandor Han,

The patch c50b21b70523: "bootcount: add a new driver with syscon as
backend" from Jun 10, 2021 , leads to the following Smatch static
checker warning:

	drivers/bootcount/bootcount_syscon.c:56 bootcount_syscon_set()
	warn: double left shift '(regval & 65535) << ((priv->size) << 3)'

drivers/bootcount/bootcount_syscon.c
    44 static int bootcount_syscon_set(struct udevice *dev, const u32 val)
    45 {
    46         struct bootcount_syscon_priv *priv = dev_get_priv(dev);
    47         u32 regval;
    48 
    49         if ((val & priv->magic_mask) != 0)
    50                 return -EINVAL;
    51 
    52         regval = (priv->magic & priv->magic_mask) | (val & ~priv->magic_mask);
    53 
    54         if (priv->size == 2) {
    55                 regval &= 0xffff;
--> 56                 regval |= (regval & 0xffff) << BYTES_TO_BITS(priv->size);

I don't understand what's going on here but it doesn't look correct.
The 0xffff mask is a no-op because we already masked it on the previous
line.  priv->size is either 2 or 4.  So in bits that's 16 or 32.
But regval is a u32 and so shifting by 32 is undefined.

    57         }
    58 
    59         debug("%s: Prepare to write reg value: 0x%08x with register mask: 0x%08x\n",
    60               __func__, regval, priv->reg_mask);
    61 
    62         return regmap_update_bits(priv->regmap, priv->reg_addr, priv->reg_mask,
    63                                   regval);
    64 }

regards,
dan carpenter


More information about the U-Boot mailing list