All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: Re: [PATCH] PCI/VPD: Use unaligned access helper in pci_vpd_write
Date: Fri, 30 Apr 2021 15:29:33 -0500	[thread overview]
Message-ID: <20210430202933.GA678605@bjorn-Precision-5520> (raw)
In-Reply-To: <79d337f4-25d6-9024-2cbd-63801cbd9992@gmail.com>

On Sun, Apr 18, 2021 at 11:19:29AM +0200, Heiner Kallweit wrote:
> Use helper get_unaligned_le32() to simplify the code.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/pci/vpd.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
> index 60573f27a..2888bb300 100644
> --- a/drivers/pci/vpd.c
> +++ b/drivers/pci/vpd.c
> @@ -9,6 +9,7 @@
>  #include <linux/delay.h>
>  #include <linux/export.h>
>  #include <linux/sched/signal.h>
> +#include <asm/unaligned.h>
>  #include "pci.h"
>  
>  /* VPD access through PCI 2.2+ VPD capability */
> @@ -235,10 +236,9 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
>  }
>  
>  static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
> -			     const void *arg)
> +			     const void *buf)
>  {
>  	struct pci_vpd *vpd = dev->vpd;
> -	const u8 *buf = arg;
>  	loff_t end = pos + count;
>  	int ret = 0;
>  
> @@ -264,14 +264,8 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
>  		goto out;
>  
>  	while (pos < end) {
> -		u32 val;
> -
> -		val = *buf++;
> -		val |= *buf++ << 8;
> -		val |= *buf++ << 16;
> -		val |= *buf++ << 24;
> -
> -		ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA, val);
> +		ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA,
> +						  get_unaligned_le32(buf));

If I understand correctly, get_unaligned_le32() is equivalent to the
open-coded "val = *buf++; ..."  In other words, this doesn't fix a bug
on any platforms, and it doesn't change the bits written to VPD.
Right?

If so, this makes sense.  I'd like it better if we could also make
pci_vpd_read() look more symmetric, since it has similar byte
order-related code.  The read side is a little more complicated since
the size need not be 4-byte aligned.  But maybe there's a way?  Seems
like there should be other examples of this sort of thing, but my
quick look didn't find one.

>  		if (ret < 0)
>  			break;
>  		ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
> @@ -286,6 +280,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
>  			break;
>  
>  		pos += sizeof(u32);
> +		buf += sizeof(u32);
>  	}
>  out:
>  	mutex_unlock(&vpd->lock);
> -- 
> 2.31.1
> 

  parent reply	other threads:[~2021-04-30 20:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-18  9:19 [PATCH] PCI/VPD: Use unaligned access helper in pci_vpd_write Heiner Kallweit
2021-04-19 11:10 ` Heiner Kallweit
2021-04-19 11:31   ` Heiner Kallweit
2021-04-30 20:29 ` Bjorn Helgaas [this message]
2021-04-30 20:35   ` Heiner Kallweit

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=20210430202933.GA678605@bjorn-Precision-5520 \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.