diff options
author | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2024-06-30 12:36:58 +0200 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2024-06-30 12:36:58 +0200 |
commit | 4f291b30163737103e60bdc7c4d62a7121b0d715 (patch) | |
tree | 98e4b71f0307d13f407b7af93cb37c678f6010c2 /drivers | |
parent | Documentation: iio: Document high-speed DMABUF based API (diff) | |
parent | spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) (diff) | |
download | linux-4f291b30163737103e60bdc7c4d62a7121b0d715.tar.xz linux-4f291b30163737103e60bdc7c4d62a7121b0d715.zip |
Merge tag 'spi-devm-optimize' into togreg
spi: add devm_spi_optimize_message() helper
Helper 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')
-rw-r--r-- | drivers/spi/spi.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9bc9fd10d538..93f59ebb5b79 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -4378,6 +4378,34 @@ 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); +} +EXPORT_SYMBOL_GPL(devm_spi_optimize_message); + /** * spi_async - asynchronous SPI transfer * @spi: device with which data will be exchanged |