[PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration

Markus Burri posted 7 patches 2 months ago
There is a newer version of this series
[PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Markus Burri 2 months ago
The delay is retrieved from a device-tree property, so the duration is
variable. fsleep guesses the best delay function based on duration.

see Documentation/timers/delay_sleep_functions.rst

Signed-off-by: Markus Burri <markus.burri@mt.com>

---
 drivers/input/keyboard/matrix_keypad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index 2a3b3bf..5571d2e 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -68,7 +68,7 @@ static void activate_col(struct matrix_keypad *keypad, int col, bool on)
 	__activate_col(keypad, col, on);
 
 	if (on && keypad->col_scan_delay_us)
-		udelay(keypad->col_scan_delay_us);
+		fsleep(keypad->col_scan_delay_us);
 }
 
 static void activate_all_cols(struct matrix_keypad *keypad, bool on)
-- 
2.39.5
Re: [PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Dmitry Torokhov 2 weeks, 2 days ago
On Fri, Jan 10, 2025 at 06:49:00AM +0100, Markus Burri wrote:
> The delay is retrieved from a device-tree property, so the duration is
> variable. fsleep guesses the best delay function based on duration.
> 
> see Documentation/timers/delay_sleep_functions.rst
> 
> Signed-off-by: Markus Burri <markus.burri@mt.com>
> 

Applied, thank you.

-- 
Dmitry
Re: [PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Manuel Traut 3 weeks, 1 day ago
On Fri, Jan 10, 2025 at 06:49:00AM +0100, Markus Burri wrote:
> The delay is retrieved from a device-tree property, so the duration is
> variable. fsleep guesses the best delay function based on duration.
> 
> see Documentation/timers/delay_sleep_functions.rst
> 
> Signed-off-by: Markus Burri <markus.burri@mt.com>

Reviewed-by: Manuel Traut <manuel.traut@mt.com> 

> ---
>  drivers/input/keyboard/matrix_keypad.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index 2a3b3bf..5571d2e 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -68,7 +68,7 @@ static void activate_col(struct matrix_keypad *keypad, int col, bool on)
>  	__activate_col(keypad, col, on);
>  
>  	if (on && keypad->col_scan_delay_us)
> -		udelay(keypad->col_scan_delay_us);
> +		fsleep(keypad->col_scan_delay_us);
>  }
>  
>  static void activate_all_cols(struct matrix_keypad *keypad, bool on)
> -- 
> 2.39.5
>
Re: [PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Dmitry Torokhov 2 weeks, 3 days ago
On Wed, Feb 19, 2025 at 05:34:49PM +0100, Manuel Traut wrote:
> On Fri, Jan 10, 2025 at 06:49:00AM +0100, Markus Burri wrote:
> > The delay is retrieved from a device-tree property, so the duration is
> > variable. fsleep guesses the best delay function based on duration.
> > 
> > see Documentation/timers/delay_sleep_functions.rst
> > 
> > Signed-off-by: Markus Burri <markus.burri@mt.com>
> 
> Reviewed-by: Manuel Traut <manuel.traut@mt.com> 

As I mentioned in other review activate_col() may be called in atomic
context where we can not sleep:

"activate_col() may be called in atomic context, and if fsleep() turns
into usleep_range() or msleep() we are going to have a bad time.

We should either stop using request_any_context_irq() or figure out if
interrupt handler can sleep or not and adjust behavior properly."

Unfortunately this was completely ignored.

> 
> > ---
> >  drivers/input/keyboard/matrix_keypad.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> > index 2a3b3bf..5571d2e 100644
> > --- a/drivers/input/keyboard/matrix_keypad.c
> > +++ b/drivers/input/keyboard/matrix_keypad.c
> > @@ -68,7 +68,7 @@ static void activate_col(struct matrix_keypad *keypad, int col, bool on)
> >  	__activate_col(keypad, col, on);
> >  
> >  	if (on && keypad->col_scan_delay_us)
> > -		udelay(keypad->col_scan_delay_us);
> > +		fsleep(keypad->col_scan_delay_us);
> >  }
> >  
> >  static void activate_all_cols(struct matrix_keypad *keypad, bool on)
> > -- 
> > 2.39.5
> > 

Thanks.

-- 
Dmitry
Re: [PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Dmitry Torokhov 2 weeks, 3 days ago
On Mon, Feb 24, 2025 at 10:40:55PM -0800, Dmitry Torokhov wrote:
> On Wed, Feb 19, 2025 at 05:34:49PM +0100, Manuel Traut wrote:
> > On Fri, Jan 10, 2025 at 06:49:00AM +0100, Markus Burri wrote:
> > > The delay is retrieved from a device-tree property, so the duration is
> > > variable. fsleep guesses the best delay function based on duration.
> > > 
> > > see Documentation/timers/delay_sleep_functions.rst
> > > 
> > > Signed-off-by: Markus Burri <markus.burri@mt.com>
> > 
> > Reviewed-by: Manuel Traut <manuel.traut@mt.com> 
> 
> As I mentioned in other review activate_col() may be called in atomic
> context where we can not sleep:
> 
> "activate_col() may be called in atomic context, and if fsleep() turns
> into usleep_range() or msleep() we are going to have a bad time.
> 
> We should either stop using request_any_context_irq() or figure out if
> interrupt handler can sleep or not and adjust behavior properly."
> 
> Unfortunately this was completely ignored.

My apologies, it looks like it only is called from work handler, so my
comment was wrong.

Thanks.

-- 
Dmitry
Re: [PATCH v5 1/7] Input: matrix_keypad - use fsleep for variable delay duration
Posted by Markus Burri 2 weeks, 2 days ago
On Mon, Feb 24, 2025 at 10:55:36PM -0800, Dmitry Torokhov wrote:
> On Mon, Feb 24, 2025 at 10:40:55PM -0800, Dmitry Torokhov wrote:
> > On Wed, Feb 19, 2025 at 05:34:49PM +0100, Manuel Traut wrote:
> > > On Fri, Jan 10, 2025 at 06:49:00AM +0100, Markus Burri wrote:
> > > > The delay is retrieved from a device-tree property, so the duration is
> > > > variable. fsleep guesses the best delay function based on duration.
> > > > 
> > > > see Documentation/timers/delay_sleep_functions.rst
> > > > 
> > > > Signed-off-by: Markus Burri <markus.burri@mt.com>
> > > 
> > > Reviewed-by: Manuel Traut <manuel.traut@mt.com> 
> > 
> > As I mentioned in other review activate_col() may be called in atomic
> > context where we can not sleep:
> > 
> > "activate_col() may be called in atomic context, and if fsleep() turns
> > into usleep_range() or msleep() we are going to have a bad time.
> > 
> > We should either stop using request_any_context_irq() or figure out if
> > interrupt handler can sleep or not and adjust behavior properly."
> > 
> > Unfortunately this was completely ignored.
> 
> My apologies, it looks like it only is called from work handler, so my
> comment was wrong.
> 
> Thanks.

Yes sorry to ignore, it is only called in work handler
> 
> -- 
> Dmitry