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

From: Zhang Xiaolei

Date: Mon May 04 2026 - 03:56:13 EST


Add validation for input pointers and number of lines.

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;
+
ret = asprintf(&chrdev_name, "/dev/%s", device_name);
if (ret < 0)
return -ENOMEM;
--
2.34.1