Linux Kernel Mentees list
 help / color / mirror / Atom feed
From: SeungJu Cheon <suunj1331@gmail.com>
To: jic23@kernel.org, linux-iio@vger.kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	apokusinski01@gmail.com, me@brighamcampbell.com,
	skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev,
	SeungJu Cheon <suunj1331@gmail.com>
Subject: [PATCH 1/4] iio: pressure: mpl3115: convert probe to fully devm managed
Date: Sat, 30 May 2026 20:39:35 +0900	[thread overview]
Message-ID: <20260530113938.171540-2-suunj1331@gmail.com> (raw)
In-Reply-To: <20260530113938.171540-1-suunj1331@gmail.com>

Convert probe to use devm-managed resource allocation,
removing the need for an explicit remove callback.

Replace iio_triggered_buffer_setup() and
iio_device_register() with their devm equivalents.
Register a devm action to return the device to standby,
replacing the cleanup previously performed in
mpl3115_remove().

Move mpl3115_standby() and suspend/resume helpers above
probe to satisfy declaration ordering requirements.

No functional change.

Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
---
 drivers/iio/pressure/mpl3115.c | 81 ++++++++++++++++------------------
 1 file changed, 39 insertions(+), 42 deletions(-)

diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index aeac1586f12e..befb6d48efa9 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -691,6 +691,33 @@ static int mpl3115_trigger_probe(struct mpl3115_data *data,
 	return 0;
 }
 
+static int mpl3115_standby(struct mpl3115_data *data)
+{
+	return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
+		data->ctrl_reg1 & ~MPL3115_CTRL1_ACTIVE);
+}
+
+static void mpl3115_standby_action(void *d)
+{
+	mpl3115_standby(d);
+}
+
+static int mpl3115_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+
+	return mpl3115_standby(iio_priv(indio_dev));
+}
+
+static int mpl3115_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+	struct mpl3115_data *data = iio_priv(indio_dev);
+
+	return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
+					 data->ctrl_reg1);
+}
+
 static int mpl3115_probe(struct i2c_client *client)
 {
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
@@ -730,53 +757,24 @@ static int mpl3115_probe(struct i2c_client *client)
 	if (ret < 0)
 		return ret;
 
-	ret = mpl3115_trigger_probe(data, indio_dev);
+	ret = devm_add_action_or_reset(&client->dev, mpl3115_standby_action,
+				       data);
 	if (ret)
 		return ret;
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
-		mpl3115_trigger_handler, NULL);
-	if (ret < 0)
+	ret = mpl3115_trigger_probe(data, indio_dev);
+	if (ret)
 		return ret;
 
-	ret = iio_device_register(indio_dev);
-	if (ret < 0)
-		goto buffer_cleanup;
-	return 0;
-
-buffer_cleanup:
-	iio_triggered_buffer_cleanup(indio_dev);
-	return ret;
-}
-
-static int mpl3115_standby(struct mpl3115_data *data)
-{
-	return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
-		data->ctrl_reg1 & ~MPL3115_CTRL1_ACTIVE);
-}
-
-static void mpl3115_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-	mpl3115_standby(iio_priv(indio_dev));
-}
-
-static int mpl3115_suspend(struct device *dev)
-{
-	return mpl3115_standby(iio_priv(i2c_get_clientdata(
-		to_i2c_client(dev))));
-}
-
-static int mpl3115_resume(struct device *dev)
-{
-	struct mpl3115_data *data = iio_priv(i2c_get_clientdata(
-		to_i2c_client(dev)));
+	ret = devm_iio_triggered_buffer_setup(&client->dev,
+				      indio_dev,
+				      NULL,
+				      mpl3115_trigger_handler,
+				      NULL);
+	if (ret)
+		return ret;
 
-	return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
-		data->ctrl_reg1);
+	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(mpl3115_pm_ops, mpl3115_suspend,
@@ -801,7 +799,6 @@ static struct i2c_driver mpl3115_driver = {
 		.pm	= pm_sleep_ptr(&mpl3115_pm_ops),
 	},
 	.probe = mpl3115_probe,
-	.remove = mpl3115_remove,
 	.id_table = mpl3115_id,
 };
 module_i2c_driver(mpl3115_driver);
-- 
2.52.0


  reply	other threads:[~2026-05-30 11:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30 11:39 [PATCH 0/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 11:39 ` SeungJu Cheon [this message]
2026-05-30 12:12   ` [PATCH 1/4] iio: pressure: mpl3115: convert probe to fully devm managed Andy Shevchenko
2026-05-31 10:46     ` SeungJu Cheon
2026-05-30 15:10   ` Jonathan Cameron
2026-05-31 10:49     ` SeungJu Cheon
2026-05-31 14:29       ` Jonathan Cameron
2026-05-30 11:39 ` [PATCH 2/4] iio: pressure: mpl3115: clean up interrupt handling and locking SeungJu Cheon
2026-05-30 12:33   ` Andy Shevchenko
2026-05-31 10:55     ` SeungJu Cheon
2026-05-30 15:23   ` Jonathan Cameron
2026-05-31 10:59     ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 3/4] iio: pressure: mpl3115: generalize interrupt pin routing SeungJu Cheon
2026-05-30 12:39   ` Andy Shevchenko
2026-05-31 11:01     ` SeungJu Cheon
2026-05-30 15:32   ` Jonathan Cameron
2026-05-31 11:08     ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 4/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 13:32   ` Andy Shevchenko
2026-05-30 15:43     ` Jonathan Cameron
2026-06-02 10:31       ` Andy Shevchenko
2026-05-31 11:15     ` SeungJu Cheon
2026-05-30 16:05   ` Jonathan Cameron
2026-05-31 12:38     ` SeungJu Cheon

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=20260530113938.171540-2-suunj1331@gmail.com \
    --to=suunj1331@gmail.com \
    --cc=andy@kernel.org \
    --cc=apokusinski01@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=me@brighamcampbell.com \
    --cc=nuno.sa@analog.com \
    --cc=skhan@linuxfoundation.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