Skip to contentSkip to conversation

Input: pwm-beeper - add range check for parameter.

PATCH In review Tamura Dai 2 participants 2 messages Jan 6, 2025

Subsystems (2)
lore
Share & tools
lore

Tamura Dai

author
#0 lore raw

PATCH 1/1 Input: pwm-beeper - add range check for parameter.

The parameter "beeper-hz" range is defined in pwm-beeper.yaml, so add range check.

---
 drivers/input/misc/pwm-beeper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/pwm-beeper.c +1 -1
index 0e19e97d98ec..455054f9aae6 100644
@@ -153,7 +153,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	INIT_WORK(&beeper->work, pwm_beeper_work);
 
 	error = device_property_read_u32(dev, "beeper-hz", &bell_frequency);
-	if (error) {
+	if (error || (bell_frequency < 10) || (bell_frequency > 10000)) {
 		bell_frequency = 1000;
 		dev_dbg(dev,
 			"failed to parse 'beeper-hz' property, using default: %uHz\n",
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 2 lines · Tamura Dai

The parameter "beeper-hz" range is defined in pwm-beeper.yaml, so add range check.

What will happen if we try to use data that is out of range?

We now do have tools to check whether DTS is compliant bindings, so I wonder how useful to also have checks in the kernel....

Quoted 22 lines
---
 drivers/input/misc/pwm-beeper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/pwm-beeper.c +1 -1
index 0e19e97d98ec..455054f9aae6 100644
@@ -153,7 +153,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	INIT_WORK(&beeper->work, pwm_beeper_work);
 
 	error = device_property_read_u32(dev, "beeper-hz", &bell_frequency);
-	if (error) {
+	if (error || (bell_frequency < 10) || (bell_frequency > 10000)) {
 		bell_frequency = 1000;
 		dev_dbg(dev,
 			"failed to parse 'beeper-hz' property, using default: %uHz\n",
Signature · 1 line
2.45.2

Thanks.

Signature · 1 line
Dmitry