From: Heiner Kallweit <hkallweit1@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
Bjorn Helgaas <helgaas@kernel.org>
Subject: [PATCH] PCI/VPD: Use unaligned access helpers in pci_vpd_read
Date: Sat, 1 May 2021 15:43:11 +0200 [thread overview]
Message-ID: <6edebb53-b714-3205-6266-d02416fd3cfe@gmail.com> (raw)
With this patch we avoid some unnecessary looping and make the code
better readable.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/pci/vpd.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 741e7a505..0752505d7 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -163,12 +163,11 @@ static int pci_vpd_wait(struct pci_dev *dev)
}
static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
- void *arg)
+ void *buf)
{
struct pci_vpd *vpd = dev->vpd;
int ret;
loff_t end = pos + count;
- u8 *buf = arg;
if (pos < 0)
return -EINVAL;
@@ -197,8 +196,8 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
goto out;
while (pos < end) {
+ unsigned int len, skip;
u32 val;
- unsigned int i, skip;
ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
pos & ~3);
@@ -215,14 +214,19 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
break;
skip = pos & 3;
- for (i = 0; i < sizeof(u32); i++) {
- if (i >= skip) {
- *buf++ = val;
- if (++pos == end)
- break;
- }
- val >>= 8;
+ len = min_t(unsigned int, 4 - skip, end - pos);
+
+ if (len == 4) {
+ put_unaligned_le32(val, buf);
+ } else {
+ u8 tmpbuf[4];
+
+ put_unaligned_le32(val, tmpbuf);
+ memcpy(buf, tmpbuf + skip, len);
}
+
+ buf += len;
+ pos += len;
}
out:
mutex_unlock(&vpd->lock);
--
2.31.1
next reply other threads:[~2021-05-01 13:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-01 13:43 Heiner Kallweit [this message]
2021-05-01 16:52 ` [PATCH] PCI/VPD: Use unaligned access helpers in pci_vpd_read kernel test robot
2021-05-01 19:53 ` Heiner Kallweit
2021-05-07 21:18 ` Heiner Kallweit
2021-05-01 17:23 ` kernel test robot
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=6edebb53-b714-3205-6266-d02416fd3cfe@gmail.com \
--to=hkallweit1@gmail.com \
--cc=bhelgaas@google.com \
--cc=helgaas@kernel.org \
--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 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).