From 8c756a0a2de17f1535ef885ac7e556e016735eb2 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Thu, 31 Mar 2022 15:54:47 +0300 Subject: device property: Convert device_{dma_supported,get_dma_attr} to fwnode Make the device_dma_supported and device_get_dma_attr functions to use the fwnode ops, and move the implementation to ACPI and OF frameworks. Signed-off-by: Sakari Ailus Acked-by: Rob Herring Reviewed-by: Andy Shevchenko Reviewed-by: Heikki Krogerus Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index c0e94cce9c29..09686e2e903e 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -823,33 +823,16 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count); bool device_dma_supported(struct device *dev) { - const struct fwnode_handle *fwnode = dev_fwnode(dev); - - /* For DT, this is always supported. - * For ACPI, this depends on CCA, which - * is determined by the acpi_dma_supported(). - */ - if (is_of_node(fwnode)) - return true; - - return acpi_dma_supported(to_acpi_device_node(fwnode)); + return fwnode_call_bool_op(dev_fwnode(dev), device_dma_supported); } EXPORT_SYMBOL_GPL(device_dma_supported); enum dev_dma_attr device_get_dma_attr(struct device *dev) { - const struct fwnode_handle *fwnode = dev_fwnode(dev); - enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED; - - if (is_of_node(fwnode)) { - if (of_dma_is_coherent(to_of_node(fwnode))) - attr = DEV_DMA_COHERENT; - else - attr = DEV_DMA_NON_COHERENT; - } else - attr = acpi_get_dma_attr(to_acpi_device_node(fwnode)); + if (!fwnode_has_op(dev_fwnode(dev), device_get_dma_attr)) + return DEV_DMA_NOT_SUPPORTED; - return attr; + return fwnode_call_int_op(dev_fwnode(dev), device_get_dma_attr); } EXPORT_SYMBOL_GPL(device_get_dma_attr); -- cgit v1.2.3 From 68b979d068d3d0dceb14c446f664433d96f20a7e Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Thu, 31 Mar 2022 15:54:49 +0300 Subject: device property: Add iomap to fwnode operations Add iomap() fwnode operation to implement fwnode_iomap() through fwnode operations, moving the code in fwnode_iomap() to OF framework. Note that the IS_ENABLED(CONFIG_OF_ADDRESS) && is_of_node(fwnode) check is needed for Sparc that has its own implementation of of_iomap anyway. Let the pre-compiler to handle that check. Signed-off-by: Sakari Ailus Reviewed-by: Andy Shevchenko Reviewed-by: Heikki Krogerus Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 5 +---- drivers/of/property.c | 10 ++++++++++ include/linux/fwnode.h | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 09686e2e903e..83dd22e7cb81 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -887,10 +887,7 @@ EXPORT_SYMBOL_GPL(device_get_phy_mode); */ void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index) { - if (IS_ENABLED(CONFIG_OF_ADDRESS) && is_of_node(fwnode)) - return of_iomap(to_of_node(fwnode), index); - - return NULL; + return fwnode_call_ptr_op(fwnode, iomap, index); } EXPORT_SYMBOL(fwnode_iomap); diff --git a/drivers/of/property.c b/drivers/of/property.c index 676899566f7c..ac2aa5221069 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1465,6 +1465,15 @@ static int of_link_property(struct device_node *con_np, const char *prop_name) return 0; } +static void __iomem *of_fwnode_iomap(struct fwnode_handle *fwnode, int index) +{ +#ifdef CONFIG_OF_ADDRESS + return of_iomap(to_of_node(fwnode), index); +#else + return NULL; +#endif +} + static int of_fwnode_add_links(struct fwnode_handle *fwnode) { struct property *p; @@ -1502,6 +1511,7 @@ const struct fwnode_operations of_fwnode_ops = { .graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint, .graph_get_port_parent = of_fwnode_graph_get_port_parent, .graph_parse_endpoint = of_fwnode_graph_parse_endpoint, + .iomap = of_fwnode_iomap, .add_links = of_fwnode_add_links, }; EXPORT_SYMBOL_GPL(of_fwnode_ops); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 6f307f21fc65..ebbc3bf03f95 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -148,6 +148,7 @@ struct fwnode_operations { (*graph_get_port_parent)(struct fwnode_handle *fwnode); int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); + void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index); int (*add_links)(struct fwnode_handle *fwnode); }; -- cgit v1.2.3 From 99c63707bafd15bcf97fbd6bef1c92d5bfa01d28 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Thu, 31 Mar 2022 15:54:50 +0300 Subject: device property: Add irq_get to fwnode operation Add irq_get() fwnode operation to implement fwnode_irq_get() through fwnode operations, moving the code in fwnode_irq_get() to OF and ACPI frameworks. Signed-off-by: Sakari Ailus Acked-by: Rob Herring Reviewed-by: Andy Shevchenko Reviewed-by: Heikki Krogerus Signed-off-by: Rafael J. Wysocki --- drivers/acpi/property.c | 14 ++++++++++++++ drivers/base/property.c | 12 +----------- drivers/of/property.c | 7 +++++++ include/linux/fwnode.h | 1 + 4 files changed, 23 insertions(+), 11 deletions(-) (limited to 'drivers/base') diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 9f7ca34b7a95..292364c991a8 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1394,6 +1394,19 @@ static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, return 0; } +static int acpi_fwnode_irq_get(const struct fwnode_handle *fwnode, + unsigned int index) +{ + struct resource res; + int ret; + + ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res); + if (ret) + return ret; + + return res.start; +} + #define DECLARE_ACPI_FWNODE_OPS(ops) \ const struct fwnode_operations ops = { \ .device_is_available = acpi_fwnode_device_is_available, \ @@ -1418,6 +1431,7 @@ static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, acpi_graph_get_remote_endpoint, \ .graph_get_port_parent = acpi_fwnode_get_parent, \ .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \ + .irq_get = acpi_fwnode_irq_get, \ }; \ EXPORT_SYMBOL_GPL(ops) diff --git a/drivers/base/property.c b/drivers/base/property.c index 83dd22e7cb81..3560c4419d11 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -901,17 +901,7 @@ EXPORT_SYMBOL(fwnode_iomap); */ int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index) { - struct resource res; - int ret; - - if (is_of_node(fwnode)) - return of_irq_get(to_of_node(fwnode), index); - - ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res); - if (ret) - return ret; - - return res.start; + return fwnode_call_int_op(fwnode, irq_get, index); } EXPORT_SYMBOL(fwnode_irq_get); diff --git a/drivers/of/property.c b/drivers/of/property.c index ac2aa5221069..9a50ad25906e 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1474,6 +1474,12 @@ static void __iomem *of_fwnode_iomap(struct fwnode_handle *fwnode, int index) #endif } +static int of_fwnode_irq_get(const struct fwnode_handle *fwnode, + unsigned int index) +{ + return of_irq_get(to_of_node(fwnode), index); +} + static int of_fwnode_add_links(struct fwnode_handle *fwnode) { struct property *p; @@ -1512,6 +1518,7 @@ const struct fwnode_operations of_fwnode_ops = { .graph_get_port_parent = of_fwnode_graph_get_port_parent, .graph_parse_endpoint = of_fwnode_graph_parse_endpoint, .iomap = of_fwnode_iomap, + .irq_get = of_fwnode_irq_get, .add_links = of_fwnode_add_links, }; EXPORT_SYMBOL_GPL(of_fwnode_ops); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index ebbc3bf03f95..6ab69871b06d 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -149,6 +149,7 @@ struct fwnode_operations { int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index); + int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index); int (*add_links)(struct fwnode_handle *fwnode); }; -- cgit v1.2.3 From 002752af7b89b74c64fe6bec8c5fde3d3a7810d8 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 8 Apr 2022 21:48:40 +0300 Subject: device property: Allow error pointer to be passed to fwnode APIs Some of the fwnode APIs might return an error pointer instead of NULL or valid fwnode handle. The result of such API call may be considered optional and hence the test for it is usually done in a form of fwnode = fwnode_find_reference(...); if (IS_ERR(fwnode)) ...error handling... Nevertheless the resulting fwnode may have bumped the reference count and hence caller of the above API is obliged to call fwnode_handle_put(). Since fwnode may be not valid either as NULL or error pointer the check has to be performed there. This approach uglifies the code and adds a point of making a mistake, i.e. forgetting about error point case. To prevent this, allow an error pointer to be passed to the fwnode APIs. Fixes: 83b34afb6b79 ("device property: Introduce fwnode_find_reference()") Reported-by: Nuno Sá Tested-by: Nuno Sá Acked-by: Nuno Sá Reviewed-by: Sakari Ailus Reviewed-by: Heikki Krogerus Signed-off-by: Andy Shevchenko Tested-by: Michael Walle Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 89 ++++++++++++++++++++++++++++--------------------- include/linux/fwnode.h | 10 +++--- 2 files changed, 56 insertions(+), 43 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 3560c4419d11..6ecc1398b0ba 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -47,12 +47,14 @@ bool fwnode_property_present(const struct fwnode_handle *fwnode, { bool ret; + if (IS_ERR_OR_NULL(fwnode)) + return false; + ret = fwnode_call_bool_op(fwnode, property_present, propname); - if (ret == false && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_bool_op(fwnode->secondary, property_present, - propname); - return ret; + if (ret) + return ret; + + return fwnode_call_bool_op(fwnode->secondary, property_present, propname); } EXPORT_SYMBOL_GPL(fwnode_property_present); @@ -232,15 +234,16 @@ static int fwnode_property_read_int_array(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -EINVAL; + ret = fwnode_call_int_op(fwnode, property_read_int_array, propname, elem_size, val, nval); - if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op( - fwnode->secondary, property_read_int_array, propname, - elem_size, val, nval); + if (ret != -EINVAL) + return ret; - return ret; + return fwnode_call_int_op(fwnode->secondary, property_read_int_array, propname, + elem_size, val, nval); } /** @@ -371,14 +374,16 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -EINVAL; + ret = fwnode_call_int_op(fwnode, property_read_string_array, propname, val, nval); - if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op(fwnode->secondary, - property_read_string_array, propname, - val, nval); - return ret; + if (ret != -EINVAL) + return ret; + + return fwnode_call_int_op(fwnode->secondary, property_read_string_array, propname, + val, nval); } EXPORT_SYMBOL_GPL(fwnode_property_read_string_array); @@ -480,15 +485,19 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -ENOENT; + ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop, nargs, index, args); + if (ret == 0) + return ret; - if (ret < 0 && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op(fwnode->secondary, get_reference_args, - prop, nargs_prop, nargs, index, args); + if (IS_ERR_OR_NULL(fwnode->secondary)) + return ret; - return ret; + return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop, + nargs, index, args); } EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args); @@ -635,12 +644,13 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, unsigned int depth) { - unsigned int i; - fwnode_handle_get(fwnode); - for (i = 0; i < depth && fwnode; i++) + do { + if (depth-- == 0) + break; fwnode = fwnode_get_next_parent(fwnode); + } while (fwnode); return fwnode; } @@ -659,17 +669,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, struct fwnode_handle *test_child) { - if (!test_ancestor) + if (IS_ERR_OR_NULL(test_ancestor)) return false; fwnode_handle_get(test_child); - while (test_child) { + do { if (test_child == test_ancestor) { fwnode_handle_put(test_child); return true; } test_child = fwnode_get_next_parent(test_child); - } + } while (test_child); return false; } @@ -698,7 +708,7 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode, { struct fwnode_handle *next_child = child; - if (!fwnode) + if (IS_ERR_OR_NULL(fwnode)) return NULL; do { @@ -722,16 +732,16 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev, const struct fwnode_handle *fwnode = dev_fwnode(dev); struct fwnode_handle *next; + if (IS_ERR_OR_NULL(fwnode)) + return NULL; + /* Try to find a child in primary fwnode */ next = fwnode_get_next_child_node(fwnode, child); if (next) return next; /* When no more children in primary, continue with secondary */ - if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) - next = fwnode_get_next_child_node(fwnode->secondary, child); - - return next; + return fwnode_get_next_child_node(fwnode->secondary, child); } EXPORT_SYMBOL_GPL(device_get_next_child_node); @@ -798,6 +808,9 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put); */ bool fwnode_device_is_available(const struct fwnode_handle *fwnode) { + if (IS_ERR_OR_NULL(fwnode)) + return false; + if (!fwnode_has_op(fwnode, device_is_available)) return true; @@ -958,14 +971,14 @@ fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, parent = fwnode_graph_get_port_parent(prev); else parent = fwnode; + if (IS_ERR_OR_NULL(parent)) + return NULL; ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev); + if (ep) + return ep; - if (IS_ERR_OR_NULL(ep) && - !IS_ERR_OR_NULL(parent) && !IS_ERR_OR_NULL(parent->secondary)) - ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL); - - return ep; + return fwnode_graph_get_next_endpoint(parent->secondary, NULL); } EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 6ab69871b06d..9a81c4410b9f 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -153,12 +153,12 @@ struct fwnode_operations { int (*add_links)(struct fwnode_handle *fwnode); }; -#define fwnode_has_op(fwnode, op) \ - ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) +#define fwnode_has_op(fwnode, op) \ + (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op) + #define fwnode_call_int_op(fwnode, op, ...) \ - (fwnode ? (fwnode_has_op(fwnode, op) ? \ - (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ - -EINVAL) + (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO)) #define fwnode_call_bool_op(fwnode, op, ...) \ (fwnode_has_op(fwnode, op) ? \ -- cgit v1.2.3 From 87ffea09470d94c93dd6a5a22d4b2216b395d1ea Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 8 Apr 2022 21:48:41 +0300 Subject: device property: Introduce fwnode_for_each_parent_node() In a few cases the functionality of fwnode_for_each_parent_node() is already in use. Introduce a common helper macro for it. It may be used by others as well in the future. Signed-off-by: Andy Shevchenko Reviewed-by: Sakari Ailus Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 56 +++++++++++++++++++++++++----------------------- include/linux/property.h | 9 ++++++-- 2 files changed, 36 insertions(+), 29 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 6ecc1398b0ba..f0ac31d28798 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -596,17 +596,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent); */ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) { + struct fwnode_handle *parent; struct device *dev; - fwnode_handle_get(fwnode); - do { - fwnode = fwnode_get_next_parent(fwnode); - if (!fwnode) - return NULL; + fwnode_for_each_parent_node(fwnode, parent) { dev = get_dev_from_fwnode(fwnode); - } while (!dev); - fwnode_handle_put(fwnode); - return dev; + if (dev) { + fwnode_handle_put(parent); + return dev; + } + } + return NULL; } /** @@ -617,13 +617,11 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) */ unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode) { - struct fwnode_handle *__fwnode; - unsigned int count; - - __fwnode = fwnode_get_parent(fwnode); + struct fwnode_handle *parent; + unsigned int count = 0; - for (count = 0; __fwnode; count++) - __fwnode = fwnode_get_next_parent(__fwnode); + fwnode_for_each_parent_node(fwnode, parent) + count++; return count; } @@ -644,15 +642,16 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, unsigned int depth) { - fwnode_handle_get(fwnode); + struct fwnode_handle *parent; - do { - if (depth-- == 0) - break; - fwnode = fwnode_get_next_parent(fwnode); - } while (fwnode); + if (depth == 0) + return fwnode_handle_get(fwnode); - return fwnode; + fwnode_for_each_parent_node(fwnode, parent) { + if (--depth == 0) + return parent; + } + return NULL; } EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); @@ -669,17 +668,20 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, struct fwnode_handle *test_child) { + struct fwnode_handle *parent; + if (IS_ERR_OR_NULL(test_ancestor)) return false; - fwnode_handle_get(test_child); - do { - if (test_child == test_ancestor) { - fwnode_handle_put(test_child); + if (test_child == test_ancestor) + return true; + + fwnode_for_each_parent_node(test_child, parent) { + if (parent == test_ancestor) { + fwnode_handle_put(parent); return true; } - test_child = fwnode_get_next_parent(test_child); - } while (test_child); + } return false; } diff --git a/include/linux/property.h b/include/linux/property.h index 4cd4b326941f..15d6863ae962 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -83,9 +83,14 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, const char *fwnode_get_name(const struct fwnode_handle *fwnode); const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); + struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); -struct fwnode_handle *fwnode_get_next_parent( - struct fwnode_handle *fwnode); +struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); + +#define fwnode_for_each_parent_node(fwnode, parent) \ + for (parent = fwnode_get_parent(fwnode); parent; \ + parent = fwnode_get_next_parent(parent)) + struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, -- cgit v1.2.3 From 022fe6bc8f3bd0f2b1f9bc778bacc38020dfd420 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 8 Apr 2022 21:48:42 +0300 Subject: device property: Drop 'test' prefix in parameters of fwnode_is_ancestor_of() The part 'is' in the function name implies the test against something. Drop unnecessary 'test' prefix in the fwnode_is_ancestor_of() parameters. No functional change intended. Signed-off-by: Andy Shevchenko Reviewed-by: Sakari Ailus Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 20 +++++++++----------- include/linux/property.h | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index f0ac31d28798..36401cfe432c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -656,28 +656,26 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); /** - * fwnode_is_ancestor_of - Test if @test_ancestor is ancestor of @test_child - * @test_ancestor: Firmware which is tested for being an ancestor - * @test_child: Firmware which is tested for being the child + * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child + * @ancestor: Firmware which is tested for being an ancestor + * @child: Firmware which is tested for being the child * * A node is considered an ancestor of itself too. * - * Returns true if @test_ancestor is an ancestor of @test_child. - * Otherwise, returns false. + * Returns true if @ancestor is an ancestor of @child. Otherwise, returns false. */ -bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, - struct fwnode_handle *test_child) +bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child) { struct fwnode_handle *parent; - if (IS_ERR_OR_NULL(test_ancestor)) + if (IS_ERR_OR_NULL(ancestor)) return false; - if (test_child == test_ancestor) + if (child == ancestor) return true; - fwnode_for_each_parent_node(test_child, parent) { - if (parent == test_ancestor) { + fwnode_for_each_parent_node(child, parent) { + if (parent == ancestor) { fwnode_handle_put(parent); return true; } diff --git a/include/linux/property.h b/include/linux/property.h index 15d6863ae962..fc24d45632eb 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -95,8 +95,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, unsigned int depth); -bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, - struct fwnode_handle *test_child); +bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_child_node( const struct fwnode_handle *fwnode, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_available_child_node( -- cgit v1.2.3 From 117ef574074d69d87c222dbbbc744bc06cf5a833 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 29 Apr 2022 16:43:47 -0700 Subject: device property: Fix recent breakage of fwnode_get_next_parent_dev() Due to a subtle typo, instead of commit 87ffea09470d ("device property: Introduce fwnode_for_each_parent_node()") being a no-op change, it ended up causing the display on my sc7180-trogdor-lazor device from coming up unless I added "fw_devlink=off" to my kernel command line. Fix the typo. Fixes: 87ffea09470d ("device property: Introduce fwnode_for_each_parent_node()") Signed-off-by: Douglas Anderson Reviewed-by: Saravana Kannan Reviewed-by: Sakari Ailus Reviewed-by: Andy Shevchenko Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 36401cfe432c..52e85dcb20b5 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -600,7 +600,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) struct device *dev; fwnode_for_each_parent_node(fwnode, parent) { - dev = get_dev_from_fwnode(fwnode); + dev = get_dev_from_fwnode(parent); if (dev) { fwnode_handle_put(parent); return dev; -- cgit v1.2.3 From f6e109a0afedec2a9470fec31a567071e2f01e46 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 2 May 2022 12:51:01 +0300 Subject: device property: Advertise fwnode and device property count API calls The documentation of fwnode and device property array API calls isn't pointing out to the shortcuts to count the number of elements of size in an array. Amend the documentation to advertise fwnode and device property count API calls. Reported-by: Sakari Ailus Signed-off-by: Andy Shevchenko Signed-off-by: Rafael J. Wysocki --- drivers/base/property.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/property.c b/drivers/base/property.c index 52e85dcb20b5..3adcac2c78fa 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -68,6 +68,9 @@ EXPORT_SYMBOL_GPL(fwnode_property_present); * Function reads an array of u8 properties with @propname from the device * firmware description and stores them to @val if found. * + * It's recommended to call device_property_count_u8() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -93,6 +96,9 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array); * Function reads an array of u16 properties with @propname from the device * firmware description and stores them to @val if found. * + * It's recommended to call device_property_count_u16() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -118,6 +124,9 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array); * Function reads an array of u32 properties with @propname from the device * firmware description and stores them to @val if found. * + * It's recommended to call device_property_count_u32() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -143,6 +152,9 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array); * Function reads an array of u64 properties with @propname from the device * firmware description and stores them to @val if found. * + * It's recommended to call device_property_count_u64() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -168,6 +180,9 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array); * Function reads an array of string properties with @propname from the device * firmware description and stores them to @val if found. * + * It's recommended to call device_property_string_array_count() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values read on success if @val is non-NULL, * number of values available on success if @val is NULL, * %-EINVAL if given arguments are not valid, @@ -256,6 +271,9 @@ static int fwnode_property_read_int_array(const struct fwnode_handle *fwnode, * Read an array of u8 properties with @propname from @fwnode and stores them to * @val if found. * + * It's recommended to call fwnode_property_count_u8() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -282,6 +300,9 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array); * Read an array of u16 properties with @propname from @fwnode and store them to * @val if found. * + * It's recommended to call fwnode_property_count_u16() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -308,6 +329,9 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array); * Read an array of u32 properties with @propname from @fwnode store them to * @val if found. * + * It's recommended to call fwnode_property_count_u32() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -334,6 +358,9 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array); * Read an array of u64 properties with @propname from @fwnode and store them to * @val if found. * + * It's recommended to call fwnode_property_count_u64() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values if @val was %NULL, * %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -360,6 +387,9 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array); * Read an string list property @propname from the given firmware node and store * them to @val if found. * + * It's recommended to call fwnode_property_string_array_count() instead of calling + * this function with @val equals %NULL and @nval equals 0. + * * Return: number of values read on success if @val is non-NULL, * number of values available on success if @val is NULL, * %-EINVAL if given arguments are not valid, -- cgit v1.2.3