Skip to content

Commit

Permalink
drivers: gpio: GPIO_DT_SPEC_GET_BY_IDX_OR: use default if idx invalid
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit ee250a1)

Original-Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
GitOrigin-RevId: ee250a1
Cr-Build-Id: 8727042214506707905
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8727042214506707905
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: Icbe25dfba647142db3536e9a5a53a6b0d871d75e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6134540
Commit-Queue: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Bot-Commit: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
  • Loading branch information
Henrik Brix Andersen authored and Chromeos LUCI committed Dec 31, 2024
1 parent ab1ad68 commit 15ae680
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/zephyr/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ struct gpio_dt_spec {
* @brief Like GPIO_DT_SPEC_GET_BY_IDX(), with a fallback to a default value
*
* If the devicetree node identifier 'node_id' refers to a node with a
* property 'prop', this expands to
* <tt>GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)</tt>. The @p
* property 'prop', and the index @p idx is valid for that property,
* this expands to <tt>GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)</tt>. The @p
* default_value parameter is not expanded in this case.
*
* Otherwise, this expands to @p default_value.
Expand All @@ -354,7 +354,7 @@ struct gpio_dt_spec {
* or default_value if the node or property do not exist
*/
#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
COND_CODE_1(DT_PROP_HAS_IDX(node_id, prop, idx), \
(GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
(default_value))

Expand Down

0 comments on commit 15ae680

Please sign in to comment.