From patchwork Tue Apr 7 18:39:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 6174391 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A7FBABF4A6 for ; Tue, 7 Apr 2015 18:39:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC3A620381 for ; Tue, 7 Apr 2015 18:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C96D0203AD for ; Tue, 7 Apr 2015 18:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752855AbbDGSjZ (ORCPT ); Tue, 7 Apr 2015 14:39:25 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:46031 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752311AbbDGSjY (ORCPT ); Tue, 7 Apr 2015 14:39:24 -0400 Received: from ayla.of.borg ([84.193.93.87]) by xavier.telenet-ops.be with bizsmtp id D6fL1q00w1t5w8s016fLvD; Tue, 07 Apr 2015 20:39:22 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1YfYPA-00005k-J2; Tue, 07 Apr 2015 20:39:20 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1YfYPH-0006Ee-4I; Tue, 07 Apr 2015 20:39:27 +0200 From: Geert Uytterhoeven To: Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] spi: Make master->handle_err() callback optional to avoid crashes Date: Tue, 7 Apr 2015 20:39:19 +0200 Message-Id: <1428431959-23935-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/spi/spi.c | 2 +- include/linux/spi/spi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 04e9d9262711a56e..d5d7d2235163f9ef 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -736,7 +736,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); diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 57a89347b038e611..d673072346f2e041 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -290,7 +290,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