Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>
Subject: Re: [PATCH v2] PCI/VPD: Use unaligned access helpers in pci_vpd_read
Date: Mon, 10 May 2021 09:09:02 +0200	[thread overview]
Message-ID: <26a9b3ec-07dc-c474-25ad-d7082060d305@gmail.com> (raw)
In-Reply-To: <YJjUWulw8vkscdwg@infradead.org>

On 10.05.2021 08:36, Christoph Hellwig wrote:
> On Sat, May 08, 2021 at 12:29:15AM +0200, Heiner Kallweit wrote:
>> +
>> +		if (len == 4)  {
>> +			put_unaligned_le32(val, buf);
>> +		} else {
>> +			cpu_to_le32s(&val);
>> +			memcpy(buf, (u8 *)&val + skip, len);
> 
> cpu_to_le32s is a horrible API that breaks endianess annotations.
> 
The endian-adjusted value is used just in the next line, so I think
there's no risk of wrong usage.
But yes, this function converts to le32 w/o using __bitwise.
Therefore I understand the concern.

> Is the intent of this code to only put 16 bits in?  Why not something
> like:
> 
> 		switch (len) {
> 		case 4:
> 			put_unaligned_le32(val, buf);
> 			break;
> 		case 2:
> 			put_unaligned_le16(val, buf + 2);
> 			break;
> 		case 1:
> 			buf[3] = val;
> 			break;
>   		}
> 
len can have any value 1 .. 4. Also the proposal doesn't consider
the skip value.

  reply	other threads:[~2021-05-10  7:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 22:29 [PATCH v2] PCI/VPD: Use unaligned access helpers in pci_vpd_read Heiner Kallweit
2021-05-10  6:36 ` Christoph Hellwig
2021-05-10  7:09   ` Heiner Kallweit [this message]
2021-05-12  7:21     ` Christoph Hellwig
2021-05-12  7:56       ` Heiner Kallweit
2021-05-12 17:35         ` Christoph Hellwig

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=26a9b3ec-07dc-c474-25ad-d7082060d305@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=hch@infradead.org \
    --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