Re: [PATCH] software node: provide wrappers around kobject_get/put()

From: Andy Shevchenko

Date: Fri Apr 24 2026 - 11:34:53 EST


On Fri, Apr 24, 2026 at 03:43:39PM +0200, Bartosz Golaszewski wrote:
> On Fri, Apr 24, 2026 at 3:33 PM Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> > On Fri, Apr 24, 2026 at 02:42:50PM +0200, Bartosz Golaszewski wrote:

...

> > Isn't a pattern to return the object itself so the code can bump the reference
> > in a single statement (if appropriate)?
>
> Typically yeah but nobody here would use it right now. I can change it
> if you prefer it.

I showed below the example (it's now cut from the context).

...

> > > list_for_each_entry(child, &swnode->children, entry) {
> > > if (!strcmp(childname, kobject_name(&child->kobj))) {
> > > - kobject_get(&child->kobj);
> > > + swnode_get(child);
> >
> > Becomes inconsistent with kobject_name()...
>
> What do you mean?
>
> > > return &child->fwnode;
> > > }
> > > }

The same piece of code uses kobj and child either way of this conversion happen
or not. To be fully consistent we need something like swnode_match_name() or
alike instead of that strcmp().

...

> > > swnode = kobj_to_swnode(k);
> > > if (parent == swnode->node->parent && swnode->node->name &&
> > > !strcmp(name, swnode->node->name)) {
> > > - kobject_get(&swnode->kobj);
> > > + swnode_get(swnode);
> >
> > Also not sure. Maybe use 'k'?
>
> I'm not following either, please rephrase.

kobject_get(k);

should also work. And here I referred to the fact that we already have a kobject
instance available. Yes, my counter example is just to reveal inconsistency,
I kinda agree that using swnode specific API might be clearer approach.

--
With Best Regards,
Andy Shevchenko