From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mark Brown <broonie@kernel.org>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/1] spi: Simplify devm_spi_*_controller()
Date: Thu, 8 Jan 2026 18:51:45 +0100 [thread overview]
Message-ID: <20260108175145.3535441-1-andriy.shevchenko@linux.intel.com> (raw)
Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional changes.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/spi/spi.c | 47 ++++++++++++++++++-----------------------------
1 file changed, 18 insertions(+), 29 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index e25df9990f82..f077ea74e299 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3079,9 +3079,9 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
}
EXPORT_SYMBOL_GPL(__spi_alloc_controller);
-static void devm_spi_release_controller(struct device *dev, void *ctlr)
+static void devm_spi_release_controller(void *ctlr)
{
- spi_controller_put(*(struct spi_controller **)ctlr);
+ spi_controller_put(ctlr);
}
/**
@@ -3103,21 +3103,18 @@ struct spi_controller *__devm_spi_alloc_controller(struct device *dev,
unsigned int size,
bool target)
{
- struct spi_controller **ptr, *ctlr;
-
- ptr = devres_alloc(devm_spi_release_controller, sizeof(*ptr),
- GFP_KERNEL);
- if (!ptr)
- return NULL;
+ struct spi_controller *ctlr;
+ int ret;
ctlr = __spi_alloc_controller(dev, size, target);
- if (ctlr) {
- ctlr->devm_allocated = true;
- *ptr = ctlr;
- devres_add(dev, ptr);
- } else {
- devres_free(ptr);
- }
+ if (!ctlr)
+ return NULL;
+
+ ret = devm_add_action_or_reset(dev, devm_spi_release_controller, ctlr);
+ if (ret)
+ return NULL;
+
+ ctlr->devm_allocated = true;
return ctlr;
}
@@ -3378,9 +3375,9 @@ int spi_register_controller(struct spi_controller *ctlr)
}
EXPORT_SYMBOL_GPL(spi_register_controller);
-static void devm_spi_unregister(struct device *dev, void *res)
+static void devm_spi_unregister_controller(void *ctlr)
{
- spi_unregister_controller(*(struct spi_controller **)res);
+ spi_unregister_controller(ctlr);
}
/**
@@ -3398,22 +3395,14 @@ static void devm_spi_unregister(struct device *dev, void *res)
int devm_spi_register_controller(struct device *dev,
struct spi_controller *ctlr)
{
- struct spi_controller **ptr;
int ret;
- ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
- if (!ptr)
- return -ENOMEM;
-
ret = spi_register_controller(ctlr);
- if (!ret) {
- *ptr = ctlr;
- devres_add(dev, ptr);
- } else {
- devres_free(ptr);
- }
+ if (ret)
+ return ret;
+
+ return devm_add_action_or_reset(dev, devm_spi_unregister_controller, ctlr);
- return ret;
}
EXPORT_SYMBOL_GPL(devm_spi_register_controller);
--
2.50.1
next reply other threads:[~2026-01-08 17:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 17:51 Andy Shevchenko [this message]
2026-01-09 15:30 ` [PATCH v1 1/1] spi: Simplify devm_spi_*_controller() Mark Brown
2026-03-24 14:55 ` Felix Gu
2026-03-25 9:54 ` Andy Shevchenko
2026-03-25 10:22 ` Felix Gu
2026-03-25 11:36 ` Andy Shevchenko
2026-03-25 15:03 ` Johan Hovold
2026-03-26 9:29 ` Andy Shevchenko
2026-03-25 14:59 ` Johan Hovold
-- strict thread matches above, loose matches on Subject: below --
2025-11-27 19:51 Andy Shevchenko
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=20260108175145.3535441-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.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