Netdev List
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: Re: [PATCH net-next] net: enetc: use get/put_unaligned() for mac address handling
Date: Fri, 04 Jun 2021 15:27:48 +0200	[thread overview]
Message-ID: <a1f426e85e24a910944fc712e5c08f01@walle.cc> (raw)
In-Reply-To: <db1964cd-df60-08a2-1a66-8a8df7f14fef@gmail.com>

Am 2021-06-04 14:44, schrieb Heiner Kallweit:
> On 04.06.2021 14:30, Michael Walle wrote:
>> The supplied buffer for the MAC address might not be aligned. Thus
>> doing a 32bit (or 16bit) access could be on an unaligned address. For
>> now, enetc is only used on aarch64 which can do unaligned accesses, 
>> thus
>> there is no error. In any case, be correct and use the 
>> get/put_unaligned()
>> helpers.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  drivers/net/ethernet/freescale/enetc/enetc_pf.c | 9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c 
>> b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
>> index 31274325159a..a96d2acb5e11 100644
>> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
>> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
>> @@ -1,6 +1,7 @@
>>  // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
>>  /* Copyright 2017-2019 NXP */
>> 
>> +#include <asm/unaligned.h>
>>  #include <linux/mdio.h>
>>  #include <linux/module.h>
>>  #include <linux/fsl/enetc_mdio.h>
>> @@ -17,15 +18,15 @@ static void enetc_pf_get_primary_mac_addr(struct 
>> enetc_hw *hw, int si, u8 *addr)
>>  	u32 upper = __raw_readl(hw->port + ENETC_PSIPMAR0(si));
>>  	u16 lower = __raw_readw(hw->port + ENETC_PSIPMAR1(si));
>> 
>> -	*(u32 *)addr = upper;
>> -	*(u16 *)(addr + 4) = lower;
>> +	put_unaligned(upper, (u32 *)addr);
>> +	put_unaligned(lower, (u16 *)(addr + 4));
> 
> I think you want to write little endian, therefore on a BE platform
> this code may be wrong. Better use put_unaligned_le32?
> By using these versions of the unaligned helpers you could also
> remove the pointer cast.

I wasn't sure about the endianness. Might be the case, that on BE
platforms, the endianess of the register will swap too. (OTOH I
could use aarch64 with BE..)

But I'm fine with changing it. I'd presume this being the only
platform for now it doesn't really matter.

-michael

  reply	other threads:[~2021-06-04 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 12:30 [PATCH net-next] net: enetc: use get/put_unaligned() for mac address handling Michael Walle
2021-06-04 12:44 ` Heiner Kallweit
2021-06-04 13:27   ` Michael Walle [this message]
2021-06-04 13:34   ` Claudiu Manoil

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=a1f426e85e24a910944fc712e5c08f01@walle.cc \
    --to=michael@walle.cc \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    /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