Skip to content

Commit

Permalink
spi: sh-sci: Prevent NULL pointer dereference
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Axel Lin authored and Mark Brown committed Mar 13, 2014
1 parent 38dbfb5 commit ed8eb25
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/spi/spi-sh-sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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);
}

Expand All @@ -131,6 +131,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;
Expand Down

0 comments on commit ed8eb25

Please sign in to comment.