Subject: Re: [RFC net-next PATCH 2/3] mv88e6xxx: Implement remote management support (RMU)

From: Andrew Lunn <[email-masked]>
Date: Fri, 19 Aug 2022 14:29:56 +0200

> >> +int mv88e6xxx_inband_rcv(struct dsa_switch *ds, struct sk_buff *skb, int seq_no)
> >> +{
> >> +	struct mv88e6xxx_chip *chip = ds->priv;
> >> +	struct mv88e6xxx_port *port;
> >> +	__be16 *prodnum;
> >> +	__be16 *format;
> >> +	__be16 *code;
> >> +	__be32 *mib_data;
> >> +	u8 pkt_dev;
> >> +	u8 pkt_prt;
> >> +	int i;
> > 
> > Reverse christmass tree.
> > 
> 
> Will fix. Doesn't checkpatch find these?

No it does not :-(

It is only something which netdev enforces.

> >> +
> >> +	/* Extract response data */
> >> +	format = (__be16 *)&skb->data[0];
> > 
> > You have no idea of the alignment of data, so you should not cast it
> > to a pointer type and dereference it. Take a look at the unaligned
> > helpers.
> > 
> 
> Can you point me to an example please?

#include <asm/unaligned.h>

then you can use functions like get_unaligned_be16(),
get_unaligned_le32(), put_unaligned_le32().

On X86 unaligned accesses are cheap, so these macros do nothing. For
ARM they are expensive so split it into byte accesses.

> I've tested this implementation in a system with multiple switchcores
> and it works.

Cool, there are not many such boards, but RMU really helps these if
they are sharing the same MDIO bus.

     Andrew