[PATCH 1/5] dm: pwm: Check if duty_ns is lower than period_ns

Cheick Traore cheick.traore at foss.st.com
Thu Mar 6 11:56:16 CET 2025


It was possible to provide a duty_ns greater than period_ns to
"pwm config" command. The framework must check the values before
providing them to drivers.

Signed-off-by: Cheick Traore <cheick.traore at foss.st.com>
---

 drivers/pwm/pwm-uclass.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pwm/pwm-uclass.c b/drivers/pwm/pwm-uclass.c
index 6543db1d623..b4491f7dcd4 100644
--- a/drivers/pwm/pwm-uclass.c
+++ b/drivers/pwm/pwm-uclass.c
@@ -27,6 +27,9 @@ int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
 	if (!ops->set_config)
 		return -ENOSYS;
 
+	if (duty_ns > period_ns)
+		return -EINVAL;
+
 	return ops->set_config(dev, channel, period_ns, duty_ns);
 }
 
-- 
2.34.1



More information about the U-Boot mailing list