Thread (2 messages) read the whole thread 2 messages, 2 authors, 2016-06-16

Re: [PATCH] gpio: make library immune to error pointers

From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: 2016-06-16 10:19:22
Also in: stable

On 06/16/2016 12:59 PM, Linus Walleij wrote:
quoted hunk ↗ jump to hunk
Most functions that take a GPIO descriptor in need to check the
descriptor for IS_ERR(). We do this mostly in the VALIDATE_DESC()
macro except for the gpiod_to_irq() function which needs special
handling.

Cc: stable@vger.kernel.org
Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Linus Walleij <redacted>
---
  drivers/gpio/gpiolib.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f39bf05993e7..1a8dbc791892 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1371,7 +1371,7 @@ done:
   * optional GPIO and calls should just bail out.
   */
  #define VALIDATE_DESC(desc) do { \
-	if (!desc) \
+	if (!desc || IS_ERR(desc)) \
  		return 0; \
i do not think this right thing to return 0 here :(
if IS_ERR(desc) this is bug and drivers must handle this properly.

For example, -EPROBE_DEFER
quoted hunk ↗ jump to hunk
  	if (!desc->gdev) { \
  		pr_warn("%s: invalid GPIO\n", __func__); \
@@ -1384,7 +1384,7 @@ done:
  	} } while (0)

  #define VALIDATE_DESC_VOID(desc) do { \
-	if (!desc) \
+	if (!desc || IS_ERR(desc)) \
  		return; \
  	if (!desc->gdev) { \
  		pr_warn("%s: invalid GPIO\n", __func__); \
@@ -2061,7 +2061,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
  	 * requires this function to not return zero on an invalid descriptor
  	 * but rather a negative error number.
  	 */
-	if (!desc || !desc->gdev || !desc->gdev->chip)
+	if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
  		return -EINVAL;

  	chip = desc->gdev->chip;

-- 
regards,
-grygorii
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help