Re: [PATCH v2 2/3] tools: gpio: validate arguments in gpiotools_request_line

From: 007

Date: Wed May 06 2026 - 20:05:03 EST


OK, I will redo it, thanks.

Best regards,

Zhang Xiaolei

On 5/5/26 00:13, Maxwell Doose wrote:
On Mon, May 4, 2026 at 2:56 AM Zhang Xiaolei <zxl434815272@xxxxxxxxx> wrote:
Add validation for input pointers and number of lines.

Perhaps make the commit message more descriptive?

Signed-off-by: Zhang Xiaolei <zxl434815272@xxxxxxxxx>
---
tools/gpio/gpio-utils.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/tools/gpio/gpio-utils.c b/tools/gpio/gpio-utils.c
index 176bccfcccb0..930a38fe7911 100644
--- a/tools/gpio/gpio-utils.c
+++ b/tools/gpio/gpio-utils.c
@@ -65,6 +65,12 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,
int i;
int ret;

+ if (!device_name || !lines || !config || !consumer || !num_lines)
+ return -EINVAL;
+
+ if (num_lines > GPIO_V2_LINES_MAX)
+ return -EINVAL;
+
I'm wondering if we might want to use ERANGE here for the num_lines >
GPIO_V2_LINES_MAX check instead of EINVAL.

best regards,
maxwell