As for i2c-core, let the SPI core handle the removal of the device's
drvdata, after a remove() or a probe() failure.

Signed-off-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
---
 drivers/spi/spi.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 84c2861..fe636fe 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -233,15 +233,25 @@ 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               *sdev = to_spi_device(dev);
+       int                             status;
 
-       return sdrv->probe(to_spi_device(dev));
+       status = sdrv->probe(sdev);
+       if (status)
+               spi_set_drvdata(sdev, NULL);
+       return status;
 }
 
 static int spi_drv_remove(struct device *dev)
 {
        const struct spi_driver         *sdrv = to_spi_driver(dev->driver);
+       struct spi_device               *sdev = to_spi_device(dev);
+       int                             status;
 
-       return sdrv->remove(to_spi_device(dev));
+       status = sdrv->remove(sdev);
+       if (status == 0)
+               spi_set_drvdata(sdev, NULL);
+       return status;
 }
 
 static void spi_drv_shutdown(struct device *dev)
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

Reply via email to