From: Arnav Kapoor <kapoorarnav43@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
"Wang Shuaijie" <wangshuaijie@awinic.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Arnav Kapoor" <kapoorarnav43@gmail.com>
Subject: [PATCH 3/4] iio: proximity: aw96103: wait for the configuration load before freeing
Date: Thu, 26 Nov 2026 11:00:27 +0530 [thread overview]
Message-ID: <20261126053033.603086-4-kapoorarnav43@gmail.com> (raw)
In-Reply-To: <20261126053033.603086-1-kapoorarnav43@gmail.com>
aw96103_i2c_probe() loads the register configuration with
request_firmware_nowait(), and aw96103_cfg_update() runs later and
writes to the driver data and the chip. Nothing waits for it: if probe
fails after the request (e.g. aw96103_interrupt_init() fails because the
device has no interrupt), or the driver is unbound before the callback
has run, the devm-allocated iio_dev that holds that data is freed first,
and the callback then uses freed memory. The regmap and the vcc supply
it uses are devm-managed as well.
Signal a completion at the end of aw96103_cfg_update() and wait for it
in a devm action added right after the request, so it runs before any
of those resources are released.
Fixes: 07b241262dca ("iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
drivers/iio/proximity/aw96103.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
index 504e92ab9b07..b4aa31a65369 100644
--- a/drivers/iio/proximity/aw96103.c
+++ b/drivers/iio/proximity/aw96103.c
@@ -8,6 +8,7 @@
*/
#include <linux/bits.h>
#include <linux/bitfield.h>
+#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
@@ -118,6 +119,8 @@ struct aw96103 {
struct aw_channels_info channels_arr[6];
unsigned int max_channels;
unsigned int chan_en;
+ /* Signalled when the asynchronous configuration load has finished */
+ struct completion cfg_done;
};
static const unsigned int aw96103_reg_default[] = {
@@ -605,7 +608,7 @@ static void aw96103_cfg_update(const struct firmware *fw, void *data)
ret = aw96103_para_loaded(aw96103);
if (ret) {
dev_err(aw96103->dev, "load param error.\n");
- return;
+ goto out;
}
}
@@ -615,6 +618,16 @@ static void aw96103_cfg_update(const struct firmware *fw, void *data)
else
aw96103->channels_arr[i].used = false;
}
+
+out:
+ complete(&aw96103->cfg_done);
+}
+
+static void aw96103_wait_cfg_update(void *data)
+{
+ struct aw96103 *aw96103 = data;
+
+ wait_for_completion(&aw96103->cfg_done);
}
static int aw96103_sw_reset(struct aw96103 *aw96103)
@@ -811,12 +824,19 @@ static int aw96103_i2c_probe(struct i2c_client *i2c)
if (ret)
return ret;
+ init_completion(&aw96103->cfg_done);
ret = request_firmware_nowait(THIS_MODULE, true, "aw96103_0.bin",
aw96103->dev, GFP_KERNEL, aw96103,
aw96103_cfg_update);
if (ret)
return ret;
+ /* The callback uses aw96103, so it must finish before that is freed */
+ ret = devm_add_action_or_reset(aw96103->dev, aw96103_wait_cfg_update,
+ aw96103);
+ if (ret)
+ return ret;
+
ret = aw96103_interrupt_init(indio_dev, i2c);
if (ret)
return ret;
--
2.53.0
next prev parent reply other threads:[~2026-11-26 5:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 5:30 [PATCH 0/4] iio: proximity: aw96103: fix diff sign, missing config, async config lifetime and event values Arnav Kapoor
2026-11-26 5:30 ` [PATCH 1/4] iio: proximity: aw96103: report negative proximity diff values Arnav Kapoor
2026-11-26 5:30 ` [PATCH 2/4] iio: proximity: aw96103: use the default configuration without firmware Arnav Kapoor
2026-11-26 5:30 ` Arnav Kapoor [this message]
2026-11-26 5:30 ` [PATCH 4/4] iio: proximity: aw96103: reject out-of-range debounce and hysteresis values Arnav Kapoor
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=20261126053033.603086-4-kapoorarnav43@gmail.com \
--to=kapoorarnav43@gmail.com \
--cc=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=nuno.sa@analog.com \
--cc=wangshuaijie@awinic.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
all inboxes | Powered by JetHome®