[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230528174903.6a9c2533@jic23-huawei>
Date: Sun, 28 May 2023 17:49:03 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Matti Vaittinen <mazziesaccount@...il.com>
Cc: Mehdi Djait <mehdi.djait.k@...il.com>,
krzysztof.kozlowski+dt@...aro.org,
andriy.shevchenko@...ux.intel.com, robh+dt@...nel.org,
lars@...afoo.de, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org
Subject: Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and
add chip_info structure
...
> > @@ -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;
...
Powered by blists - more mailing lists