devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Mehdi Djait <mehdi.djait.k@gmail.com>,
	krzysztof.kozlowski+dt@linaro.org,
	andriy.shevchenko@linux.intel.com, robh+dt@kernel.org,
	lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Date: Sun, 28 May 2023 17:49:03 +0100	[thread overview]
Message-ID: <20230528174903.6a9c2533@jic23-huawei> (raw)
In-Reply-To: <682e84b6-9912-ecb9-9ca2-9d96f511c22d@gmail.com>


...

> > @@ -762,6 +763,8 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
> >   {
> >   	int ret = 0;
> >   
> > +	kfree(data->fifo_buffer);  
> 
> Should we have the kfree only after the sensor is disabled? I wonder if 
> we in theory have here a time window where the buffer is freed but the 
> measurement is still running and - with a lots of bad luck - can result 
> measurement being written to a freed buffer? Perhaps move the kfree to 
> be done only after the measurement has been stopped?
> 
> Other than that, this is looking good to me.
> 
Agreed. Even if it's not a bug as such, it is better to keep the order
of this function as close as possible to the reverse of what happens in
*_fifo_enabled() as easier to reason about if that's the case.

> > +
> >   	ret = kx022a_turn_off_lock(data);
> >   	if (ret)
> >   		return ret;
> > @@ -770,7 +773,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
> >   	if (ret)
> >   		goto unlock_out;
> >   
> > -	ret = regmap_clear_bits(data->regmap, KX022A_REG_BUF_CNTL2,
> > +	ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
> >   				KX022A_MASK_BUF_EN);
> >   	if (ret)
> >   		goto unlock_out;
> > @@ -801,6 +804,12 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
> >   {
> >   	int ret;
> >   
> > +	data->fifo_buffer = kmalloc(data->chip_info->fifo_length *
> > +				    KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL);
> > +
> > +	if (!data->fifo_buffer)
> > +		return -ENOMEM;
> > +
> >   	ret = kx022a_turn_off_lock(data);
> >   	if (ret)
> >   		return ret;
> > @@ -811,7 +820,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
> >   		goto unlock_out;
> >   
> >   	/* Enable buffer */
> > -	ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2,
> > +	ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
> >   			      KX022A_MASK_BUF_EN);
> >   	if (ret)
> >   		goto unlock_out;

...



  reply	other threads:[~2023-05-28 16:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 14:30 [PATCH v4 0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 1/7] dt-bindings: iio: Add " Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 2/7] iio: accel: kionix-kx022a: Remove blank lines Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Mehdi Djait
2023-05-26 16:35   ` Matti Vaittinen
2023-05-26 14:30 ` [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Mehdi Djait
2023-05-26 17:04   ` Matti Vaittinen
2023-05-28 16:49     ` Jonathan Cameron [this message]
2023-05-27 13:39   ` Andy Shevchenko
2023-05-28 16:55   ` Jonathan Cameron
2023-05-26 14:30 ` [PATCH v4 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Mehdi Djait
     [not found] <cover.1685111274.git.mehdi.djait.k@gmail.com>
2023-05-26 14:30 ` [PATCH v4 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-05-26 14:42   ` Mehdi Djait
2023-05-26 17:13   ` Matti Vaittinen
2023-05-27  8:24   ` Andy Shevchenko
2023-05-28 16:59   ` 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=20230528174903.6a9c2533@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=mehdi.djait.k@gmail.com \
    --cc=robh+dt@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).