Commit 0a6d3879 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

spi: Always check complete callback before calling it

Since commit 1e25cd47 "spi: Do not require a completion", this checking is
required to prevent NULL pointer dereference.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 455c6fdb
...@@ -446,7 +446,8 @@ static void fsl_espi_do_one_msg(struct spi_message *m) ...@@ -446,7 +446,8 @@ static void fsl_espi_do_one_msg(struct spi_message *m)
m->actual_length = espi_trans.actual_length; m->actual_length = espi_trans.actual_length;
m->status = espi_trans.status; m->status = espi_trans.status;
m->complete(m->context); if (m->complete)
m->complete(m->context);
} }
static int fsl_espi_setup(struct spi_device *spi) static int fsl_espi_setup(struct spi_device *spi)
......
...@@ -404,7 +404,8 @@ static void fsl_spi_do_one_msg(struct spi_message *m) ...@@ -404,7 +404,8 @@ static void fsl_spi_do_one_msg(struct spi_message *m)
} }
m->status = status; m->status = status;
m->complete(m->context); if (m->complete)
m->complete(m->context);
if (status || !cs_change) { if (status || !cs_change) {
ndelay(nsecs); ndelay(nsecs);
......
...@@ -301,7 +301,8 @@ static int mpc512x_psc_spi_msg_xfer(struct spi_master *master, ...@@ -301,7 +301,8 @@ static int mpc512x_psc_spi_msg_xfer(struct spi_master *master,
} }
m->status = status; m->status = status;
m->complete(m->context); if (m->complete)
m->complete(m->context);
if (status || !cs_change) if (status || !cs_change)
mpc512x_psc_spi_deactivate_cs(spi); mpc512x_psc_spi_deactivate_cs(spi);
......
...@@ -248,7 +248,8 @@ static void mpc52xx_psc_spi_work(struct work_struct *work) ...@@ -248,7 +248,8 @@ static void mpc52xx_psc_spi_work(struct work_struct *work)
} }
m->status = status; m->status = status;
m->complete(m->context); if (m->complete)
m->complete(m->context);
if (status || !cs_change) if (status || !cs_change)
mpc52xx_psc_spi_deactivate_cs(spi); mpc52xx_psc_spi_deactivate_cs(spi);
......
...@@ -235,7 +235,8 @@ static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms, ...@@ -235,7 +235,8 @@ static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
dev_err(&ms->master->dev, "mode fault\n"); dev_err(&ms->master->dev, "mode fault\n");
mpc52xx_spi_chipsel(ms, 0); mpc52xx_spi_chipsel(ms, 0);
ms->message->status = -EIO; ms->message->status = -EIO;
ms->message->complete(ms->message->context); if (ms->message->complete)
ms->message->complete(ms->message->context);
ms->state = mpc52xx_spi_fsmstate_idle; ms->state = mpc52xx_spi_fsmstate_idle;
return FSM_CONTINUE; return FSM_CONTINUE;
} }
...@@ -289,7 +290,8 @@ mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data) ...@@ -289,7 +290,8 @@ mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
ms->msg_count++; ms->msg_count++;
mpc52xx_spi_chipsel(ms, 0); mpc52xx_spi_chipsel(ms, 0);
ms->message->status = 0; ms->message->status = 0;
ms->message->complete(ms->message->context); if (ms->message->complete)
ms->message->complete(ms->message->context);
ms->state = mpc52xx_spi_fsmstate_idle; ms->state = mpc52xx_spi_fsmstate_idle;
return FSM_CONTINUE; return FSM_CONTINUE;
} }
......
...@@ -322,7 +322,8 @@ static void spi_sh_work(struct work_struct *work) ...@@ -322,7 +322,8 @@ static void spi_sh_work(struct work_struct *work)
spin_lock_irqsave(&ss->lock, flags); spin_lock_irqsave(&ss->lock, flags);
mesg->status = 0; mesg->status = 0;
mesg->complete(mesg->context); if (mesg->complete)
mesg->complete(mesg->context);
} }
clear_fifo(ss); clear_fifo(ss);
...@@ -340,7 +341,8 @@ static void spi_sh_work(struct work_struct *work) ...@@ -340,7 +341,8 @@ static void spi_sh_work(struct work_struct *work)
error: error:
mesg->status = ret; mesg->status = ret;
mesg->complete(mesg->context); if (mesg->complete)
mesg->complete(mesg->context);
spi_sh_clear_bit(ss, SPI_SH_SSA | SPI_SH_SSDB | SPI_SH_SSD, spi_sh_clear_bit(ss, SPI_SH_SSA | SPI_SH_SSDB | SPI_SH_SSD,
SPI_SH_CR1); SPI_SH_CR1);
......
...@@ -265,7 +265,8 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) ...@@ -265,7 +265,8 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m)
exit: exit:
m->status = status; m->status = status;
m->complete(m->context); if (m->complete)
m->complete(m->context);
/* normally deactivate chipselect ... unless no error and /* normally deactivate chipselect ... unless no error and
* cs_change has hinted that the next message will probably * cs_change has hinted that the next message will probably
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment