Message ID | 20211007000954.30621-5-zev@bewilderbeest.net |
---|---|
State | New |
Headers | show |
Series | Dynamic DT device nodes | expand |
On Wed, Oct 06, 2021 at 05:09:49PM -0700, Zev Weiss wrote: > This allows using the function to remove a bin_attribute from that > attribute's own methods (by calling sysfs_remove_bin_file_self() > instead of sysfs_remove_bin_file()). > > Signed-off-by: Zev Weiss <zev@bewilderbeest.net> > --- > drivers/of/kobj.c | 13 ++++++++----- > drivers/of/of_private.h | 2 +- > 2 files changed, 9 insertions(+), 6 deletions(-) > > diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c > index 6675b5e56960..06d6c90f7aa1 100644 > --- a/drivers/of/kobj.c > +++ b/drivers/of/kobj.c > @@ -84,12 +84,15 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp) > return rc; > } > > -void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop) > +void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop, bool self) > { > if (!IS_ENABLED(CONFIG_SYSFS)) > return; > > - sysfs_remove_bin_file(&np->kobj, &prop->attr); > + if (self) > + sysfs_remove_bin_file_self(&np->kobj, &prop->attr); > + else > + sysfs_remove_bin_file(&np->kobj, &prop->attr); > kfree(prop->attr.attr.name); > } > > @@ -97,7 +100,7 @@ void __of_remove_property_sysfs(struct device_node *np, struct property *prop) > { > /* at early boot, bail here and defer setup to of_init() */ > if (of_kset && of_node_is_attached(np)) > - __of_sysfs_remove_bin_file(np, prop); > + __of_sysfs_remove_bin_file(np, prop, false); > } > > void __of_update_property_sysfs(struct device_node *np, struct property *newprop, > @@ -108,7 +111,7 @@ void __of_update_property_sysfs(struct device_node *np, struct property *newprop > return; > > if (oldprop) > - __of_sysfs_remove_bin_file(np, oldprop); > + __of_sysfs_remove_bin_file(np, oldprop, false); > __of_add_property_sysfs(np, newprop); > } > > @@ -157,7 +160,7 @@ void __of_detach_node_sysfs(struct device_node *np) > /* only remove properties if on sysfs */ > if (of_node_is_attached(np)) { > for_each_property_of_node(np, pp) > - __of_sysfs_remove_bin_file(np, pp); > + __of_sysfs_remove_bin_file(np, pp, false); > kobject_del(&np->kobj); > } > > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > index 75e67b8bb826..fff157c63907 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -134,7 +134,7 @@ extern int __of_update_property(struct device_node *np, > extern void __of_detach_node(struct device_node *np); > > extern void __of_sysfs_remove_bin_file(struct device_node *np, > - struct property *prop); > + struct property *prop, bool selfremove); Ick, no, now you have to go and find the function declaration every time you see this called. Adding random boolean flags to functions is not how to make an api that works well, sorry. greg k-h
diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 6675b5e56960..06d6c90f7aa1 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -84,12 +84,15 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp) return rc; } -void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop) +void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop, bool self) { if (!IS_ENABLED(CONFIG_SYSFS)) return; - sysfs_remove_bin_file(&np->kobj, &prop->attr); + if (self) + sysfs_remove_bin_file_self(&np->kobj, &prop->attr); + else + sysfs_remove_bin_file(&np->kobj, &prop->attr); kfree(prop->attr.attr.name); } @@ -97,7 +100,7 @@ void __of_remove_property_sysfs(struct device_node *np, struct property *prop) { /* at early boot, bail here and defer setup to of_init() */ if (of_kset && of_node_is_attached(np)) - __of_sysfs_remove_bin_file(np, prop); + __of_sysfs_remove_bin_file(np, prop, false); } void __of_update_property_sysfs(struct device_node *np, struct property *newprop, @@ -108,7 +111,7 @@ void __of_update_property_sysfs(struct device_node *np, struct property *newprop return; if (oldprop) - __of_sysfs_remove_bin_file(np, oldprop); + __of_sysfs_remove_bin_file(np, oldprop, false); __of_add_property_sysfs(np, newprop); } @@ -157,7 +160,7 @@ void __of_detach_node_sysfs(struct device_node *np) /* only remove properties if on sysfs */ if (of_node_is_attached(np)) { for_each_property_of_node(np, pp) - __of_sysfs_remove_bin_file(np, pp); + __of_sysfs_remove_bin_file(np, pp, false); kobject_del(&np->kobj); } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 75e67b8bb826..fff157c63907 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -134,7 +134,7 @@ extern int __of_update_property(struct device_node *np, extern void __of_detach_node(struct device_node *np); extern void __of_sysfs_remove_bin_file(struct device_node *np, - struct property *prop); + struct property *prop, bool selfremove); /* illegal phandle value (set when unresolved) */ #define OF_PHANDLE_ILLEGAL 0xdeadbeef
This allows using the function to remove a bin_attribute from that attribute's own methods (by calling sysfs_remove_bin_file_self() instead of sysfs_remove_bin_file()). Signed-off-by: Zev Weiss <zev@bewilderbeest.net> --- drivers/of/kobj.c | 13 ++++++++----- drivers/of/of_private.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)