mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 14:41:31 +00:00
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>
This commit is contained in:
parent
c6ecb2f81e
commit
10221d2847
1 changed files with 9 additions and 0 deletions
|
@ -335,6 +335,10 @@ static int single_configure_bits(struct udevice *dev,
|
||||||
phys_addr_t reg;
|
phys_addr_t reg;
|
||||||
u32 offset, val, mask, bit_pos, val_pos, mask_pos, submask;
|
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;
|
npins_in_reg = pdata->width / priv->bits_per_pin;
|
||||||
func = single_allocate_function(dev, count * npins_in_reg);
|
func = single_allocate_function(dev, count * npins_in_reg);
|
||||||
if (IS_ERR(func))
|
if (IS_ERR(func))
|
||||||
|
@ -469,6 +473,11 @@ static int single_probe(struct udevice *dev)
|
||||||
|
|
||||||
priv->npins = size / (pdata->width / BITS_PER_BYTE);
|
priv->npins = size / (pdata->width / BITS_PER_BYTE);
|
||||||
if (pdata->bits_per_mux) {
|
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->bits_per_pin = fls(pdata->mask);
|
||||||
priv->npins *= (pdata->width / priv->bits_per_pin);
|
priv->npins *= (pdata->width / priv->bits_per_pin);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue