mirror of
https://github.com/torvalds/linux.git
synced 2026-11-30 18:42:21 +00:00
gpio: bail out silently on NULL descriptors
Infdeb8e1547("gpio: reflect base and ngpio into gpio_device") assumed that GPIO descriptors are either valid or error pointers, but gpiod_get_[index_]optional() actually return NULL descriptors and then all subsequent calls should just bail out. Cc: [email protected] Cc: Sergei Shtylyov <[email protected]> Cc: Florian Fainelli <[email protected]> Cc: Andrew Lunn <[email protected]> Fixes:fdeb8e1547("gpio: reflect base and ngpio into gpio_device") Reported-by: Uwe Kleine-König <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
This commit is contained in:
@@ -1367,10 +1367,13 @@ done:
|
||||
/*
|
||||
* This descriptor validation needs to be inserted verbatim into each
|
||||
* function taking a descriptor, so we need to use a preprocessor
|
||||
* macro to avoid endless duplication.
|
||||
* macro to avoid endless duplication. If the desc is NULL it is an
|
||||
* optional GPIO and calls should just bail out.
|
||||
*/
|
||||
#define VALIDATE_DESC(desc) do { \
|
||||
if (!desc || !desc->gdev) { \
|
||||
if (!desc) \
|
||||
return 0; \
|
||||
if (!desc->gdev) { \
|
||||
pr_warn("%s: invalid GPIO\n", __func__); \
|
||||
return -EINVAL; \
|
||||
} \
|
||||
@@ -1381,7 +1384,9 @@ done:
|
||||
} } while (0)
|
||||
|
||||
#define VALIDATE_DESC_VOID(desc) do { \
|
||||
if (!desc || !desc->gdev) { \
|
||||
if (!desc) \
|
||||
return; \
|
||||
if (!desc->gdev) { \
|
||||
pr_warn("%s: invalid GPIO\n", __func__); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user