diff options
author | David Lechner <dlechner@baylibre.com> | 2024-06-21 15:51:31 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2024-06-22 12:14:33 +0100 |
commit | d4a0055fdc22381fa256e345095e88d134e354c5 (patch) | |
tree | 230e9dcb0562b19d66aec08f8e40c9cc0cb55412 /drivers/spi | |
parent | 9b894d65e9788ece0d51e76d2c184524900f5ec9 (diff) | |
download | lwn-d4a0055fdc22381fa256e345095e88d134e354c5.tar.gz lwn-d4a0055fdc22381fa256e345095e88d134e354c5.zip |
spi: add devm_spi_optimize_message() helper
This adds a new helper function devm_spi_optimize_message() that
automatically registers spi_unoptimize_message() to be called
when the device is removed.
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20240621-devm_spi_optimize_message-v1-2-3f9dcba6e95e@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9bc9fd10d538..32d2a4f3dfca 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -4378,6 +4378,33 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) return ctlr->transfer(spi, message); } +static void devm_spi_unoptimize_message(void *msg) +{ + spi_unoptimize_message(msg); +} + +/** + * devm_spi_optimize_message - managed version of spi_optimize_message() + * @dev: the device that manages @msg (usually @spi->dev) + * @spi: the device that will be used for the message + * @msg: the message to optimize + * Return: zero on success, else a negative error code + * + * spi_unoptimize_message() will automatically be called when the device is + * removed. + */ +int devm_spi_optimize_message(struct device *dev, struct spi_device *spi, + struct spi_message *msg) +{ + int ret; + + ret = spi_optimize_message(spi, msg); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, devm_spi_unoptimize_message, msg); +} + /** * spi_async - asynchronous SPI transfer * @spi: device with which data will be exchanged |