linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: sh-sci: Prevent NULL pointer dereference
@ 2014-03-13  2:32 Axel Lin
  2014-03-13  9:52 ` Geert Uytterhoeven
  2014-03-13 13:40 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2014-03-13  2:32 UTC (permalink / raw)
  To: Mark Brown; +Cc: Magnus Damm, linux-spi-u79uwXL29TY76Z2rM5mHXA

If sp->info is NULL, we will hit NULL pointer dereference in probe() while
setting bus_num and num_chipselect for master:

        sp->bitbang.master->bus_num = sp->info->bus_num;
        sp->bitbang.master->num_chipselect = sp->info->num_chipselect;

Thus add NULL test for sp->info in probe() to prevent NULL pointer dereference.

Signed-off-by: Axel Lin <axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org>
---
 drivers/spi/spi-sh-sci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c
index 85c2efd..8b44b71 100644
--- a/drivers/spi/spi-sh-sci.c
+++ b/drivers/spi/spi-sh-sci.c
@@ -108,7 +108,7 @@ static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
 {
 	struct sh_sci_spi *sp = spi_master_get_devdata(dev->master);
 
-	if (sp->info && sp->info->chip_select)
+	if (sp->info->chip_select)
 		(sp->info->chip_select)(sp->info, dev->chip_select, value);
 }
 
@@ -130,6 +130,11 @@ static int sh_sci_spi_probe(struct platform_device *dev)
 
 	platform_set_drvdata(dev, sp);
 	sp->info = dev_get_platdata(&dev->dev);
+	if (!sp->info) {
+		dev_err(&dev->dev, "platform data is missing\n");
+		ret = -ENOENT;
+		goto err1;
+	}
 
 	/* setup spi bitbang adaptor */
 	sp->bitbang.master = master;
-- 
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] 3+ messages in thread

* Re: [PATCH] spi: sh-sci: Prevent NULL pointer dereference
  2014-03-13  2:32 [PATCH] spi: sh-sci: Prevent NULL pointer dereference Axel Lin
@ 2014-03-13  9:52 ` Geert Uytterhoeven
  2014-03-13 13:40 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-03-13  9:52 UTC (permalink / raw)
  To: Axel Lin; +Cc: Mark Brown, Magnus Damm, linux-spi

On Thu, Mar 13, 2014 at 3:32 AM, Axel Lin <axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org> wrote:
> If sp->info is NULL, we will hit NULL pointer dereference in probe() while
> setting bus_num and num_chipselect for master:
>
>         sp->bitbang.master->bus_num = sp->info->bus_num;
>         sp->bitbang.master->num_chipselect = sp->info->num_chipselect;
>
> Thus add NULL test for sp->info in probe() to prevent NULL pointer dereference.
>
> Signed-off-by: Axel Lin <axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org>

Reviewed-by: Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>

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] 3+ messages in thread

* Re: [PATCH] spi: sh-sci: Prevent NULL pointer dereference
  2014-03-13  2:32 [PATCH] spi: sh-sci: Prevent NULL pointer dereference Axel Lin
  2014-03-13  9:52 ` Geert Uytterhoeven
@ 2014-03-13 13:40 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-03-13 13:40 UTC (permalink / raw)
  To: Axel Lin; +Cc: Magnus Damm, linux-spi-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]

On Thu, Mar 13, 2014 at 10:32:37AM +0800, Axel Lin wrote:
> If sp->info is NULL, we will hit NULL pointer dereference in probe() while
> setting bus_num and num_chipselect for master:
> 
>         sp->bitbang.master->bus_num = sp->info->bus_num;
>         sp->bitbang.master->num_chipselect = sp->info->num_chipselect;

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-13 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-13  2:32 [PATCH] spi: sh-sci: Prevent NULL pointer dereference Axel Lin
2014-03-13  9:52 ` Geert Uytterhoeven
2014-03-13 13:40 ` 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).