linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: "Uwe Kleine-König" <uwe@kleine-koenig.org>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	linux-pci@vger.kernel.org,
	"Alexander Duyck" <alexanderduyck@fb.com>,
	oss-drivers@corigine.com, "Paul Mackerras" <paulus@samba.org>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Rafał Miłecki" <zajec5@gmail.com>,
	"Jesse Brandeburg" <jesse.brandeburg@intel.com>,
	"Bjorn Helgaas" <helgaas@kernel.org>,
	"Ido Schimmel" <idosch@nvidia.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Michael Buesch" <m@bues.ch>, "Jiri Pirko" <jiri@nvidia.com>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Zhou Wang" <wangzhou1@hisilicon.com>,
	linux-crypto@vger.kernel.org, kernel@pengutronix.de,
	"Oliver O'Halloran" <oohall@gmail.com>,
	linuxppc-dev@lists.ozlabs.org,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v4 4/8] PCI: replace pci_dev::driver usage that gets the driver name
Date: Wed, 29 Sep 2021 10:05:42 +0200	[thread overview]
Message-ID: <20210929080541.GA13506@corigine.com> (raw)
In-Reply-To: <20210928103129.c3gcbnfbarezr3mm@pengutronix.de>

On Tue, Sep 28, 2021 at 12:31:29PM +0200, Uwe Kleine-König wrote:
> On Tue, Sep 28, 2021 at 12:01:28PM +0200, Simon Horman wrote:
> > On Mon, Sep 27, 2021 at 10:43:22PM +0200, Uwe Kleine-König wrote:
> > > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > 
> > > struct pci_dev::driver holds (apart from a constant offset) the same
> > > data as struct pci_dev::dev->driver. With the goal to remove struct
> > > pci_dev::driver to get rid of data duplication replace getting the
> > > driver name by dev_driver_string() which implicitly makes use of struct
> > > pci_dev::dev->driver.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > 
> > ...
> > 
> > > diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > > index 0685ece1f155..23dfb599c828 100644
> > > --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > > +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > > @@ -202,7 +202,7 @@ nfp_get_drvinfo(struct nfp_app *app, struct pci_dev *pdev,
> > >  {
> > >  	char nsp_version[ETHTOOL_FWVERS_LEN] = {};
> > >  
> > > -	strlcpy(drvinfo->driver, pdev->driver->name, sizeof(drvinfo->driver));
> > > +	strlcpy(drvinfo->driver, dev_driver_string(&pdev->dev), sizeof(drvinfo->driver));
> > 
> > I'd slightly prefer to maintain lines under 80 columns wide.
> > But not nearly strongly enough to engage in a long debate about it.
> 
> :-)
> 
> Looking at the output of
> 
> 	git grep strlcpy.\*sizeof
> 
> I wonder if it would be sensible to introduce something like
> 
> 	#define strlcpy_array(arr, src) (strlcpy(arr, src, sizeof(arr)) + __must_be_array(arr))
> 
> but not sure this is possible without a long debate either (and this
> line is over 80 chars wide, too :-).

My main motivation for the 80 char limit in nfp_net_ethtool.c is
not that I think 80 char is universally a good limit (although that is true),
but rather that I expect that is the prevailing style in nfp_net_ethtool.c.

So a macro more than 80 car wide somewhere else is fine by me.

However, when running checkpatch --strict over the patch it told me:

    WARNING: Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
    #276: FILE: drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c:205:
    +	strlcpy(drvinfo->driver, dev_driver_string(&pdev->dev), sizeof(drvinfo->driver));

    total: 0 errors, 1 warnings, 0 checks, 80 lines checked

(Amusingly, more text wider than 80 column, perhaps suggesting the folly of
 my original comment, but lets move on from that.)

As your patch doesn't introduce the usage of strlcpy() I was considering a
follow-up patch to change it to strscpy(). And in general the email at the
link above suggests all usages of strlcpy() should do so. So perhaps
creating strscpy_array is a better idea?

I have not thought about this much, and probably this just leads us to a
deeper part of the rabbit hole.

  reply	other threads:[~2021-09-29  8:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 20:43 [PATCH v4 0/8] PCI: Drop duplicated tracking of a pci_dev's bound driver Uwe Kleine-König
2021-09-27 20:43 ` [PATCH v4 4/8] PCI: replace pci_dev::driver usage that gets the driver name Uwe Kleine-König
2021-09-28  8:28   ` Kalle Valo
2021-09-28 10:01   ` Simon Horman
2021-09-28 10:31     ` Uwe Kleine-König
2021-09-29  8:05       ` Simon Horman [this message]
2021-09-29  9:04         ` Uwe Kleine-König
2021-09-28 17:17   ` Bjorn Helgaas
2021-09-28 19:29     ` Uwe Kleine-König
2021-09-28 20:08       ` Bjorn Helgaas
2021-09-27 20:59 ` [PATCH v4 0/8] PCI: Drop duplicated tracking of a pci_dev's bound driver Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929080541.GA13506@corigine.com \
    --to=simon.horman@corigine.com \
    --cc=alexanderduyck@fb.com \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=helgaas@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=idosch@nvidia.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=jiri@nvidia.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=m@bues.ch \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=oohall@gmail.com \
    --cc=oss-drivers@corigine.com \
    --cc=paulus@samba.org \
    --cc=salil.mehta@huawei.com \
    --cc=tchornyi@marvell.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=uwe@kleine-koenig.org \
    --cc=vkochan@marvell.com \
    --cc=wangzhou1@hisilicon.com \
    --cc=yisen.zhuang@huawei.com \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).