linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: <Eugen.Hristev@microchip.com>
Cc: <jic23@kernel.org>, <linux-iio@vger.kernel.org>
Subject: Re: [PATCH 01/11] iio: adc: at91-sama5d2: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
Date: Thu, 27 May 2021 09:48:56 +0100	[thread overview]
Message-ID: <20210527094856.00003d70@Huawei.com> (raw)
In-Reply-To: <0384e41b-a995-d9aa-c077-b71917eca45c@microchip.com>

On Wed, 26 May 2021 17:23:11 +0000
<Eugen.Hristev@microchip.com> wrote:

> On 5/1/21 8:13 PM, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > 
> > To make code more readable, use a structure to express the channel
> > layout and ensure the timestamp is 8 byte aligned.
> > 
> > Found during an audit of all calls of this function.
> > 
> > Fixes: 5e1a1da0f8c9 ("iio: adc: at91-sama5d2_adc: add hw trigger and buffer support")
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Eugen Hristev <eugen.hristev@microchip.com>
> > ---
> >   drivers/iio/adc/at91-sama5d2_adc.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> > index a7826f097b95..d356b515df09 100644
> > --- a/drivers/iio/adc/at91-sama5d2_adc.c
> > +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> > @@ -403,7 +403,8 @@ struct at91_adc_state {
> >          struct at91_adc_dma             dma_st;
> >          struct at91_adc_touch           touch_st;
> >          struct iio_dev                  *indio_dev;
> > -       u16                             buffer[AT91_BUFFER_MAX_HWORDS];
> > +       /* Ensure naturally aligned timestamp */
> > +       u16                             buffer[AT91_BUFFER_MAX_HWORDS] __aligned(8);  
> 
> Hello Jonathan,
> 
> I am preparing to change this buffer to a dynamically allocated 
> buffer... because we want to support several versions of the ADC with 
> this driver, having an arbitrary number of channels..
> 
> You think it's possible to have this alignment when I move to a 
> devm_kzalloc call ?

Hmm. You should be fine, but looking through the docs, guaranteed alignment for
devm_kmalloc is unsigned long long.  Sounds worryingly vague, but c99 (which kernel
uses) guarantees at least 64 bits so that's fine.

However, unless your maximum size is very large, I'd be cynical and just leave it
where it is.  Chances are it won't actually make any difference to the real amount
of memory allocated for at91_adc_state and it'll make your code simpler.

No one minds a buffer being too big :)

Jonathan

> 
> Thanks,
> Eugen
> 
> >          /*
> >           * lock to prevent concurrent 'single conversion' requests through
> >           * sysfs.
> > --
> > 2.31.1
> >   
> 


  reply	other threads:[~2021-05-27  8:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 17:13 [PATCH 00/11] IIO: Alignment fixes part 3 - __aligned(8) used to ensure alignment Jonathan Cameron
2021-05-01 17:13 ` [PATCH 01/11] iio: adc: at91-sama5d2: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Jonathan Cameron
2021-05-26 17:23   ` Eugen.Hristev
2021-05-27  8:48     ` Jonathan Cameron [this message]
2021-05-01 17:13 ` [PATCH 02/11] iio: adc: hx711: " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 03/11] iio: adc: mxs-lradc: " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 04/11] iio: adc: ti-ads8688: Fix alignment of buffer " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 05/11] iio: chemical: atlas: Fix buffer alignment " Jonathan Cameron
2021-05-06  6:44   ` Matt Ranostay
2021-05-13 17:59     ` Jonathan Cameron
2021-05-01 17:13 ` [PATCH 06/11] iio: cros_ec_sensors: Fix alignment of buffer " Jonathan Cameron
2021-05-01 23:58   ` Gwendal Grignou
2021-05-13 18:03     ` Jonathan Cameron
2021-05-01 17:13 ` [PATCH 07/11] iio: potentiostat: lmp91000: " Jonathan Cameron
2021-05-06  6:44   ` Matt Ranostay
2021-05-13 18:04     ` Jonathan Cameron
2021-05-01 17:13 ` [PATCH 08/11] iio: magn: rm3100: " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 09/11] iio: light: vcnl4000: Fix buffer alignment " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 10/11] iio: light: vcnl4035: " Jonathan Cameron
2021-05-01 17:13 ` [PATCH 11/11] iio: prox: isl29501: " Jonathan Cameron
2021-05-13 17:58 ` [PATCH 00/11] IIO: Alignment fixes part 3 - __aligned(8) used to ensure alignment Jonathan Cameron
2021-05-26 17:09   ` Jonathan Cameron
2021-05-26 17:17     ` Andy Shevchenko

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=20210527094856.00003d70@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=Eugen.Hristev@microchip.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@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;
as well as URLs for NNTP newsgroup(s).