Commit 7b58696d authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bartosz Golaszewski

gpiolib: Extract gpiod_not_found() helper

Several places in the code are using same idiom, i.e.
	IS_ERR(desc) && PTR_ERR(desc) == -ENOENT
which meaning is GPIO description is not found.

For better readability extract gpiod_not_found() helper and use it.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent 3650b228
...@@ -246,10 +246,8 @@ struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, ...@@ -246,10 +246,8 @@ struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
struct gpio_desc *desc; struct gpio_desc *desc;
desc = devm_gpiod_get_index(dev, con_id, index, flags); desc = devm_gpiod_get_index(dev, con_id, index, flags);
if (IS_ERR(desc)) { if (gpiod_not_found(desc))
if (PTR_ERR(desc) == -ENOENT)
return NULL; return NULL;
}
return desc; return desc;
} }
...@@ -308,7 +306,7 @@ devm_gpiod_get_array_optional(struct device *dev, const char *con_id, ...@@ -308,7 +306,7 @@ devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
struct gpio_descs *descs; struct gpio_descs *descs;
descs = devm_gpiod_get_array(dev, con_id, flags); descs = devm_gpiod_get_array(dev, con_id, flags);
if (PTR_ERR(descs) == -ENOENT) if (gpiod_not_found(descs))
return NULL; return NULL;
return descs; return descs;
......
...@@ -509,31 +509,31 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -509,31 +509,31 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
&of_flags); &of_flags);
if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT) if (!gpiod_not_found(desc))
break; break;
} }
if (PTR_ERR(desc) == -ENOENT) { if (gpiod_not_found(desc)) {
/* Special handling for SPI GPIOs if used */ /* Special handling for SPI GPIOs if used */
desc = of_find_spi_gpio(dev, con_id, &of_flags); desc = of_find_spi_gpio(dev, con_id, &of_flags);
} }
if (PTR_ERR(desc) == -ENOENT) { if (gpiod_not_found(desc)) {
/* This quirk looks up flags and all */ /* This quirk looks up flags and all */
desc = of_find_spi_cs_gpio(dev, con_id, idx, flags); desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
if (!IS_ERR(desc)) if (!IS_ERR(desc))
return desc; return desc;
} }
if (PTR_ERR(desc) == -ENOENT) { if (gpiod_not_found(desc)) {
/* Special handling for regulator GPIOs if used */ /* Special handling for regulator GPIOs if used */
desc = of_find_regulator_gpio(dev, con_id, &of_flags); desc = of_find_regulator_gpio(dev, con_id, &of_flags);
} }
if (PTR_ERR(desc) == -ENOENT) if (gpiod_not_found(desc))
desc = of_find_arizona_gpio(dev, con_id, &of_flags); desc = of_find_arizona_gpio(dev, con_id, &of_flags);
if (PTR_ERR(desc) == -ENOENT) if (gpiod_not_found(desc))
desc = of_find_usb_gpio(dev, con_id, &of_flags); desc = of_find_usb_gpio(dev, con_id, &of_flags);
if (IS_ERR(desc)) if (IS_ERR(desc))
......
...@@ -3767,7 +3767,7 @@ struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, ...@@ -3767,7 +3767,7 @@ struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags, desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags,
label); label);
if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) if (!gpiod_not_found(desc))
break; break;
} }
...@@ -3943,7 +3943,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, ...@@ -3943,7 +3943,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
* Either we are not using DT or ACPI, or their lookup did not return * Either we are not using DT or ACPI, or their lookup did not return
* a result. In that case, use platform lookup as a fallback. * a result. In that case, use platform lookup as a fallback.
*/ */
if (!desc || desc == ERR_PTR(-ENOENT)) { if (!desc || gpiod_not_found(desc)) {
dev_dbg(dev, "using lookup tables for GPIO lookup\n"); dev_dbg(dev, "using lookup tables for GPIO lookup\n");
desc = gpiod_find(dev, con_id, idx, &lookupflags); desc = gpiod_find(dev, con_id, idx, &lookupflags);
} }
...@@ -4078,10 +4078,8 @@ struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, ...@@ -4078,10 +4078,8 @@ struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
struct gpio_desc *desc; struct gpio_desc *desc;
desc = gpiod_get_index(dev, con_id, index, flags); desc = gpiod_get_index(dev, con_id, index, flags);
if (IS_ERR(desc)) { if (gpiod_not_found(desc))
if (PTR_ERR(desc) == -ENOENT)
return NULL; return NULL;
}
return desc; return desc;
} }
...@@ -4283,7 +4281,7 @@ struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, ...@@ -4283,7 +4281,7 @@ struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
struct gpio_descs *descs; struct gpio_descs *descs;
descs = gpiod_get_array(dev, con_id, flags); descs = gpiod_get_array(dev, con_id, flags);
if (PTR_ERR(descs) == -ENOENT) if (gpiod_not_found(descs))
return NULL; return NULL;
return descs; return descs;
......
...@@ -130,6 +130,8 @@ struct gpio_desc { ...@@ -130,6 +130,8 @@ struct gpio_desc {
#endif #endif
}; };
#define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
int gpiod_request(struct gpio_desc *desc, const char *label); int gpiod_request(struct gpio_desc *desc, const char *label);
void gpiod_free(struct gpio_desc *desc); void gpiod_free(struct gpio_desc *desc);
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment