public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v1 1/2] iio: core: Leave private pointer NULL when no private data supplied
Date: Sat, 9 Mar 2024 18:37:00 +0000	[thread overview]
Message-ID: <20240309183700.60133d78@jic23-huawei> (raw)
In-Reply-To: <20240304140650.977784-2-andriy.shevchenko@linux.intel.com>

On Mon,  4 Mar 2024 16:04:32 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> In iio_device_alloc() when size of the private data is 0,
> the private pointer is calculated to point behind the valid data.
> Leave it NULL when no private data supplied.
> 
> Fixes: 6d4ebd565d15 ("iio: core: wrap IIO device into an iio_dev_opaque object")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Fix is a strong word given any driver trying to access the pointer in this case
will be broken anyway.  I don't mind it being backported as it'll make bugs
easier to identify but I'm not rushing it in.

Otherwise seems like a sensible bit of tidying up.

Jonathan

> ---
>  drivers/iio/industrialio-core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 4302093b92c7..8684ba246969 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1654,8 +1654,10 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
>  		return NULL;
>  
>  	indio_dev = &iio_dev_opaque->indio_dev;
> -	indio_dev->priv = (char *)iio_dev_opaque +
> -		ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN);
> +
> +	if (sizeof_priv)
> +		indio_dev->priv = (char *)iio_dev_opaque +
> +			ALIGN(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN);
>  
>  	indio_dev->dev.parent = parent;
>  	indio_dev->dev.type = &iio_device_type;


  parent reply	other threads:[~2024-03-09 18:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 14:04 [PATCH v1 0/2] iio: core: Fix and cleanup to iio_device_alloc() Andy Shevchenko
2024-03-04 14:04 ` [PATCH v1 1/2] iio: core: Leave private pointer NULL when no private data supplied Andy Shevchenko
2024-03-04 14:39   ` David Lechner
2024-03-09 18:37   ` Jonathan Cameron [this message]
2024-03-04 14:04 ` [PATCH v1 2/2] iio: core: Calculate alloc_size only once in iio_device_alloc() Andy Shevchenko
2024-03-04 14:38   ` David Lechner
2024-03-09 18:42   ` Christophe JAILLET
2024-03-09 18:38 ` [PATCH v1 0/2] iio: core: Fix and cleanup to iio_device_alloc() Jonathan Cameron

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=20240309183700.60133d78@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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