]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
pinctrl: single: check function mask to be non-zero
authorDario Binacchi <dariobin@libero.it>
Thu, 22 Apr 2021 16:35:58 +0000 (18:35 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 27 Apr 2021 12:05:30 +0000 (08:05 -0400)
Otherwise it can generate a division by zero, which has an undefined
behavior.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
drivers/pinctrl/pinctrl-single.c

index 48bdd0f6f5b3e79c6a9810c043ea20d3a2030eec..17f3818dd11eb9c011f2fca2fc3df2f702a2eef5 100644 (file)
@@ -335,6 +335,10 @@ static int single_configure_bits(struct udevice *dev,
        phys_addr_t reg;
        u32 offset, val, mask, bit_pos, val_pos, mask_pos, submask;
 
+       /* If function mask is null, needn't enable it. */
+       if (!pdata->mask)
+               return 0;
+
        npins_in_reg = pdata->width / priv->bits_per_pin;
        func = single_allocate_function(dev, count * npins_in_reg);
        if (IS_ERR(func))
@@ -469,6 +473,11 @@ static int single_probe(struct udevice *dev)
 
        priv->npins = size / (pdata->width / BITS_PER_BYTE);
        if (pdata->bits_per_mux) {
+               if (!pdata->mask) {
+                       dev_err(dev, "function mask needs to be non-zero\n");
+                       return -EINVAL;
+               }
+
                priv->bits_per_pin = fls(pdata->mask);
                priv->npins *= (pdata->width / priv->bits_per_pin);
        }