Message ID | 1474008303-20365-2-git-send-email-oohall@gmail.com |
---|---|
State | RFC |
Headers | show |
On 09/16/2016 12:14 PM, Oliver O'Halloran wrote: > This is similar to dt_new(), but if the node already exists it will > return the existing node. This is useful because some init code depends > on the presence of certain nodes, but where the node is actually created > is unimportant. > > Signed-off-by: Oliver O'Halloran <oohall@gmail.com> > --- > core/device.c | 14 ++++++++++++++ > include/device.h | 1 + > 2 files changed, 15 insertions(+) > > diff --git a/core/device.c b/core/device.c > index 9e7ef0d448d9..bd0674e31fda 100644 > --- a/core/device.c > +++ b/core/device.c > @@ -352,6 +352,20 @@ struct dt_node *dt_find_by_name(struct dt_node *root, const char *name) > return NULL; > } > > + > +struct dt_node *dt_new_check(struct dt_node *parent, const char *name) Patch itself looks good. Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> May be its better to rename function as dt_new_get() ? Also it doesn't takes care of handling node creation with address etc.. which is probably fine for now ..as we have issues with node name without address (like ibm,opal). -Vasant
On Fri, Sep 16, 2016 at 6:41 PM, Vasant Hegde <hegdevasant@linux.vnet.ibm.com> wrote: > On 09/16/2016 12:14 PM, Oliver O'Halloran wrote: >> >> This is similar to dt_new(), but if the node already exists it will >> return the existing node. This is useful because some init code depends >> on the presence of certain nodes, but where the node is actually created >> is unimportant. >> >> Signed-off-by: Oliver O'Halloran <oohall@gmail.com> >> --- >> core/device.c | 14 ++++++++++++++ >> include/device.h | 1 + >> 2 files changed, 15 insertions(+) >> >> diff --git a/core/device.c b/core/device.c >> index 9e7ef0d448d9..bd0674e31fda 100644 >> --- a/core/device.c >> +++ b/core/device.c >> @@ -352,6 +352,20 @@ struct dt_node *dt_find_by_name(struct dt_node *root, >> const char *name) >> return NULL; >> } >> >> + >> +struct dt_node *dt_new_check(struct dt_node *parent, const char *name) > > > Patch itself looks good. > > Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> > > May be its better to rename function as dt_new_get() ? I'd like to avoid using *_get and *_put considering how they are used in Linux. I know dt_new_check() isn't a great name, but it seemed like the least bad option. > > Also it doesn't takes care of handling node creation with address etc.. > which is probably fine for now ..as we have issues with node name without > address (like ibm,opal). Add it when we need it IMO. > > > -Vasant >
diff --git a/core/device.c b/core/device.c index 9e7ef0d448d9..bd0674e31fda 100644 --- a/core/device.c +++ b/core/device.c @@ -352,6 +352,20 @@ struct dt_node *dt_find_by_name(struct dt_node *root, const char *name) return NULL; } + +struct dt_node *dt_new_check(struct dt_node *parent, const char *name) +{ + struct dt_node *node = dt_find_by_name(parent, name); + + if (!node) { + node = dt_new(parent, name); + assert(node); + } + + return node; +} + + struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle) { struct dt_node *node; diff --git a/include/device.h b/include/device.h index ed4fc460598f..47ec95b92528 100644 --- a/include/device.h +++ b/include/device.h @@ -67,6 +67,7 @@ struct dt_node *dt_new_addr(struct dt_node *parent, const char *name, uint64_t unit_addr); struct dt_node *dt_new_2addr(struct dt_node *parent, const char *name, uint64_t unit_addr0, uint64_t unit_addr1); +struct dt_node *dt_new_check(struct dt_node *parent, const char *name); /* Copy node to new parent, including properties and subnodes */ struct dt_node *dt_copy(struct dt_node *node, struct dt_node *parent);
This is similar to dt_new(), but if the node already exists it will return the existing node. This is useful because some init code depends on the presence of certain nodes, but where the node is actually created is unimportant. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> --- core/device.c | 14 ++++++++++++++ include/device.h | 1 + 2 files changed, 15 insertions(+)