Re: [PATCH 1/1] lib/vsprintf: Fix %pfwf when current node refcount == 0

From: Sakari Ailus
Date: Tue Nov 14 2023 - 07:29:39 EST


Hi Herve,

On Tue, Nov 14, 2023 at 12:48:32PM +0100, Herve Codina wrote:
> Hi Sakari,
>
> On Tue, 14 Nov 2023 11:28:43 +0000
> Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> wrote:
>
> > > --- a/lib/vsprintf.c
> > > +++ b/lib/vsprintf.c
> > > @@ -2108,8 +2108,8 @@ char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> > > {
> > > int depth;
> > >
> > > - /* Loop starting from the root node to the current node. */
> > > - for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
> > > + /* Loop starting from the root node to the parent of current node. */
> > > + for (depth = fwnode_count_parents(fwnode); depth > 0; depth--) {
> > > struct fwnode_handle *__fwnode =
> > > fwnode_get_nth_parent(fwnode, depth);
> >
> > How about, without changing the loop:
> >
> > /*
> > * Only get a reference for other nodes, fwnode refcount
> > * may be 0 here.
> > */
> > struct fwnode_handle *__fwnode =
> > depth ? fwnode_get_nth_parent(fwnode, depth) : fwnode;
> >
> > >
> > > @@ -2121,6 +2121,16 @@ char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> > > fwnode_handle_put(__fwnode);
> >
> > And:
> >
> > if (__fwnode != fwnode)
> > fwnode_handle_put(__fwnode);
> >
>
> Sure.
> I will just change to keep the both tests consistent.
> I mean test with depth or test with __fwnode != fwnode but avoid
> mixing them.
>
> What do you think about testing using depth in all cases and so:
> if (depth)
> fwnode_handle_put(__fwnode);

I'd compare fwnodes as we're putting __fwnode since we've gotten a
reference to fwnodes different from fwnode. I don't have a strong opinion
on this though, up to you.

--
Regards,

Sakari Ailus