* [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
@ 2014-03-09 6:11 Axel Lin
2014-03-10 15:48 ` Steven King
2014-03-10 16:04 ` Steven King
0 siblings, 2 replies; 6+ messages in thread
From: Axel Lin @ 2014-03-09 6:11 UTC (permalink / raw)
To: Mark Brown; +Cc: Steven King, linux-spi-u79uwXL29TY76Z2rM5mHXA
If pdata->cs_control is NULL, we will hit NULL pointer dereference in
mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for
pdata->cs_control in probe().
Signed-off-by: Axel Lin <axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org>
---
drivers/spi/spi-coldfire-qspi.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c
index c29bbb0..b01616c 100644
--- a/drivers/spi/spi-coldfire-qspi.c
+++ b/drivers/spi/spi-coldfire-qspi.c
@@ -133,13 +133,13 @@ static void mcfqspi_cs_deselect(struct mcfqspi *mcfqspi, u8 chip_select,
static int mcfqspi_cs_setup(struct mcfqspi *mcfqspi)
{
- return (mcfqspi->cs_control && mcfqspi->cs_control->setup) ?
+ return (mcfqspi->cs_control->setup) ?
mcfqspi->cs_control->setup(mcfqspi->cs_control) : 0;
}
static void mcfqspi_cs_teardown(struct mcfqspi *mcfqspi)
{
- if (mcfqspi->cs_control && mcfqspi->cs_control->teardown)
+ if (mcfqspi->cs_control->teardown)
mcfqspi->cs_control->teardown(mcfqspi->cs_control);
}
@@ -366,6 +366,11 @@ static int mcfqspi_probe(struct platform_device *pdev)
return -ENOENT;
}
+ if (!pdata->cs_control) {
+ dev_dbg(&pdev->dev, "pdata->cs_control is NULL\n");
+ return -EINVAL;
+ }
+
master = spi_alloc_master(&pdev->dev, sizeof(*mcfqspi));
if (master == NULL) {
dev_dbg(&pdev->dev, "spi_alloc_master failed\n");
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
2014-03-09 6:11 [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference Axel Lin
@ 2014-03-10 15:48 ` Steven King
[not found] ` <201403100848.41186.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
2014-03-10 16:04 ` Steven King
1 sibling, 1 reply; 6+ messages in thread
From: Steven King @ 2014-03-10 15:48 UTC (permalink / raw)
To: Axel Lin; +Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA
On Saturday 08 March 2014 10:11:10 pm Axel Lin wrote:
> If pdata->cs_control is NULL, we will hit NULL pointer dereference in
> mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for
> pdata->cs_control in probe().
>
NAK.
I suggest you read the code again. There is no NULL pointer dereference and
further, by returning an error if cs_control is NULL, you've now broken the
design which was that cs_control is optional.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
2014-03-09 6:11 [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference Axel Lin
2014-03-10 15:48 ` Steven King
@ 2014-03-10 16:04 ` Steven King
[not found] ` <201403100904.05819.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
1 sibling, 1 reply; 6+ messages in thread
From: Steven King @ 2014-03-10 16:04 UTC (permalink / raw)
To: Axel Lin; +Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA
On Saturday 08 March 2014 10:11:10 pm Axel Lin wrote:
> If pdata->cs_control is NULL, we will hit NULL pointer dereference in
> mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for
> pdata->cs_control in probe().
D'oh! My bad. Actually you're right there would be a NULL pointer
dereference in cs_select and cs_deselect (I was looking at the cs_setup and
cs_teardown in the patch) and so cs_control must not be NULL. Thats want I
get for replying before I've had my coffee and when I haven't looked at the
code in awhile. So yeah, the patch is GTG.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
[not found] ` <201403100848.41186.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
@ 2014-03-10 16:05 ` Mark Brown
0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2014-03-10 16:05 UTC (permalink / raw)
To: Steven King; +Cc: Axel Lin, linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 945 bytes --]
On Mon, Mar 10, 2014 at 08:48:40AM -0700, Steven King wrote:
> On Saturday 08 March 2014 10:11:10 pm Axel Lin wrote:
> > If pdata->cs_control is NULL, we will hit NULL pointer dereference in
> > mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for
> > pdata->cs_control in probe().
> NAK.
> I suggest you read the code again. There is no NULL pointer dereference and
> further, by returning an error if cs_control is NULL, you've now broken the
> design which was that cs_control is optional.
So, you've sent this after I'd applied the patch (having ignored prior
patches as well, the last activity was in 2012), that's a bit
unfortunate. I've reverted the patch but please if you're reviewing
changes to the driver can you indicate if things are OK when you do so -
if patches aren't getting any review from people working on the driver
the tendency is to assume that the driver has been abandoned.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
[not found] ` <201403100904.05819.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
@ 2014-03-10 16:06 ` Geert Uytterhoeven
2014-03-10 16:08 ` Mark Brown
1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2014-03-10 16:06 UTC (permalink / raw)
To: Steven King; +Cc: Axel Lin, Mark Brown, linux-spi
On Mon, Mar 10, 2014 at 5:04 PM, Steven King <sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org> wrote:
> On Saturday 08 March 2014 10:11:10 pm Axel Lin wrote:
>> If pdata->cs_control is NULL, we will hit NULL pointer dereference in
>> mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for
>> pdata->cs_control in probe().
>
> D'oh! My bad. Actually you're right there would be a NULL pointer
> dereference in cs_select and cs_deselect (I was looking at the cs_setup and
> cs_teardown in the patch) and so cs_control must not be NULL. Thats want I
> get for replying before I've had my coffee and when I haven't looked at the
> code in awhile. So yeah, the patch is GTG.
I had the same first impression. But after looking through the code, the
changes is fine. Furthermore, there's only on in-tree user it, which does
provide cs_control.
There's more opportunity for cleanup, though, as cs_control provides control
of a GPIO, which can be handled by the SPI core, too.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference
[not found] ` <201403100904.05819.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
2014-03-10 16:06 ` Geert Uytterhoeven
@ 2014-03-10 16:08 ` Mark Brown
1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2014-03-10 16:08 UTC (permalink / raw)
To: Steven King; +Cc: Axel Lin, linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 544 bytes --]
On Mon, Mar 10, 2014 at 09:04:05AM -0700, Steven King wrote:
> D'oh! My bad. Actually you're right there would be a NULL pointer
> dereference in cs_select and cs_deselect (I was looking at the cs_setup and
> cs_teardown in the patch) and so cs_control must not be NULL. Thats want I
> get for replying before I've had my coffee and when I haven't looked at the
> code in awhile. So yeah, the patch is GTG.
Hrm, I managed to make the same mistake when I redid the verification
somehow. Odd. Anyway, reinstated the patch.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-10 16:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-09 6:11 [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference Axel Lin
2014-03-10 15:48 ` Steven King
[not found] ` <201403100848.41186.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
2014-03-10 16:05 ` Mark Brown
2014-03-10 16:04 ` Steven King
[not found] ` <201403100904.05819.sfking-xS0NTnu2YfYAvxtiuMwx3w@public.gmane.org>
2014-03-10 16:06 ` Geert Uytterhoeven
2014-03-10 16:08 ` Mark Brown
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).