[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0hbY8XCC-DfkoPFe15awV_FOpq91pUZvmZ9JrYi1QBMEg@mail.gmail.com>
Date: Tue, 15 Mar 2022 12:16:01 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Michael Walle <michael@...le.cc>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Len Brown <lenb@...nel.org>,
ACPI Devel Maling List <linux-acpi@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Nuno Sá <nuno.sa@...log.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Russell King <linux@...linux.org.uk>,
Horatiu Vultur <horatiu.vultur@...rochip.com>
Subject: Re: [PATCH v4 1/1] device property: Allow error pointer to be passed
to fwnode APIs
On Mon, Mar 14, 2022 at 8:51 PM Michael Walle <michael@...le.cc> wrote:
>
> Hi Andy,
>
> > Some of the fwnode APIs might return an error pointer instead of NULL
> > or valid fwnode handle. The result of such API call may be considered
> > optional and hence the test for it is usually done in a form of
> >
> > fwnode = fwnode_find_reference(...);
> > if (IS_ERR(fwnode))
> > ...error handling...
> >
> > Nevertheless the resulting fwnode may have bumped the reference count
> > and hence caller of the above API is obliged to call fwnode_handle_put().
> > Since fwnode may be not valid either as NULL or error pointer the check
> > has to be performed there. This approach uglifies the code and adds
> > a point of making a mistake, i.e. forgetting about error point case.
> >
> > To prevent this, allow an error pointer to be passed to the fwnode APIs.
> >
> > Fixes: 83b34afb6b79 ("device property: Introduce fwnode_find_reference()")
> > Reported-by: Nuno Sá <nuno.sa@...log.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> > Tested-by: Nuno Sá <nuno.sa@...log.com>
> > Reviewed-by: Sakari Ailus <sakari.ailus@...ux.intel.com>
> > Acked-by: Nuno Sá <nuno.sa@...log.com>
>
> This breaks SFP/phylink (using the lan966x switch) on my board. See below
> for more details.
I'm dropping this commit for the time being.
> [..]
>
> > @@ -480,15 +485,16 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
> > {
> > int ret;
> >
> > + if (IS_ERR_OR_NULL(fwnode))
> > + return -ENOENT;
> > +
> > ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
> > nargs, index, args);
> > + if (ret == 0)
>
> Should this be "if (ret == 0 || IS_ERR_OR_NULL(fwnode->secondary))" ?
>
> > + return ret;
> >
> > - if (ret < 0 && !IS_ERR_OR_NULL(fwnode) &&
> > - !IS_ERR_OR_NULL(fwnode->secondary))
> > - ret = fwnode_call_int_op(fwnode->secondary, get_reference_args,
> > - prop, nargs_prop, nargs, index, args);
> > -
> > - return ret;
> > + return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop,
> > + nargs, index, args);
> > }
> > EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args);
>
> What happens before this patch is that sfp_bus_find_fwnode() will call
> fwnode_property_get_reference_args() and the first calls return -ENOENT
> which sfp_bus_find_fwnode() will handle in a special way. After your
> patch, -EINVAL is returned, because fwnode_call_int_op() on
> fwnode->secondary is always called regardless of the return value of
> the original fwnode.
>
> -michael
Powered by blists - more mailing lists