diff options
author | Mark Brown <broonie@kernel.org> | 2024-06-23 13:14:18 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2024-06-23 13:14:18 +0100 |
commit | 17436001a6bc42c7f55dc547ca5b1a873208d91d (patch) | |
tree | 186b872edc5080b90ef1f8fb88f774d4f242775f /drivers/spi | |
parent | 5d0c35feea339e4a3a9c9e99731e4d49ad5ee329 (diff) | |
parent | d4a0055fdc22381fa256e345095e88d134e354c5 (diff) | |
download | lwn-17436001a6bc42c7f55dc547ca5b1a873208d91d.tar.gz lwn-17436001a6bc42c7f55dc547ca5b1a873208d91d.zip |
spi: add devm_spi_optimize_message() helper
Merge series from David Lechner <dlechner@baylibre.com>:
In the IIO subsystem, we are finding that it is common to call
spi_optimize_message() during driver probe since the SPI message
doesn't change for the lifetime of the driver. This patch adds a
devm_spi_optimize_message() helper to simplify this common pattern.
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 54cbe652a4df..3f953504244b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -4358,6 +4358,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 |