Input: charlieplex_keypad - check gpiod_direction_output() return value
Subsystems (3)
PATCH 1/1 Input: charlieplex_keypad - check gpiod_direction_output() return value
From: Surendra Singh Chouhan <[email protected]>
charlieplex_keypad_scan_line() currently ignores the return value of gpiod_direction_output() when setting the active output line for scanning.
If setting the GPIO direction fails (e.g. on I2C/SPI GPIO expanders or hardware errors), the function continues to sleep and read input values from an improperly configured GPIO line.
Fix this by capturing the return value of gpiod_direction_output() and returning the error code immediately if it fails.
--- drivers/input/keyboard/charlieplex_keypad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/keyboard/charlieplex_keypad.c +3 -1
@@ -77,7 +77,9 @@ static int charlieplex_keypad_scan_line(struct charlieplex_keypad *keypad,int err;/* Activate only one line as output at a time. */ -gpiod_direction_output (line_gpios->desc[oline],1 ); + err =gpiod_direction_output (line_gpios->desc[oline],1 ); +if (err) +return err;if (keypad->settling_time_us)fsleep (keypad->settling_time_us);
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The return value of gpiod_direction_input() is ignored, which can leave the line configured as an output driving HIGH upon hardware failure, breaking the matrix scanning logic. --
--- Patch [1]: [PATCH] Input: charlieplex_keypad - check gpiod_direction_output() return value --- commit dcc381a1c321f8eedf04b92519f6edd1db4050eb
Author: Surendra Singh Chouhan <[email protected]>
Input: charlieplex_keypad - check gpiod_direction_output() return value
This commit updates charlieplex_keypad_scan_line() to capture and return the error code if setting the active output line fails. This prevents the keypad from continuing to sleep and read inputs from an improperly configured GPIO.
drivers/input/keyboard/charlieplex_keypad.c static int charlieplex_keypad_scan_line(struct charlieplex_keypad *keypad, · line 82
Quoted 11 lines
drivers/input/keyboard/charlieplex_keypad.c +3
-1@@ -77,7 +77,9 @@ static int charlieplex_keypad_scan_line(struct charlieplex_keypad *keypad,int err;/* Activate only one line as output at a time. */ -gpiod_direction_output (line_gpios->desc[oline],1 ); + err =gpiod_direction_output (line_gpios->desc[oline],1 ); +if (err) +return err;
[Severity: High]
This is a pre-existing issue, but since this patch explicitly adds error checking for gpiod_direction_output(), should we also check the return value when restoring the line to an input state?
A few lines below in charlieplex_keypad_scan_line(), the same pattern exists when restoring the line direction:
err = gpiod_get_array_value_cansleep(line_gpios->ndescs, ...); gpiod_direction_input(line_gpios->desc[oline]); if (err) return err;
If gpiod_direction_input() fails here due to a temporary hardware or bus error (like on an i2c or spi GPIO expander), does this leave the line configured as an output driving high?
On subsequent scans, this could cause multiple lines to act as outputs simultaneously and break the matrix scanning logic entirely.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · On Thu, Jul 23, 2026 at 07:59:43AM +0530, [email protected] wrote:
From: Surendra Singh Chouhan <[email protected]>
charlieplex_keypad_scan_line()currently ignores the return value ofgpiod_direction_output()when setting the active output line for scanning.If setting the GPIO direction fails (e.g. on I2C/SPI GPIO expanders or hardware errors), the function continues to sleep and read input values from an improperly configured GPIO line.
Quoted 5 lines
Fix this by capturing the return value of
gpiod_direction_output()and returning the error code immediately if it fails.Fixes 2ca45e57ea02 ("Input: charlieplex_keypad - add GPIO charlieplex keypad")Signed-off-by Surendra Singh Chouhan <[email protected]>
Applied, thank you.
Signature · 1 line
Dmitry