diff mbox

spi: sh-sci: Prevent NULL pointer dereference

Message ID 1394677957.15733.1.camel@phoenix (mailing list archive)
State Accepted
Commit ed8eb250d7b097dbd888e46ad0d35a2cb1858221
Headers show

Commit Message

Axel Lin March 13, 2014, 2:32 a.m. UTC
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@ingics.com>
---
 drivers/spi/spi-sh-sci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Geert Uytterhoeven March 13, 2014, 9:52 a.m. UTC | #1
On Thu, Mar 13, 2014 at 3:32 AM, Axel Lin <axel.lin@ingics.com> 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@ingics.com>

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mark Brown March 13, 2014, 1:40 p.m. UTC | #2
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.
diff mbox

Patch

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;