From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
To: spi-devel-general@lists.sourceforge.net
Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
Rob Herring <rob.herring@calxeda.com>,
Grant Likely <grant.likely@secretlab.ca>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH RESEND] spi: erase pointer to drvdata on removal
Date: Mon, 3 Dec 2012 15:28:24 -0500 [thread overview]
Message-ID: <1354566504-17657-1-git-send-email-vivien.didelot@savoirfairelinux.com> (raw)
Without this patch, a SPI device may keep its drvdata whereas it was unbound
from its driver. This may result in accessing an invalid pointer.
As for i2c-core, let the SPI core handle the removal of the device's drvdata,
after a remove(), or a probe() failure.
This is a resent of the previous patch https://lkml.org/lkml/2012/11/1/314
Signed-off-by: Vivien Didelot <vivien.didelot@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
next reply other threads:[~2012-12-03 20:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-03 20:28 Vivien Didelot [this message]
2012-12-04 14:56 ` [PATCH RESEND] spi: erase pointer to drvdata on removal Grant Likely
2012-12-04 16:39 ` Vivien Didelot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1354566504-17657-1-git-send-email-vivien.didelot@savoirfairelinux.com \
--to=vivien.didelot@savoirfairelinux.com \
--cc=akpm@linux-foundation.org \
--cc=grant.likely@secretlab.ca \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob.herring@calxeda.com \
--cc=spi-devel-general@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).