[PATCH 5/8] gpiolib: sanitize the return value of gpio_chip::get_multiple()

Bartosz Golaszewski posted 8 patches 10 months, 1 week ago
[PATCH 5/8] gpiolib: sanitize the return value of gpio_chip::get_multiple()
Posted by Bartosz Golaszewski 10 months, 1 week ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

As per the API contract, the get_multiple() callback is only allowed to
return 0 or a negative error number. Filter out anything else.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 7bc316154fdc..7255f4df6a8b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3164,8 +3164,13 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
 static int gpio_chip_get_multiple(struct gpio_chip *gc,
 				  unsigned long *mask, unsigned long *bits)
 {
-	if (gc->get_multiple)
-		return gc->get_multiple(gc, mask, bits);
+	int ret;
+
+	if (gc->get_multiple) {
+		ret = gc->get_multiple(gc, mask, bits);
+		if (ret > 0)
+			return -EBADE;
+	}
 	if (gc->get) {
 		int i, value;
 

-- 
2.45.2