lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y2V+8tiwstXbTWoq@smile.fi.intel.com>
Date:   Fri, 4 Nov 2022 23:06:58 +0200
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Dmitry Torokhov <dmitry.torokhov@...il.com>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Bartosz Golaszewski <brgl@...ev.pl>,
        linux-acpi@...r.kernel.org, linux-gpio@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 5/6] gpiolib: consolidate GPIO lookups

On Fri, Nov 04, 2022 at 11:52:26AM -0700, Dmitry Torokhov wrote:
> On Fri, Nov 04, 2022 at 07:17:27PM +0200, Andy Shevchenko wrote:
> > On Thu, Nov 03, 2022 at 11:10:15PM -0700, Dmitry Torokhov wrote:

...

> > > +static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
> > > +					      struct device *consumer,
> > > +					      const char *con_id,
> > > +					      unsigned int idx,
> > > +					      enum gpiod_flags *flags,
> > > +					      unsigned long *lookupflags)
> > >  {
> > 
> > > +	struct gpio_desc *desc = ERR_PTR(-ENOENT);
> > 
> > No need, just return directly.
> > 
> > > +	dev_dbg(consumer, "GPIO lookup for consumer %s in node '%s'\n",
> > > +		con_id, fwnode_get_name(fwnode));
> > 
> > %pfwP ?
> 
> OK. Although, I think I like %pfw (without 'P') better as it gives
> results like:
> 
> 	/soc/i2c@...07000/edp-bridge@8
> 
> or
> 
> 	\_SB.PCI0.I2C1.D010
> 
> which should help identifying the exact node.

I agree.

> > > +	/* Using device tree? */
> > >  	if (is_of_node(fwnode)) {
> > > +		dev_dbg(consumer, "using device tree for GPIO lookup\n");
> > > +		desc = of_find_gpio(to_of_node(fwnode),
> > > +				    con_id, idx, lookupflags);
> > >  	} else if (is_acpi_node(fwnode)) {
> > 
> > With direct return, no need for 'else' here.
> 
> When we have several branches of equal weight I prefer not to have
> early/inline returns, but I can add:
> 
> 	} else {
> 		desc = ERR_PTR(-ENOENT);
> 	}
> 
> at the end, what do you think?

No strong opinion here.

> > > +		dev_dbg(consumer, "using ACPI for GPIO lookup\n");
> > > +		desc = acpi_find_gpio(fwnode, con_id, idx, flags, lookupflags);
> > >  	}
> > >  
> > > +	return desc;
> > > +}

...

> > > +	struct gpio_desc *desc = ERR_PTR(-ENOENT);
> > 
> > We can get rid of the assignment, see below.

Still below another thought which affects this.

> > > +	if (fwnode)
> > 
> > Do we need this check?
> 
> Yes, I would prefer to have it as it clearly informs the reader that we
> are only doing lookup by node if we actually have a node.
> 
> gpiod_find_and_request() expects that it gets a valid node and in the
> followup change it will be dereferencing fwnode without checking for
> NULL-ness.

But most of the code will check for the NULL anyway. The exceptions are
dev_dbg() and accessing to the secondary fwnode.

> > Debug message above (when %pfw is used) would be even useful when
> > fwnode == NULL.

> > > +		desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx,
> > > +					    &flags, &lookupflags);

Looking into drivers/base/property.c makes me realize that you might need to
test for error pointer as well.

Perhaps something like

	if (IS_ERR_OR_NULL(fwnode))
		return ERR_PTR(-ENOENT);

in the gpiod_find_by_fwnode() needs to be added. Can you check this?

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ