From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Matti Vaittinen <mazziesaccount@gmail.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>,
"Mehdi Djait" <mehdi.djait.k@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/4] iio: accel: kionix-kx022a: Prevent memory leak and fix state
Date: Fri, 28 Aug 2026 10:56:53 +0300 [thread overview]
Message-ID: <apE_RZJu37iMuWnJ@ashevche-desk.local> (raw)
In-Reply-To: <9e4453fcc00df6ec988207df8916226d18aecb20.1787901813.git.mazziesaccount@gmail.com>
On Fri, Aug 28, 2026 at 10:40:51AM +0300, Matti Vaittinen wrote:
> 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.
...
> static int kx022a_fifo_enable(struct kx022a_data *data)
With
struct regmap *map = data->regmap;
> guard(mutex)(&data->mutex);
> ret = __kx022a_turn_on_off(data, false);
> if (ret)
> - return ret;
> + goto err_free_out;
>
> /* Update watermark to HW */
> ret = kx022a_fifo_set_wmi(data);
> if (ret)
> - return ret;
> + goto err_wmi_out;
>
> /* Enable buffer */
> ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
> KX022A_MASK_BUF_EN);
> if (ret)
> - return ret;
> + goto err_wmi_out;
>
> data->state |= KX022A_STATE_FIFO;
> ret = regmap_set_bits(data->regmap, data->ien_reg,
> KX022A_MASK_WMI);
> if (ret)
> - return ret;
> + goto err_buf_en_out;
>
> - return __kx022a_turn_on_off(data, true);
> + ret = __kx022a_turn_on_off(data, true);
> + if (ret)
> + goto err_on_out;
> +
> + return ret;
> +
> +err_on_out:
> + regmap_clear_bits(data->regmap, data->ien_reg,
> + KX022A_MASK_WMI);
in particular this will be
regmap_clear_bits(map, data->ien_reg, KX022A_MASK_WMI);
> +err_buf_en_out:
> + regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
> + KX022A_MASK_BUF_EN);
regmap_clear_bits(map, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN);
Which saves a single line, and the followup may shorten the existing code even
more.
> + data->state &= ~KX022A_STATE_FIFO;
> +err_wmi_out:
> + __kx022a_turn_on_off(data, true);
> +err_free_out:
> + kfree(data->fifo_buffer);
> +
> + return ret;
> }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-08-28 7:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 7:40 [PATCH v2 0/4] ROHM IIO fixes Matti Vaittinen
2026-08-28 7:40 ` [PATCH v2 1/4] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization Matti Vaittinen
2026-08-28 7:40 ` [PATCH v2 2/4] iio: light: rohm-bu27034: Fix infinite delay on error Matti Vaittinen
2026-08-28 7:53 ` Andy Shevchenko
2026-08-28 9:46 ` Matti Vaittinen
2026-08-28 11:01 ` Andy Shevchenko
2026-08-30 1:16 ` Jonathan Cameron
2026-08-30 9:32 ` Matti Vaittinen
2026-08-28 7:40 ` [PATCH v2 3/4] iio: accel: kionix-kx022a: Prevent memory leak and fix state Matti Vaittinen
2026-08-28 7:56 ` Andy Shevchenko [this message]
2026-08-28 9:51 ` Matti Vaittinen
2026-08-30 1:22 ` Jonathan Cameron
2026-08-30 9:33 ` Matti Vaittinen
2026-08-28 7:41 ` [PATCH v2 4/4] iio: accel: kionix-kx022a: Fix IPOL macro name Matti Vaittinen
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=apE_RZJu37iMuWnJ@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=matti.vaittinen@linux.dev \
--cc=mazziesaccount@gmail.com \
--cc=mehdi.djait.k@gmail.com \
--cc=nuno.sa@analog.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