Skip to contentSkip to conversation

pinctrl: single: check function mask to be non-zero

PATCH New Dario Binacchi 2 participants 2 messages Apr 22, 2021 – Apr 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: single: check function mask to be non-zero

Otherwise it can generate a division by zero, which has an undefined behavior.

---

 drivers/pinctrl/pinctrl-single.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pinctrl/pinctrl-single.c +9 -0
index 7e1c5bb0a5..ebb7602dde 100644
@@ -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);
 	}
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 pinctrl: single: check function mask to be non-zero

Quoted 4 lines · Dario Binacchi

Otherwise it can generate a division by zero, which has an undefined behavior.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210427/ce6334cb/attachment.sig>