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 v3 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Date: Mon, 1 May 2023 15:50:19 +0100 [thread overview]
Message-ID: <20230501155019.031ff86e@jic23-huawei> (raw)
In-Reply-To: <64728e90-48a7-43d0-b3d3-bfceb94884d7@gmail.com>
On Sat, 29 Apr 2023 16:56:38 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> On 4/29/23 15:59, Mehdi Djait wrote:
> > Hi Matti,
> >
> > On Tue, Apr 25, 2023 at 11:12:11AM +0300, Matti Vaittinen wrote:
> >> On 4/25/23 10:24, Mehdi Djait wrote:
> >>> Hi Matti,
> >>>
> >>> On Tue, Apr 25, 2023 at 09:50:11AM +0300, Matti Vaittinen wrote:
> >>>> On 4/25/23 01:22, Mehdi Djait wrote:
> >>>>> Add the chip_info structure to the driver's private data to hold all
> >>>>> the device specific infos.
> >>>>> Refactor the kx022a driver implementation to make it more generic and
> >>>>> extensible.
> >>>>>
> >>>>> Signed-off-by: Mehdi Djait <mehdi.djait.k@gmail.com>
> >>>>> ---
> >>>>> v3:
> >>>>> - added the change of the buffer's allocation in the __kx022a_fifo_flush
> >>>>> to this patch
> >>>>> - added the chip_info to the struct kx022a_data
> >>>>>
> >>>>> v2:
> >>>>> - mentioned the introduction of the i2c_device_id table in the commit
> >>>>> - get i2c_/spi_get_device_id only when device get match fails
> >>>>> - removed the generic KX_define
> >>>>> - removed the kx022a_device_type enum
> >>>>> - added comments for the chip_info struct elements
> >>>>> - fixed errors pointed out by the kernel test robot
> >>>>>
> >>>>> drivers/iio/accel/kionix-kx022a-i2c.c | 15 +++-
> >>>>> drivers/iio/accel/kionix-kx022a-spi.c | 15 +++-
> >>>>> drivers/iio/accel/kionix-kx022a.c | 114 +++++++++++++++++---------
> >>>>> drivers/iio/accel/kionix-kx022a.h | 54 +++++++++++-
> >>>>> 4 files changed, 147 insertions(+), 51 deletions(-)
> >>>>>
> >>>>> diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c
> >>>>> index 8f23631a1fd3..ce299d0446f7 100644
> >>>>> --- a/drivers/iio/accel/kionix-kx022a-i2c.c
> >>>>> +++ b/drivers/iio/accel/kionix-kx022a-i2c.c
> >>>>> @@ -15,6 +15,7 @@
> >>>>
> >>>> ...
> >>>>
> >>>>
> >>>>> static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
> >>>>> @@ -600,13 +600,17 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
> >>>>> {
> >>>>> struct kx022a_data *data = iio_priv(idev);
> >>>>> struct device *dev = regmap_get_device(data->regmap);
> >>>>> - __le16 buffer[KX022A_FIFO_LENGTH * 3];
> >>>>> + __le16 *buffer;
> >>>>> uint64_t sample_period;
> >>>>> int count, fifo_bytes;
> >>>>> bool renable = false;
> >>>>> int64_t tstamp;
> >>>>> int ret, i;
> >>>>> + buffer = kmalloc(data->chip_info->fifo_length * KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL);
> >>>>> + if (!buffer)
> >>>>> + return -ENOMEM;
> >>>>
> >>>> Do you think we could get rid of allocating and freeing the buffer for each
> >>>> flush? I feel it is a bit wasteful, and with high sampling frequencies this
> >>>> function can be called quite often. Do you think there would be a way to
> >>>> either use stack (always reserve big enough buffer no matter which chip we
> >>>> have - or is the buffer too big to be safely taken from the stack?), or a
> >>>> buffer stored in private data and allocated at probe or buffer enable?
> >>>
> >>> I tried using the same allocation as before but a device like the KX127
> >>> has a fifo_length of 342 (compared to 86 for kx132, and 43 for kx022a).
> >>> Allocating this much using the stack will result in a Warning.
> >>>
> >>
> >> Right. Maybe you could then have the buffer in private-data and allocate it
> >> in buffer pre-enable? Do you think that would work?
> >
> > Do you mean add a new function kx022a_buffer_preenable to iio_buffer_setup_ops ?
>
> Sorry. I thought the kx022a already implemented the pre-enable callback
> but it was the postenable. I was mistaken.
Separation between what should be done in preenable and postenable has been
vague for a long time. These days only really matters if you need to
order them wrt updating the scan mode I think.
>
> > Would adding the allocation to kx022a_fifo_enable and the free to
> > kx022a_fifo_disable be a good option also ?
> Yes. I think that should work!
Agreed that these allocations should be taken out of this hot path.
Either of these options should work so up to you.
>
> Yours,
> -- Matti
>
>
next prev parent reply other threads:[~2023-05-01 14:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 22:22 [PATCH v3 0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 1/7] dt-bindings: iio: Add " Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 2/7] iio: accel: kionix-kx022a: Remove blank lines Mehdi Djait
2023-04-25 5:26 ` Matti Vaittinen
2023-04-24 22:22 ` [PATCH v3 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Mehdi Djait
2023-04-25 5:31 ` Matti Vaittinen
2023-05-01 14:42 ` Jonathan Cameron
2023-04-25 13:40 ` Andy Shevchenko
2023-04-29 13:10 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Mehdi Djait
2023-04-25 6:50 ` Matti Vaittinen
2023-04-25 7:24 ` Mehdi Djait
2023-04-25 8:12 ` Matti Vaittinen
2023-04-29 12:59 ` Mehdi Djait
2023-04-29 13:56 ` Matti Vaittinen
2023-05-01 14:50 ` Jonathan Cameron [this message]
2023-05-07 20:45 ` Mehdi Djait
2023-05-08 6:12 ` Matti Vaittinen
2023-04-25 15:57 ` Andi Shyti
2023-04-29 13:07 ` Mehdi Djait
2023-04-30 17:49 ` Jonathan Cameron
2023-05-02 19:41 ` Andy Shevchenko
2023-05-05 18:12 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Mehdi Djait
2023-04-25 7:07 ` Matti Vaittinen
2023-04-25 7:26 ` Mehdi Djait
2023-04-24 22:22 ` [PATCH v3 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-04-25 8:06 ` Matti Vaittinen
2023-05-01 15:04 ` Jonathan Cameron
2023-05-01 14:56 ` Jonathan Cameron
2023-05-05 18:11 ` Mehdi Djait
2023-05-06 16:46 ` Jonathan Cameron
2023-05-07 14:56 ` Mehdi Djait
2023-05-13 17:13 ` 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=20230501155019.031ff86e@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