spi: Make master->handle_err() callback optional to avoid crashes
authorGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 7 Apr 2015 18:39:19 +0000 (20:39 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 7 Apr 2015 18:41:32 +0000 (19:41 +0100)
If a driver doesn't implement the master->handle_err() callback and an
SPI transfer fails, the kernel will crash with a NULL pointer
dereference:

    Unable to handle kernel NULL pointer dereference at virtual address 00000000
    pgd = c0003000
    [00000000] *pgd=80000040004003, *pmd=00000000
    Internal error: Oops: 80000206 [#1] SMP ARM
    Modules linked in:
    CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.0.0-rc7-koelsch-05861-g1fc9fdd4add4f783 #1046
    Hardware name: Generic R8A7791 (Flattened Device Tree)
    task: eec359c0 ti: eec54000 task.ti: eec54000
    PC is at 0x0
    LR is at spi_transfer_one_message+0x1cc/0x1f0

Make the master->handle_err() callback optional to avoid the crash.

Also fix a spelling mistake in the callback documentation while we're at
it.

Fixes: b716c4ffc6a2b0bf ("spi: introduce master->handle_err() callback")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c
include/linux/spi/spi.h

index 31d4d9d997e2b8cd55c73d97ae537a8b82d23b36..7713253229958620437e61617b28780df844a57f 100644 (file)
@@ -851,7 +851,7 @@ out:
        if (msg->status == -EINPROGRESS)
                msg->status = ret;
 
-       if (msg->status)
+       if (msg->status && master->handle_err)
                master->handle_err(master, msg);
 
        spi_finalize_current_message(master);
index 4eaac3a5227bdc2d112f221c49f0e5147cdd0af2..5685af84a64dbe3f9f5897e7c99b26c89dfc41c3 100644 (file)
@@ -294,7 +294,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
  *                    transfer_one_message are mutually exclusive; when both
  *                    are set, the generic subsystem does not call your
  *                    transfer_one callback.
- * @handle_err: the subsystem calls the driver to handle and error that occurs
+ * @handle_err: the subsystem calls the driver to handle an error that occurs
  *             in the generic implementation of transfer_one_message().
  * @unprepare_message: undo any work done by prepare_message().
  * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS