diff options
author | Dario Binacchi | 2021-04-22 18:35:58 +0200 |
---|---|---|
committer | Tom Rini | 2021-04-27 08:05:30 -0400 |
commit | 69414d86ed57bf7b55ccd79d3d5ca5a01987a5b7 (patch) | |
tree | fcf0ccdd9fbbed3ab33fca17c9b534905e5159cf /drivers/pinctrl | |
parent | 7ac7038ab36feff54e882422de0f3127db094565 (diff) |
pinctrl: single: check function mask to be non-zero
Otherwise it can generate a division by zero, which has an undefined
behavior.
Signed-off-by: Dario Binacchi <dariobin@libero.it>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/pinctrl-single.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 48bdd0f6f5b..17f3818dd11 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -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); } |