public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel•org>
To: Hans Zhang <18255117159@163•com>
Cc: "Gerd Bayer" <gbayer@linux•ibm.com>,
	"Manivannan Sadhasivam" <mani@kernel•org>,
	"Hans Zhang" <hans.zhang@cixtech•com>,
	"Arnd Bergmann" <arnd@kernel•org>,
	"Bjorn Helgaas" <helgaas@kernel•org>,
	bhelgaas@google•com, "Alexander Gordeev" <agordeev@linux•ibm.com>,
	"Christian Borntraeger" <borntraeger@linux•ibm.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux•intel.com>,
	jingoohan1@gmail•com,
	"Krzysztof Wilczy´nski" <kwilczynski@kernel•org>,
	linux-kernel@vger•kernel.org, linux-s390@vger•kernel.org,
	linux-next <linux-next@vger•kernel.org>,
	linux-pci@vger•kernel.org,
	"Lorenzo Pieralisi" <lpieralisi@kernel•org>,
	"Rob Herring" <robh@kernel•org>,
	"Niklas Schnelle" <schnelle@linux•ibm.com>,
	geert@linux-m68k•org
Subject: Re: [PATCH] PCI: Fix endianness issues in pci_bus_read_config()
Date: Fri, 1 Aug 2025 12:08:58 -0600	[thread overview]
Message-ID: <aI0CupiFvyOvgNQY@kbusch-mbp> (raw)
In-Reply-To: <659b8389-16a7-423b-a231-5489c7cc0da9@163.com>

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;
> }

  reply	other threads:[~2025-08-01 18:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250716231121.GA2564572@bhelgaas>
2025-07-31  7:32 ` [REGRESSION] next/master: suspect endianness issue in common PCI capability search macro Gerd Bayer
2025-07-31 17:38   ` [PATCH] PCI: Fix endianness issues in pci_bus_read_config() Gerd Bayer
2025-07-31 18:39     ` Bjorn Helgaas
2025-07-31 19:01       ` Arnd Bergmann
2025-08-01  8:18         ` Manivannan Sadhasivam
2025-08-01  9:25           ` Hans Zhang
2025-08-01  9:47             ` Manivannan Sadhasivam
2025-08-01 10:06               ` Hans Zhang
2025-08-01 10:54                 ` Manivannan Sadhasivam
2025-08-01 11:30                   ` Gerd Bayer
2025-08-01 16:54                     ` Hans Zhang
2025-08-01 18:08                       ` Keith Busch [this message]
2025-08-02 15:23                         ` Hans Zhang
2025-08-02 15:40                           ` Arnd Bergmann
2025-08-04  3:06                     ` Hans Zhang
2025-08-04  8:03                       ` Arnd Bergmann
2025-08-04  8:25                         ` Hans Zhang
2025-08-04 10:09                       ` Gerd Bayer
2025-08-12 14:44                         ` Hans Zhang
2025-08-13  7:47                           ` Niklas Schnelle
2025-08-13  7:50                             ` Hans Zhang
2025-08-04 14:33                       ` Bjorn Helgaas
2025-08-04 15:04                         ` Hans Zhang
2025-08-01 16:47                   ` Hans Zhang
2025-07-31 18:53     ` Lukas Wunner
2025-08-01  7:52     ` Geert Uytterhoeven

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=aI0CupiFvyOvgNQY@kbusch-mbp \
    --to=kbusch@kernel$(echo .)org \
    --cc=18255117159@163$(echo .)com \
    --cc=agordeev@linux$(echo .)ibm.com \
    --cc=arnd@kernel$(echo .)org \
    --cc=bhelgaas@google$(echo .)com \
    --cc=borntraeger@linux$(echo .)ibm.com \
    --cc=gbayer@linux$(echo .)ibm.com \
    --cc=geert@linux-m68k$(echo .)org \
    --cc=hans.zhang@cixtech$(echo .)com \
    --cc=helgaas@kernel$(echo .)org \
    --cc=ilpo.jarvinen@linux$(echo .)intel.com \
    --cc=jingoohan1@gmail$(echo .)com \
    --cc=kwilczynski@kernel$(echo .)org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=linux-pci@vger$(echo .)kernel.org \
    --cc=linux-s390@vger$(echo .)kernel.org \
    --cc=lpieralisi@kernel$(echo .)org \
    --cc=mani@kernel$(echo .)org \
    --cc=robh@kernel$(echo .)org \
    --cc=schnelle@linux$(echo .)ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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