spi: Clean up probe and remove functions
PATCH 1/1 spi: Clean up probe and remove functions
While backporting 33cf00e5 ("spi: attach/detach SPI device to the ACPI power domain"), I noticed that the code changes were suboptimal:
* Why use &spi->dev when we have dev at hand?
* After fixing the above, spi is used only once, so we don't really need a local variable for it.
This results in the following clean-up.
---
Untested, no hardware.
drivers/spi/spi.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/spi/spi.c +5 -7
@@ -255,13 +255,12 @@ EXPORT_SYMBOL_GPL(spi_bus_type);static int spi_drv_probe (struct device *dev) {const struct spi_driver *sdrv =to_spi_driver (dev->driver); -struct spi_device *spi =to_spi_device (dev);int ret; -acpi_dev_pm_attach (&spi->dev, true); - ret = sdrv->probe (spi); +acpi_dev_pm_attach (dev, true); + ret = sdrv->probe (to_spi_device (dev));if (ret) -acpi_dev_pm_detach (&spi->dev, true); +acpi_dev_pm_detach (dev, true);return ret; }
@@ -269,11 +268,10 @@ static int spi_drv_probe(struct device *static int spi_drv_remove (struct device *dev) {const struct spi_driver *sdrv =to_spi_driver (dev->driver); -struct spi_device *spi =to_spi_device (dev);int ret; - ret = sdrv->remove (spi); -acpi_dev_pm_detach (&spi->dev, true); + ret = sdrv->remove (to_spi_device (dev)); +acpi_dev_pm_detach (dev, true);return ret; }
Signature · 6 lines
Jean Delvare Suse L3 Support -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Rafael J. Wysocki
Acked-byQuoted 5 lines · Jean Delvare
While backporting
33cf00e5("spi: attach/detach SPI device to the ACPI power domain"), I noticed that the code changes were suboptimal:* Why use
&spi->devwhen we have dev at hand?
Quoted 8 lines
* After fixing the above, spi is used only once, so we don't really need a local variable for it.
This results in the following clean-up.
Signed-off-by Jean Delvare <[email protected]>Cc Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>Cc Mark Brown <[email protected]>
Quoted 31 lines
---
Untested, no hardware.drivers/spi/spi.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/spi/spi.c +3
-4@@ -255,13 +255,12 @@ EXPORT_SYMBOL_GPL(spi_bus_type);static int spi_drv_probe (struct device *dev) {const struct spi_driver *sdrv =to_spi_driver (dev->driver); -struct spi_device *spi =to_spi_device (dev);int ret; -acpi_dev_pm_attach (&spi->dev, true); - ret = sdrv->probe (spi); +acpi_dev_pm_attach (dev, true); + ret = sdrv->probe (to_spi_device (dev));if (ret) -acpi_dev_pm_detach (&spi->dev, true); +acpi_dev_pm_detach (dev, true);return ret; }@@ -269,11 +268,10 @@ static int spi_drv_probe(struct device *static int spi_drv_remove (struct device *dev) {const struct spi_driver *sdrv =to_spi_driver (dev->driver);
drivers/spi/spi.c static int spi_drv_probe(struct device * · line 277
Quoted 10 lines
drivers/spi/spi.c +2
-3-struct spi_device *spi =to_spi_device (dev);int ret; - ret = sdrv->remove (spi); -acpi_dev_pm_detach (&spi->dev, true); + ret = sdrv->remove (to_spi_device (dev)); +acpi_dev_pm_detach (dev, true);return ret; }
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Jean Delvare
While backporting
33cf00e5("spi: attach/detach SPI device to the ACPI power domain"), I noticed that the code changes were suboptimal:* Why use
&spi->devwhen we have dev at hand?* After fixing the above, spi is used only once, so we don't really need a local variable for it.
I've applied this but I have to say it's a bit marginal as a cleanup - for example while we do only use the SPI device once it's not entirely idiomatic to use to_spi_device() in the middle of the code rather than at the top of the function so it's a small speed bump to see that.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Mark,
Quoted 6 lines · Mark Brown
Quoted 5 lines · Jean Delvare
While backporting
33cf00e5("spi: attach/detach SPI device to the ACPI power domain"), I noticed that the code changes were suboptimal:* Why use
&spi->devwhen we have dev at hand?
Quoted 7 lines
Quoted 2 lines
* After fixing the above, spi is used only once, so we don't really need a local variable for it.
I've applied this but I have to say it's a bit marginal as a cleanup - for example while we do only use the SPI device once it's not entirely idiomatic to use
to_spi_device()in the middle of the code rather than at the top of the function so it's a small speed bump to see that.
I don't disagree. The rationale for the change is that I simply reverted to how the code was before 33cf00e5, assuming that the introduction of spi as a local variable was caused by it being used more than once. If you believe this was a good change on its own and would prefer to keep it that way, I could send a patch replacing this one and only changing &spi->dev to dev. Let me know.
And yes, this is not the most groundbreaking patch either way, granted ;-)
Signature · 7 lines
Jean Delvare Suse L3 Support -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1392402129.4365.51.camel-H7Kp9ZFCxt/[email protected]
Quoted 6 lines · Jean Delvare
I don't disagree. The rationale for the change is that I simply reverted to how the code was before
33cf00e5, assuming that the introduction of spi as a local variable was caused by it being used more than once. If you believe this was a good change on its own and would prefer to keep it that way, I could send a patch replacing this one and only changing&spi->devto dev. Let me know.
I do have a small preference for it but I don't care enough to suggest you actually send that patch - if it annoyed me enough I'd just fix it myself.