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]
Date:   Thu, 12 Aug 2021 10:14:25 +0200
From:   Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To:     Christoph Hellwig <hch@...radead.org>
Cc:     Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        linux-pci@...r.kernel.org, Alexander Duyck <alexanderduyck@...com>,
        oss-drivers@...igine.com, Paul Mackerras <paulus@...ba.org>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        Michael Ellerman <mpe@...erman.id.au>,
        Rafa?? Mi??ecki <zajec5@...il.com>,
        Jesse Brandeburg <jesse.brandeburg@...el.com>,
        Bjorn Helgaas <helgaas@...nel.org>,
        Ido Schimmel <idosch@...dia.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Yisen Zhuang <yisen.zhuang@...wei.com>,
        Vadym Kochan <vkochan@...vell.com>, Michael Buesch <m@...s.ch>,
        Jiri Pirko <jiri@...dia.com>,
        Salil Mehta <salil.mehta@...wei.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-wireless@...r.kernel.org, linux-kernel@...r.kernel.org,
        Taras Chornyi <tchornyi@...vell.com>,
        Zhou Wang <wangzhou1@...ilicon.com>,
        linux-crypto@...r.kernel.org, kernel@...gutronix.de,
        netdev@...r.kernel.org, Simon Horman <simon.horman@...igine.com>,
        Oliver O'Halloran <oohall@...il.com>,
        linuxppc-dev@...ts.ozlabs.org,
        "David S. Miller" <davem@...emloft.net>
Subject: Re: [PATCH v3 4/8] PCI: replace pci_dev::driver usage that gets the
 driver name

On Thu, Aug 12, 2021 at 08:07:20AM +0100, Christoph Hellwig wrote:
> On Wed, Aug 11, 2021 at 10:06:33AM +0200, Uwe Kleine-K??nig wrote:
> >  static inline const char *eeh_driver_name(struct pci_dev *pdev)
> >  {
> > -	return (pdev && pdev->driver) ? pdev->driver->name : "<null>";
> > +	const char *drvstr = pdev ? dev_driver_string(&pdev->dev) : "";
> > +
> > +	if (*drvstr == '\0')
> > +		return "<null>";
> > +
> > +	return drvstr;
> 
> This looks rather obsfucated due to the fact that dev_driver_string
> never returns '\0', and due to the strange mix of a tenary operation
> and the if on a related condition.

dev_driver_string() might return "" (via dev_bus_name()). If that happens
*drvstr == '\0' becomes true.

Would the following be better?:

	const char *drvstr;

	if (pdev)
		return "<null>";

	drvstr = dev_driver_string(&pdev->dev);

	if (!strcmp(drvstr, ""))
		return "<null>";

	return drvstr;

When I thought about this hunk I considered it ugly to have "<null>" in
it twice.

> >  }
> >  
> >  #endif /* CONFIG_EEH */
> > diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
> > index 69c10a7b7c61..dc2ffa686964 100644
> > --- a/drivers/bcma/host_pci.c
> > +++ b/drivers/bcma/host_pci.c
> > @@ -175,9 +175,10 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
> >  	if (err)
> >  		goto err_kfree_bus;
> >  
> > -	name = dev_name(&dev->dev);
> > -	if (dev->driver && dev->driver->name)
> > -		name = dev->driver->name;
> > +	name = dev_driver_string(&dev->dev);
> > +	if (*name == '\0')
> > +		name = dev_name(&dev->dev);
> 
> Where does this '\0' check come from?

The original code is equivalent to

	if (dev->driver && dev->driver->name)
		name = dev->driver->name;
	else:
		name = dev_name(...);

As dev_driver_string() implements something like:

	if (dev->driver && dev->driver->name)
		return dev->driver->name;
	else
		return "";

the change looks fine to me. (One could wonder if it's sensible to fall
back to the device name if the driver has no nice name, but this isn't
new with my change.)

> > +	name = dev_driver_string(&dev->dev);
> > +	if (*name == '\0')
> > +		name = dev_name(&dev->dev);
> > +
> 
> More of this weirdness.

I admit it's not pretty. Would it help to use !strcmp(name, "")
instead of *name == '\0'? Any other constructive suggestion?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ