[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aI0CupiFvyOvgNQY@kbusch-mbp>
Date: Fri, 1 Aug 2025 12:08:58 -0600
From: Keith Busch <kbusch@...nel.org>
To: Hans Zhang <18255117159@....com>
Cc: Gerd Bayer <gbayer@...ux.ibm.com>,
Manivannan Sadhasivam <mani@...nel.org>,
Hans Zhang <hans.zhang@...tech.com>,
Arnd Bergmann <arnd@...nel.org>, Bjorn Helgaas <helgaas@...nel.org>,
bhelgaas@...gle.com, Alexander Gordeev <agordeev@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
jingoohan1@...il.com,
Krzysztof Wilczy´nski <kwilczynski@...nel.org>,
linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org,
linux-next <linux-next@...r.kernel.org>, linux-pci@...r.kernel.org,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Rob Herring <robh@...nel.org>,
Niklas Schnelle <schnelle@...ux.ibm.com>, geert@...ux-m68k.org
Subject: Re: [PATCH] PCI: Fix endianness issues in pci_bus_read_config()
On Sat, Aug 02, 2025 at 12:54:27AM +0800, Hans Zhang wrote:
> As I mentioned in my reply to Mani's email, the data ultimately read here is
> also a forced type conversion.
>
> #define PCI_OP_READ(size, type, len) \
> int noinline pci_bus_read_config_##size \
> (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
> { \
> unsigned long flags; \
> u32 data = 0; \
> int res; \
> \
> if (PCI_##size##_BAD) \
> return PCIBIOS_BAD_REGISTER_NUMBER; \
> \
> pci_lock_config(flags); \
> res = bus->ops->read(bus, devfn, pos, len, &data); \
> if (res) \
> PCI_SET_ERROR_RESPONSE(value); \
> else \
> *value = (type)data; \
> pci_unlock_config(flags); \
> \
> return res; \
> }
>
> And this function. Could it be that I misunderstood something?
The above macro retains the caller's type for "value". If the caller
passes a "u8 *", the value is deferenced as a u8.
The function below promotes everything to a u32 pointer and deferences
it as such regardless of what type the user passed in.
> int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
> int where, int size, u32 *val)
> {
> void __iomem *addr;
>
> addr = bus->ops->map_bus(bus, devfn, where);
> if (!addr)
> return PCIBIOS_DEVICE_NOT_FOUND;
>
> if (size == 1)
> *val = readb(addr);
> else if (size == 2)
> *val = readw(addr);
> else
> *val = readl(addr);
>
> return PCIBIOS_SUCCESSFUL;
> }
Powered by blists - more mailing lists