Skip to content

Commit ee250a1

Browse files
drivers: gpio: GPIO_DT_SPEC_GET_BY_IDX_OR: use default if idx invalid
It is not sufficient to check if the given node_id has the requested property in GPIO_DT_SPEC_GET_BY_IDX_OR(), the index also needs to valid. Change the logic to test for a valid index (which, in turn, also checks if the property is valid), otherwise return the default value provided by the caller. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 3c420a4 commit ee250a1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/zephyr/drivers/gpio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ struct gpio_dt_spec {
340340
* @brief Like GPIO_DT_SPEC_GET_BY_IDX(), with a fallback to a default value
341341
*
342342
* If the devicetree node identifier 'node_id' refers to a node with a
343-
* property 'prop', this expands to
344-
* <tt>GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)</tt>. The @p
343+
* property 'prop', and the index @p idx is valid for that property,
344+
* this expands to <tt>GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)</tt>. The @p
345345
* default_value parameter is not expanded in this case.
346346
*
347347
* Otherwise, this expands to @p default_value.
@@ -354,7 +354,7 @@ struct gpio_dt_spec {
354354
* or default_value if the node or property do not exist
355355
*/
356356
#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
357-
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
357+
COND_CODE_1(DT_PROP_HAS_IDX(node_id, prop, idx), \
358358
(GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
359359
(default_value))
360360

0 commit comments

Comments
 (0)