linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: pwm-beeper - add range check for parameter.
@ 2025-01-06  2:55 Tamura Dai
  2025-01-06  7:13 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Tamura Dai @ 2025-01-06  2:55 UTC (permalink / raw)
  To: Dmitry Torokhov, Javier Carrasco; +Cc: linux-input, linux-kernel, Tamura Dai

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

Signed-off-by: Tamura Dai <kirinode0@gmail.com>
---
 drivers/input/misc/pwm-beeper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index 0e19e97d98ec..455054f9aae6 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -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",
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Input: pwm-beeper - add range check for parameter.
  2025-01-06  2:55 [PATCH] Input: pwm-beeper - add range check for parameter Tamura Dai
@ 2025-01-06  7:13 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2025-01-06  7:13 UTC (permalink / raw)
  To: Tamura Dai; +Cc: Javier Carrasco, linux-input, linux-kernel

On Mon, Jan 06, 2025 at 11:55:28AM +0900, Tamura Dai wrote:
> 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....

> 
> Signed-off-by: Tamura Dai <kirinode0@gmail.com>
> ---
>  drivers/input/misc/pwm-beeper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
> index 0e19e97d98ec..455054f9aae6 100644
> --- a/drivers/input/misc/pwm-beeper.c
> +++ b/drivers/input/misc/pwm-beeper.c
> @@ -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",
> -- 
> 2.45.2
> 

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-06  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-06  2:55 [PATCH] Input: pwm-beeper - add range check for parameter Tamura Dai
2025-01-06  7:13 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).