linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'David Miller' <davem@davemloft.net>,
	"ben.dooks@codethink.co.uk" <ben.dooks@codethink.co.uk>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"oneukum@suse.com" <oneukum@suse.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-kernel@lists.codethink.co.uk" 
	<linux-kernel@lists.codethink.co.uk>
Subject: RE: [PATCH] usbnet: smsc95xx: simplify tx_fixup code
Date: Mon, 8 Oct 2018 08:41:49 +0000	[thread overview]
Message-ID: <170d3d23a5c2463fab275d2e871775f3@AcuMS.aculab.com> (raw)
In-Reply-To: <20181005.142412.601607260441380535.davem@davemloft.net>

From: David Miller
> Sent: 05 October 2018 22:24
> 
> From: Ben Dooks <ben.dooks@codethink.co.uk>
> Date: Tue,  2 Oct 2018 17:56:02 +0100
> 
> > -	memcpy(skb->data, &tx_cmd_a, 4);
> > +	ptr = skb_push(skb, 8);
> > +	tx_cmd_a = cpu_to_le32(tx_cmd_a);
> > +	tx_cmd_b = cpu_to_le32(tx_cmd_b);
> > +	memcpy(ptr, &tx_cmd_a, 4);
> > +	memcpy(ptr+4, &tx_cmd_b, 4);
> 
> Even a memcpy() through a void pointer does not guarantee that gcc will
> not emit word sized loads and stores.

True, but only if gcc can 'see' something that would require the
pointer be aligned.
In this case the void pointer comes from an external function
so is fine.

> You must use the get_unaligned()/put_unaligned() facilities to do this
> properly.
> 
> I also agree that making a proper type and structure instead of using
> a void pointer would be better.

The structure would need to be marked 'packed' - since its alignment
isn't guaranteed.
Then you don't need to use put_unaligned().

If it wasn't 'packed' then gcc would implement
memcpy(&hdr->tx_cmd_a, &tx_cmd_a, 4) using an aligned write.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  parent reply	other threads:[~2018-10-08  8:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  9:26 SMSC95XX driver updates Ben Dooks
2018-10-02  9:26 ` [PATCH 1/4] usbnet: smsc95xx: add kconfig for turbo mode Ben Dooks
2018-10-02 12:46   ` Andrew Lunn
2018-10-02  9:26 ` [PATCH 2/4] usbnet: smsc95xx: align tx-buffer to word Ben Dooks
2018-10-02 13:19   ` David Laight
2018-10-02 13:35     ` Ben Dooks
2018-10-02 16:56     ` [PATCH] usbnet: smsc95xx: simplify tx_fixup code Ben Dooks
2018-10-03 13:36       ` David Laight
2018-10-03 16:25         ` Ben Dooks
2018-10-05 21:24       ` David Miller
2018-10-06 11:27         ` Ben Dooks
2018-10-06 17:28           ` David Miller
2018-10-08  8:41         ` David Laight [this message]
2018-10-04 16:53   ` [Linux-kernel] [PATCH 2/4] usbnet: smsc95xx: align tx-buffer to word Ben Hutchings
2018-10-02  9:26 ` [PATCH 3/4] usbnet: smsc95xx: check for csum being in last four bytes Ben Dooks
2018-10-02  9:45   ` Sergei Shtylyov
2018-10-04 16:55   ` [Linux-kernel] " Ben Hutchings
2018-10-02  9:26 ` [PATCH 4/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks

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=170d3d23a5c2463fab275d2e871775f3@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=ben.dooks@codethink.co.uk \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@lists.codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.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;
as well as URLs for NNTP newsgroup(s).