diff options
author | Heiner Kallweit <hkallweit1@gmail.com> | 2021-08-26 20:58:07 +0200 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2021-08-31 16:10:18 -0500 |
commit | 2c208abd4f9efac02622d8f3c9989f4b7b1ad973 (patch) | |
tree | 5b0f8fdc3b85174d161d0d4594524fbc760278c9 /drivers/pci | |
parent | 06e1913d457121a98ee276179734c34dab30f388 (diff) |
PCI/VPD: Use unaligned access helpers
Use unaligned access helpers to simplify the code.
Link: https://lore.kernel.org/r/0f1c7e21-5330-72ab-139d-f5ce3c65f04a@gmail.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/vpd.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index ff600dff4557..25557b272a4f 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" #define PCI_VPD_LRDT_TAG_SIZE 3 @@ -19,7 +20,7 @@ static u16 pci_vpd_lrdt_size(const u8 *lrdt) { - return (u16)lrdt[1] + ((u16)lrdt[2] << 8); + return get_unaligned_le16(lrdt + 1); } static u8 pci_vpd_srdt_tag(const u8 *srdt) @@ -218,14 +219,8 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, return -EINTR; 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 (ret < 0) break; ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR, @@ -237,6 +232,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, if (ret < 0) break; + buf += sizeof(u32); pos += sizeof(u32); } |