From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Mehdi Djait <mehdi.djait@linux.intel.com>
Cc: "Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
"Matti Vaittinen" <matti.vaittinen@linux.dev>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
"Mehdi Djait" <mehdi.djait.k@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kalle Niemi" <kaleposti@gmail.com>,
"Topi Sonkajärvi" <sonkajarvi@hotmail.com>
Subject: Re: [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix statey
Date: Fri, 14 Aug 2026 10:39:48 +0300 [thread overview]
Message-ID: <5424d7ba-861b-44ea-ae92-f4b334958a71@gmail.com> (raw)
In-Reply-To: <anxcithfWakkARl8@mdjait-mobl>
On 12/08/2026 14:47, Mehdi Djait wrote:
> Hi Matti,
>
> Thank you for the patch!
>
> On Mon, Aug 10, 2026 at 10:55:03AM +0300, Matti Vaittinen wrote:
>> From: Matti Vaittinen <mazziesaccount@gmail.com>
>>
>> The driver allocates memory for samples at buffer enable path. If regmap
>> operation fails in the kx022a_fifo_enable() at the buffer enable path, the
>> allocated memory is never freed. Furthermore, the state information and
>> previous hardware configuration(s) aren't undone, potentially leaving
>> WMI interrupts and buffers enabled, or driver state flags wrong.
>>
>> Free the memory and revert the hardware configuration and state flags on
>> error path.
>
> Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>> Fixes: e7123a4dfcd7 ("iio: accel: kionix-kx022a: Refactor driver and add chip_info structure")
>> ---
>> drivers/iio/accel/kionix-kx022a.c | 27 ++++++++++++++++++++++-----
>> 1 file changed, 22 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
>> index 8a13f78aeab0..49e8b4b943da 100644
>> --- a/drivers/iio/accel/kionix-kx022a.c
>> +++ b/drivers/iio/accel/kionix-kx022a.c
>> @@ -980,26 +980,43 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
>
> Do you think this error handling should also be done for kx022a_fifo_disable():
> in case __kx022a_turn_on_off() or one of the regmap_clear_bits() fails before
> we free the fifo_buffer ?
Good question. I am not really sure what IIO thinks if disable returns
an error. Should the driver be in a state where it can handle re-try of
a disable (Eg, a new call)?
If so, then returning an error from "turning on" the IC
return __kx022a_turn_on_off(data, true);
is problematic as fifo_buffer is already freed. New call to the disable
would then cause a double free. If this is the case, it should be fixed,
perhaps by just "NULLing" the fifo_buffer after the free.
If IIO does not allow "re-disable", then failures before the free() will
cause a memory leak. Furthermore, the hardware state may be left
inconsistent. Considering that such errors should be quite unexpected,
and probably a symptom of shomething being off - I am not really
terribly worried about the leak or inconsistent state - and I don't
really know what else the driver could be except re-try - which might be
a never ending story if problem persists.
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
next prev parent reply other threads:[~2026-08-14 7:39 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
2026-08-10 7:49 ` [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm Matti Vaittinen
2026-08-17 1:17 ` Jonathan Cameron
2026-08-10 7:50 ` [PATCH 02/12] iio: adc: rohm-bd79124: Fix channel initialization Matti Vaittinen
2026-08-17 1:23 ` Jonathan Cameron
2026-08-10 7:50 ` [PATCH 03/12] iio: adc: rohm-bd79124: Fix GPIO mask check Matti Vaittinen
2026-08-17 1:23 ` Jonathan Cameron
2026-08-10 7:51 ` [PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop Matti Vaittinen
2026-08-17 1:27 ` Jonathan Cameron
2026-08-10 7:51 ` [PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE Matti Vaittinen
2026-08-17 1:32 ` Jonathan Cameron
2026-08-17 5:06 ` Matti Vaittinen
2026-08-10 7:52 ` [PATCH 06/12] iio: pressure: rohm-bm1390: Return error when read fails Matti Vaittinen
2026-08-17 1:34 ` Jonathan Cameron
2026-08-10 7:53 ` [PATCH 07/12] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization Matti Vaittinen
2026-08-10 20:06 ` Andy Shevchenko
2026-08-11 9:05 ` Matti Vaittinen
2026-08-11 10:08 ` Andy Shevchenko
2026-08-17 1:19 ` Jonathan Cameron
2026-08-17 5:43 ` Matti Vaittinen
2026-08-23 22:38 ` Jonathan Cameron
2026-08-17 1:12 ` Jonathan Cameron
2026-08-17 5:51 ` Matti Vaittinen
2026-08-18 2:01 ` Jonathan Cameron
2026-08-10 7:53 ` [PATCH 08/12] iio: light: rohm-bu27034: Fix error return Matti Vaittinen
2026-08-17 1:35 ` Jonathan Cameron
2026-08-10 7:54 ` [PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error Matti Vaittinen
2026-08-10 20:09 ` Andy Shevchenko
2026-08-11 9:07 ` Matti Vaittinen
2026-08-10 7:54 ` [PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check Matti Vaittinen
2026-08-12 11:43 ` Mehdi Djait
2026-08-17 1:37 ` Jonathan Cameron
2026-08-10 7:55 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state Matti Vaittinen
2026-08-12 11:47 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix statey Mehdi Djait
2026-08-14 7:39 ` Matti Vaittinen [this message]
2026-08-17 1:49 ` Jonathan Cameron
2026-08-17 1:45 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state Jonathan Cameron
2026-08-17 11:37 ` Matti Vaittinen
2026-08-10 7:55 ` [PATCH 12/12] iio: accel: kionix-kx022a: Fix IPOL macro name Matti Vaittinen
2026-08-12 11:53 ` Mehdi Djait
2026-08-14 7:43 ` Matti Vaittinen
2026-08-17 1:54 ` Jonathan Cameron
2026-08-17 11:43 ` Matti Vaittinen
2026-08-18 2:03 ` 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=5424d7ba-861b-44ea-ae92-f4b334958a71@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jic23@kernel.org \
--cc=kaleposti@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=matti.vaittinen@linux.dev \
--cc=mehdi.djait.k@gmail.com \
--cc=mehdi.djait@linux.intel.com \
--cc=nuno.sa@analog.com \
--cc=sonkajarvi@hotmail.com \
/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