* Re: [PATCH 5/6] OF: Utility helper functions for dynamic nodes [not found] ` <1403430039-15085-6-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> @ 2014-06-23 16:26 ` Alexander Sverdlin [not found] ` <6E91A461-4361-4A18-BE32-CECDD789C114@konsulko.com> 0 siblings, 1 reply; 6+ messages in thread From: Alexander Sverdlin @ 2014-06-23 16:26 UTC (permalink / raw) To: ext Pantelis Antoniou, Grant Likely, Ionut Nicu Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Michal Simek, Matt Ranostay, Joel Becker, devicetree-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete Popov, Dan Malek <dan.male Hello Pantelis! On 22/06/14 11:40, ext Pantelis Antoniou wrote: > Introduce helper functions for working with the live DT tree, > all of them related to dynamically adding/removing nodes and > properties. > > __of_copy_property() copies a property dynamically > __of_create_empty_node() creates an empty node > > Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext-OYasijW0DpE@public.gmane.org> Are you sure about this? (see below...) > Signed-off-by: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> > --- > drivers/of/Makefile | 2 +- > drivers/of/util.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/of.h | 42 ++++++++++++++++ > 3 files changed, 184 insertions(+), 1 deletion(-) > create mode 100644 drivers/of/util.c > > diff --git a/drivers/of/Makefile b/drivers/of/Makefile > index 099b1fb..734d3e2 100644 > --- a/drivers/of/Makefile > +++ b/drivers/of/Makefile > @@ -1,4 +1,4 @@ > -obj-y = base.o device.o platform.o > +obj-y = base.o device.o platform.o util.o > obj-$(CONFIG_OF_FLATTREE) += fdt.o > obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o > obj-$(CONFIG_OF_PROMTREE) += pdt.o > diff --git a/drivers/of/util.c b/drivers/of/util.c > new file mode 100644 > index 0000000..f4211f8 > --- /dev/null > +++ b/drivers/of/util.c > @@ -0,0 +1,141 @@ > +/* > + * Utility functions for working with device tree(s) > + * > + * Copyright (C) 2012 Pantelis Antoniou <panto-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org> > + * Copyright (C) 2012 Texas Instruments Inc. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * version 2 as published by the Free Software Foundation. > + */ > + > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/of.h> > +#include <linux/of_device.h> > +#include <linux/string.h> > +#include <linux/ctype.h> > +#include <linux/errno.h> > +#include <linux/string.h> > +#include <linux/slab.h> > +#include <linux/err.h> > + > +/** > + * __of_copy_property - Copy a property dynamically. > + * @prop: Property to copy > + * @allocflags: Allocation flags (typically pass GFP_KERNEL) > + * @propflags: Property flags > + * > + * Copy a property by dynamically allocating the memory of both the > + * property stucture and the property name & contents. The property's > + * flags have the OF_DYNAMIC bit set so that we can differentiate between > + * dynamically allocated properties and not. > + * Returns the newly allocated property or NULL on out of memory error. > + */ > +struct property *__of_copy_property(const struct property *prop, > + gfp_t allocflags, unsigned long propflags) > +{ > + struct property *propn; > + > + propn = kzalloc(sizeof(*prop), allocflags); > + if (propn == NULL) > + return NULL; > + > + propn->_flags = propflags; > + > + if (of_property_check_flag(propn, OF_ALLOCNAME)) { > + propn->name = kstrdup(prop->name, allocflags); > + if (propn->name == NULL) > + goto err_fail_name; > + } else > + propn->name = prop->name; > + > + if (prop->length > 0) { ^^^^^^^^^^^^^^^^^^^^^ Seems, that length==0 case will still produce value==NULL results, which will brake some checks in the kernel... Or am I missing something in the new version? > + if (of_property_check_flag(propn, OF_ALLOCVALUE)) { > + propn->value = kmalloc(prop->length, allocflags); > + if (propn->value == NULL) > + goto err_fail_value; > + memcpy(propn->value, prop->value, prop->length); > + } else > + propn->value = prop->value; > + > + propn->length = prop->length; > + } > + > + /* mark the property as dynamic */ > + of_property_set_flag(propn, OF_DYNAMIC); > + > + return propn; > + > +err_fail_value: > + if (of_property_check_flag(propn, OF_ALLOCNAME)) > + kfree(propn->name); > +err_fail_name: > + kfree(propn); > + return NULL; > +} > + > +/** > + * __of_create_empty_node - Create an empty device node dynamically. > + * @name: Name of the new device node > + * @type: Type of the new device node > + * @full_name: Full name of the new device node > + * @phandle: Phandle of the new device node > + * @allocflags: Allocation flags (typically pass GFP_KERNEL) > + * @nodeflags: Node flags > + * > + * Create an empty device tree node, suitable for further modification. > + * The node data are dynamically allocated and all the node flags > + * have the OF_DYNAMIC & OF_DETACHED bits set. > + * Returns the newly allocated node or NULL on out of memory error. > + */ > +struct device_node *__of_create_empty_node( > + const char *name, const char *type, const char *full_name, > + phandle phandle, gfp_t allocflags, unsigned long nodeflags) > +{ > + struct device_node *node; > + > + node = kzalloc(sizeof(*node), allocflags); > + if (node == NULL) > + return NULL; > + > + node->_flags = nodeflags; > + > + if (of_node_check_flag(node, OF_ALLOCNAME)) { > + node->name = kstrdup(name, allocflags); > + if (node->name == NULL) > + goto err_free_node; > + } else > + node->name = name; > + > + if (of_node_check_flag(node, OF_ALLOCTYPE)) { > + node->type = kstrdup(type, allocflags); > + if (node->type == NULL) > + goto err_free_name; > + } else > + node->type = type; > + > + if (of_node_check_flag(node, OF_ALLOCFULL)) { > + node->full_name = kstrdup(full_name, allocflags); > + if (node->full_name == NULL) > + goto err_free_type; > + } else > + node->full_name = full_name; > + > + node->phandle = phandle; > + of_node_set_flag(node, OF_DYNAMIC); > + of_node_set_flag(node, OF_DETACHED); > + > + of_node_init(node); > + > + return node; > +err_free_type: > + if (of_node_check_flag(node, OF_ALLOCTYPE)) > + kfree(node->type); > +err_free_name: > + if (of_node_check_flag(node, OF_ALLOCNAME)) > + kfree(node->name); > +err_free_node: > + kfree(node); > + return NULL; > +} > diff --git a/include/linux/of.h b/include/linux/of.h > index 5e4e1b3..d381eb5 100644 > --- a/include/linux/of.h > +++ b/include/linux/of.h > @@ -211,6 +211,15 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) > #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ > #define OF_DETACHED 2 /* node has been detached from the device tree */ > #define OF_POPULATED 3 /* device already created for the node */ > +#define OF_ALLOCNAME 4 /* name was kmalloc-ed */ > +#define OF_ALLOCTYPE 5 /* type was kmalloc-ed */ > +#define OF_ALLOCFULL 6 /* full_name was kmalloc-ed */ > +#define OF_ALLOCVALUE 7 /* value was kmalloc-ed */ > + > +#define OF_NODE_ALLOCALL \ > + ((1 << OF_ALLOCNAME) | (1 << OF_ALLOCTYPE) | (1 << OF_ALLOCFULL)) > +#define OF_PROP_ALLOCALL \ > + ((1 << OF_ALLOCNAME) | (1 << OF_ALLOCVALUE)) > > #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) > #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) > @@ -824,4 +833,37 @@ typedef void (*of_init_fn_1)(struct device_node *); > #define OF_DECLARE_2(table, name, compat, fn) \ > _OF_DECLARE(table, name, compat, fn, of_init_fn_2) > > +/** > + * General utilities for working with live trees. > + * > + * All functions with two leading underscores operate > + * without taking node references, so you either have to > + * own the devtree lock or work on detached trees only. > + */ > + > +#ifdef CONFIG_OF > + > +struct property *__of_copy_property(const struct property *prop, > + gfp_t allocflags, unsigned long propflags); > +struct device_node *__of_create_empty_node(const char *name, > + const char *type, const char *full_name, > + phandle phandle, gfp_t allocflags, unsigned long nodeflags); > + > +#else /* !CONFIG_OF */ > + > +static inline struct property *__of_copy_property(const struct property *prop, > + gfp_t allocflags, unsigned long propflags) > +{ > + return NULL; > +} > + > +static inline struct device_node *__of_create_empty_node(const char *name, > + const char *type, const char *full_name, > + phandle phandle, gfp_t allocflags, unsigned long nodeflags) > +{ > + return NULL; > +} > + > +#endif /* !CONFIG_OF */ > + > #endif /* _LINUX_OF_H */ > -- Best regards, Alexander Sverdlin. -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <6E91A461-4361-4A18-BE32-CECDD789C114@konsulko.com>]
[parent not found: <20140623183343.GA10389@heimdall>]
* Re: [PATCH 5/6] OF: Utility helper functions for dynamic nodes [not found] ` <20140623183343.GA10389@heimdall> @ 2014-06-24 8:10 ` Alexander Sverdlin 2014-06-25 9:09 ` Grant Likely [not found] ` <78ACBAF6-A73E-4272-8D3A-258C4B10858C@konsulko.com> 1 sibling, 1 reply; 6+ messages in thread From: Alexander Sverdlin @ 2014-06-24 8:10 UTC (permalink / raw) To: Ioan Nicu, ext Pantelis Antoniou, Grant Likely Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Michal Simek, Matt Ranostay, Joel Becker, devicetree-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete Popov, Dan Malek <dan.male Hi Pantelis, Grant, On 23/06/14 20:33, Ioan Nicu wrote: >>> On 22/06/14 11:40, ext Pantelis Antoniou wrote: >>>> Introduce helper functions for working with the live DT tree, >>>> all of them related to dynamically adding/removing nodes and >>>> properties. >>>> >>>> __of_copy_property() copies a property dynamically >>>> __of_create_empty_node() creates an empty node >>>> >>>> Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext-OYasijW0DpE@public.gmane.org> >>> >>> Are you sure about this? (see below...) >>> > > Alexander is right, my fix was lost even though it's mentioned in this patch. > >>>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> >>>> --- >> >> [snip] >>>> + >>>> + if (prop->length > 0) { >>> ^^^^^^^^^^^^^^^^^^^^^ >>> Seems, that length==0 case will still produce value==NULL results, >>> which will brake some checks in the kernel... Or am I missing something in >>> the new version? >>> >> >> prop->value will be set to NULL, and length will be set to zero (kzalloc). >> This is a normal zero length property. >> >> I don't know of any place in the kernel accessing the value if prop->length==0 >> > > We have a simple use case. We have an overlay which adds an interrupt controller. > If you look in drivers/of/irq.c, in of_irq_parse_raw(): > > [...] > /* Now start the actual "proper" walk of the interrupt tree */ > while (ipar != NULL) { > /* Now check if cursor is an interrupt-controller and if it is > * then we are done > */ > if (of_get_property(ipar, "interrupt-controller", NULL) != We have to define, if it's allowed for an empty property to have NULL value. Several places in the kernel use of_get_property() to check for property existence. We either have to make a tree-wide patch and replace of_get_property() with of_find_property() in those cases, or ensure value != NULL in this copy function... Grant, what do you think? > NULL) { > pr_debug(" -> got it !\n"); > return 0; > } > [...] > > A node is identified as an interrupt controller if it has a zero-length property > called "interrupt-controller" but with a non-NULL value. > > My proposed fix for this was to remove the if () condition. propn->value will be > allocated with kmalloc(0) which returns ZERO_SIZE_PTR which is != NULL. > > >> >> [snip] >> >>>> + >>>> #endif /* _LINUX_OF_H */ >>>> >>> >>> -- >>> Best regards, >>> Alexander Sverdlin. >> >> Regards >> >> -- Pantelis >> > > Regards, > Ionut Nicu > -- Best regards, Alexander Sverdlin. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/6] OF: Utility helper functions for dynamic nodes 2014-06-24 8:10 ` Alexander Sverdlin @ 2014-06-25 9:09 ` Grant Likely 0 siblings, 0 replies; 6+ messages in thread From: Grant Likely @ 2014-06-25 9:09 UTC (permalink / raw) To: Alexander Sverdlin, Ioan Nicu, ext Pantelis Antoniou Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Michal Simek, Matt Ranostay, Joel Becker, devicetree, Wolfram Sang, linux-i2c, Mark Brown, linux-spi, linux-kernel, Pete Popov, Dan Malek <dan.male On Tue, 24 Jun 2014 10:10:01 +0200, Alexander Sverdlin <alexander.sverdlin@nsn.com> wrote: > Hi Pantelis, Grant, > > On 23/06/14 20:33, Ioan Nicu wrote: > >>> On 22/06/14 11:40, ext Pantelis Antoniou wrote: > >>>> Introduce helper functions for working with the live DT tree, > >>>> all of them related to dynamically adding/removing nodes and > >>>> properties. > >>>> > >>>> __of_copy_property() copies a property dynamically > >>>> __of_create_empty_node() creates an empty node > >>>> > >>>> Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext@nsn.com> > >>> > >>> Are you sure about this? (see below...) > >>> > > > > Alexander is right, my fix was lost even though it's mentioned in this patch. > > > >>>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> > >>>> --- > >> > >> [snip] > >>>> + > >>>> + if (prop->length > 0) { > >>> ^^^^^^^^^^^^^^^^^^^^^ > >>> Seems, that length==0 case will still produce value==NULL results, > >>> which will brake some checks in the kernel... Or am I missing something in > >>> the new version? > >>> > >> > >> prop->value will be set to NULL, and length will be set to zero (kzalloc). > >> This is a normal zero length property. > >> > >> I don't know of any place in the kernel accessing the value if prop->length==0 > >> > > > > We have a simple use case. We have an overlay which adds an interrupt controller. > > If you look in drivers/of/irq.c, in of_irq_parse_raw(): > > > > [...] > > /* Now start the actual "proper" walk of the interrupt tree */ > > while (ipar != NULL) { > > /* Now check if cursor is an interrupt-controller and if it is > > * then we are done > > */ > > if (of_get_property(ipar, "interrupt-controller", NULL) != > > We have to define, if it's allowed for an empty property to have NULL value. > Several places in the kernel use of_get_property() to check for property existence. > We either have to make a tree-wide patch and replace of_get_property() with of_find_property() in those cases, > or ensure value != NULL in this copy function... > > Grant, what do you think? I think it's a good cleanup, but until it happens, any new code needs to match the behaviour of fdt.c. In that case, making the value point to an empty string is a sane choice. If you do the legwork of finding callers and fixing them up, then I'll apply it. Once done we can make the following change to fdt.c: - pp->value = (__be32 *)p; + pp->value = sz ? (__be32 *)p : 0; pdt.c similarly needs to be updated. I'm not overly worried though. That code has been in place for a very long time, so there is no rush. It can exist a while longer. g. ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <78ACBAF6-A73E-4272-8D3A-258C4B10858C@konsulko.com>]
[parent not found: <78ACBAF6-A73E-4272-8D3A-258C4B10858C-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>]
* Re: [PATCH 5/6] OF: Utility helper functions for dynamic nodes [not found] ` <78ACBAF6-A73E-4272-8D3A-258C4B10858C-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> @ 2014-06-23 19:48 ` Guenter Roeck 2014-06-24 8:12 ` Alexander Sverdlin 1 sibling, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2014-06-23 19:48 UTC (permalink / raw) To: Pantelis Antoniou, Ioan Nicu Cc: Alexander Sverdlin, Grant Likely, Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Michael Stickel, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Michal Simek, Matt Ranostay, Joel Becker, devicetree-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pe On 06/23/2014 12:13 PM, Pantelis Antoniou wrote: > Hi Ioan, > > I'm going to let Grant answer that but the code in question doesn't look right. > > On Jun 23, 2014, at 9:33 PM, Ioan Nicu wrote: > >> Hi Pantelis, >> >> On Mon, Jun 23, 2014 at 07:57:24PM +0300, ext Pantelis Antoniou wrote: >>> Hi Alexander, >>> >>> On Jun 23, 2014, at 7:26 PM, Alexander Sverdlin wrote: >>> >>>> Hello Pantelis! >>>> >>>> On 22/06/14 11:40, ext Pantelis Antoniou wrote: >>>>> Introduce helper functions for working with the live DT tree, >>>>> all of them related to dynamically adding/removing nodes and >>>>> properties. >>>>> >>>>> __of_copy_property() copies a property dynamically >>>>> __of_create_empty_node() creates an empty node >>>>> >>>>> Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext-OYasijW0DpE@public.gmane.org> >>>> >>>> Are you sure about this? (see below...) >>>> >> >> Alexander is right, my fix was lost even though it's mentioned in this patch. >> > > I'm sorry, I didn't understand that the intention of the fix was to address > the issue below. > >>>>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> >>>>> --- >>> >>> [snip] >>>>> + >>>>> + if (prop->length > 0) { >>>> ^^^^^^^^^^^^^^^^^^^^^ >>>> Seems, that length==0 case will still produce value==NULL results, >>>> which will brake some checks in the kernel... Or am I missing something in >>>> the new version? >>>> >>> >>> prop->value will be set to NULL, and length will be set to zero (kzalloc). >>> This is a normal zero length property. >>> >>> I don't know of any place in the kernel accessing the value if prop->length==0 >>> >> >> We have a simple use case. We have an overlay which adds an interrupt controller. >> If you look in drivers/of/irq.c, in of_irq_parse_raw(): >> >> [...] >> /* Now start the actual "proper" walk of the interrupt tree */ >> while (ipar != NULL) { >> /* Now check if cursor is an interrupt-controller and if it is >> * then we are done >> */ >> if (of_get_property(ipar, "interrupt-controller", NULL) != >> NULL) { >> pr_debug(" -> got it !\n"); >> return 0; >> } >> [...] >> >> A node is identified as an interrupt controller if it has a zero-length property >> called "interrupt-controller" but with a non-NULL value. >> >> My proposed fix for this was to remove the if () condition. propn->value will be >> allocated with kmalloc(0) which returns ZERO_SIZE_PTR which is != NULL. >> > > If that's the case, the code in irq.c is wrong. > > interrupt-controller is a bool property; the correct call to use is of_property_read_bool() > which returns true or false when the value is defined. > > The use of of_get_property is a bug here. It is perfectly valid for a property to have a > NULL value when length = 0. > That usage is spread throughout the code though. There are three or four similar checks for interrupt-controller in the code, and many others using of_get_property() to check for booleans. Some examples: s5m8767,pmic-buck2-ramp-enable s5m8767,pmic-buck3-ramp-enable s5m8767,pmic-buck4-ramp-enable d7s-flipped? atmel,use-dma-rx linux,rs485-enabled-at-boot-time marvell,enable-port1 (and many others) linux,bootx-noscreen linux,opened and many many others. Maybe people meant to use of_find_property() ? Either case, if the new code depends on proper use of of_get_property(), we may have a problem unless all those bad use cases are fixed. Guenter -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/6] OF: Utility helper functions for dynamic nodes [not found] ` <78ACBAF6-A73E-4272-8D3A-258C4B10858C-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> 2014-06-23 19:48 ` Guenter Roeck @ 2014-06-24 8:12 ` Alexander Sverdlin 1 sibling, 0 replies; 6+ messages in thread From: Alexander Sverdlin @ 2014-06-24 8:12 UTC (permalink / raw) To: ext Pantelis Antoniou, Ioan Nicu Cc: Grant Likely, Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Michal Simek, Matt Ranostay, Joel Becker, devicetree-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete Popov <pet Hi! On 23/06/14 21:13, ext Pantelis Antoniou wrote: [...] >>> I don't know of any place in the kernel accessing the value if prop->length==0 >>> >> >> We have a simple use case. We have an overlay which adds an interrupt controller. >> If you look in drivers/of/irq.c, in of_irq_parse_raw(): >> >> [...] >> /* Now start the actual "proper" walk of the interrupt tree */ >> while (ipar != NULL) { >> /* Now check if cursor is an interrupt-controller and if it is >> * then we are done >> */ >> if (of_get_property(ipar, "interrupt-controller", NULL) != >> NULL) { >> pr_debug(" -> got it !\n"); >> return 0; >> } >> [...] >> >> A node is identified as an interrupt controller if it has a zero-length property >> called "interrupt-controller" but with a non-NULL value. >> >> My proposed fix for this was to remove the if () condition. propn->value will be >> allocated with kmalloc(0) which returns ZERO_SIZE_PTR which is != NULL. >> > > If that's the case, the code in irq.c is wrong. > > interrupt-controller is a bool property; the correct call to use is of_property_read_bool() > which returns true or false when the value is defined. No, it's not bool... It's an existence of a void property. > The use of of_get_property is a bug here. It is perfectly valid for a property to have a > NULL value when length = 0. of_find_property() would be really correct in this particular case... -- Best regards, Alexander Sverdlin. -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <1403430039-15085-3-git-send-email-pantelis.antoniou@konsulko.com>]
[parent not found: <53A86ADA.9000903@roeck-us.net>]
[parent not found: <4F4A55EC-744B-49CC-96FA-811C9483A43D@konsulko.com>]
[parent not found: <4F4A55EC-744B-49CC-96FA-811C9483A43D-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>]
* Re: [PATCH 2/6] OF: Add [__]of_find_node_by_full_name [not found] ` <4F4A55EC-744B-49CC-96FA-811C9483A43D-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> @ 2014-06-24 13:55 ` Grant Likely 0 siblings, 0 replies; 6+ messages in thread From: Grant Likely @ 2014-06-24 13:55 UTC (permalink / raw) To: Pantelis Antoniou, Guenter Roeck Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi, Greg Kroah-Hartman, Alison Chaiken, Dinh Nguyen, Jan Lubbe, Alexander Sverdlin, Michael Stickel, Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Ionut Nicu, Michal Simek, Matt Ranostay, Joel Becker, devicetree-u79uwXL29TY76Z2rM5mHXA, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete On Mon, 23 Jun 2014 21:00:39 +0300, Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> wrote: > Hi Guenter, > > On Jun 23, 2014, at 8:58 PM, Guenter Roeck wrote: > > > On 06/22/2014 02:40 AM, Pantelis Antoniou wrote: > >> __of_find_node_by_full_name recursively searches for a matching node > >> with the given full name without taking any locks. > >> > >> of_find_node_by_full_name takes locks and takes a reference on the > >> matching node. > >> > >> Signed-off-by: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> > >> --- > >> drivers/of/base.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > >> include/linux/of.h | 4 ++++ > >> 2 files changed, 62 insertions(+) > >> > >> diff --git a/drivers/of/base.c b/drivers/of/base.c > >> index d3493e1..80fef33 100644 > >> --- a/drivers/of/base.c > >> +++ b/drivers/of/base.c > >> @@ -1201,6 +1201,64 @@ static void *of_find_property_value_of_size(const struct device_node *np, > >> } > >> > >> /** > >> + * __of_find_node_by_full_name - Find a node with the full name recursively > >> + * @node: Root of the tree to perform the search > >> + * @full_name: Full name of the node to find. > >> + * > >> + * Find a node with the give full name by recursively following any of > >> + * the child node links. > >> + * Returns the matching node, or NULL if not found. > >> + * Note that the devtree lock is not taken, so this function is only > >> + * safe to call on either detached trees, or when devtree lock is already > >> + * taken. > >> + */ > >> +struct device_node *__of_find_node_by_full_name(struct device_node *node, > >> + const char *full_name) > >> +{ > >> + struct device_node *child, *found; > >> + > >> + if (node == NULL) > >> + return NULL; > >> + > >> + /* check */ > >> + if (of_node_cmp(node->full_name, full_name) == 0) > >> + return node; > >> + > >> + __for_each_child_of_node(node, child) { > >> + found = __of_find_node_by_full_name(child, full_name); > >> + if (found != NULL) > >> + return found; > >> + } > >> + > >> + return NULL; > >> +} > >> +EXPORT_SYMBOL(__of_find_node_by_full_name); > >> + > >> +/** > >> + * of_find_node_by_full_name - Find a node with the full name recursively > >> + * @node: Root of the tree to perform the search > >> + * @full_name: Full name of the node to find. > >> + * > >> + * Find a node with the give full name by recursively following any of > >> + * the child node links. > >> + * Returns the matching node (with a ref taken), or NULL if not found. > >> + */ > >> +struct device_node *of_find_node_by_full_name(struct device_node *node, > >> + const char *full_name) > >> +{ > >> + unsigned long flags; > >> + struct device_node *np; > >> + > >> + raw_spin_lock_irqsave(&devtree_lock, flags); > >> + np = of_find_node_by_full_name(node, full_name); > > > > Should this be __of_find_node_by_full_name, or am I missing something ? > > > > Ugh, you're not missing something. This slipped through since this is not > used in the current code Then perhaps the function shouldn't exist at all. g. -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-25 9:09 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <1403430039-15085-1-git-send-email-pantelis.antoniou@konsulko.com> [not found] ` <1403430039-15085-6-git-send-email-pantelis.antoniou@konsulko.com> [not found] ` <1403430039-15085-6-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> 2014-06-23 16:26 ` [PATCH 5/6] OF: Utility helper functions for dynamic nodes Alexander Sverdlin [not found] ` <6E91A461-4361-4A18-BE32-CECDD789C114@konsulko.com> [not found] ` <20140623183343.GA10389@heimdall> 2014-06-24 8:10 ` Alexander Sverdlin 2014-06-25 9:09 ` Grant Likely [not found] ` <78ACBAF6-A73E-4272-8D3A-258C4B10858C@konsulko.com> [not found] ` <78ACBAF6-A73E-4272-8D3A-258C4B10858C-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> 2014-06-23 19:48 ` Guenter Roeck 2014-06-24 8:12 ` Alexander Sverdlin [not found] ` <1403430039-15085-3-git-send-email-pantelis.antoniou@konsulko.com> [not found] ` <53A86ADA.9000903@roeck-us.net> [not found] ` <4F4A55EC-744B-49CC-96FA-811C9483A43D@konsulko.com> [not found] ` <4F4A55EC-744B-49CC-96FA-811C9483A43D-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> 2014-06-24 13:55 ` [PATCH 2/6] OF: Add [__]of_find_node_by_full_name Grant Likely
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).