From patchwork Wed Apr 2 14:21:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3929051 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1306A9F2B6 for ; Wed, 2 Apr 2014 14:21:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2404520220 for ; Wed, 2 Apr 2014 14:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F1A9201D5 for ; Wed, 2 Apr 2014 14:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758796AbaDBOVN (ORCPT ); Wed, 2 Apr 2014 10:21:13 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:51798 "EHLO mail-pb0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758791AbaDBOVL (ORCPT ); Wed, 2 Apr 2014 10:21:11 -0400 Received: by mail-pb0-f53.google.com with SMTP id rp16so260981pbb.12 for ; Wed, 02 Apr 2014 07:21:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=sS9WEqGfn22SqCWXNXVYuVY4WemOlfn1O6do/5f+TWM=; b=Gr6bYxknmcaN86ftcVCx5IErphQxrN2uKag+I0zyoTff9yutyzwsq2Zglaip0rtYMt posH9cIk+EyFOvHlbIHp9WnT9ucHJxMC9CSYsI9ZmfgARPQmMRxB7NoOyj01ioeMddTB pJNqTz0ub7Vvo8ULSfkQovxICA1XXogschWilKsgF99KOcVQMV2rFMWvmlG91RB7b2WX 4RHuJJX7h06cZ3AFsHqeZwiQeTCWja0E5wX3BYWjJIvbvuS2CCQF4jB03mUm6N9XZDkD 9bRKU6jyfNtdCQfAb7wcZZhvR9iPiS1AbLxzMMkI8wfwYIyg8XqBoxw2Oh03XCj4Mu06 mt3A== X-Gm-Message-State: ALoCoQnsB1rJ3L0JSf19tCmkxcVa/IfWwoIys037nCfAdnwp/Q9bBQIvqwQ9u+X5RoprQc+B86gI X-Received: by 10.66.160.34 with SMTP id xh2mr246850pab.109.1396448470367; Wed, 02 Apr 2014 07:21:10 -0700 (PDT) Received: from [192.168.0.102] (36-239-233-75.dynamic-ip.hinet.net. [36.239.233.75]) by mx.google.com with ESMTPSA id nx12sm10670010pab.6.2014.04.02.07.21.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 02 Apr 2014 07:21:09 -0700 (PDT) Message-ID: <1396448464.8891.1.camel@phoenix> Subject: [PATCH] spi: Always check complete callback before calling it From: Axel Lin To: Mark Brown Cc: Hou Zhiqiang , Sebastian Andrzej Siewior , Gerhard Sittig , Grant Likely , Yoshihiro Shimoda , Atsushi Nemoto , linux-spi@vger.kernel.org Date: Wed, 02 Apr 2014 22:21:04 +0800 X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Since commit 1e25cd4729bd "spi: Do not require a completion", this checking is required to prevent NULL pointer dereference. Signed-off-by: Axel Lin --- drivers/spi/spi-fsl-espi.c | 3 ++- drivers/spi/spi-fsl-spi.c | 3 ++- drivers/spi/spi-mpc512x-psc.c | 3 ++- drivers/spi/spi-mpc52xx-psc.c | 3 ++- drivers/spi/spi-mpc52xx.c | 6 ++++-- drivers/spi/spi-sh.c | 6 ++++-- drivers/spi/spi-txx9.c | 3 ++- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 6fb2b75..e767f58 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -441,7 +441,8 @@ static void fsl_espi_do_one_msg(struct spi_message *m) m->actual_length = espi_trans.actual_length; 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) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index f35488e..b3e7775 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -408,7 +408,8 @@ static void fsl_spi_do_one_msg(struct spi_message *m) } m->status = status; - m->complete(m->context); + if (m->complete) + m->complete(m->context); if (status || !cs_change) { ndelay(nsecs); diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 3822eef..577d23a 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -300,7 +300,8 @@ static int mpc512x_psc_spi_msg_xfer(struct spi_master *master, } m->status = status; - m->complete(m->context); + if (m->complete) + m->complete(m->context); if (status || !cs_change) mpc512x_psc_spi_deactivate_cs(spi); diff --git a/drivers/spi/spi-mpc52xx-psc.c b/drivers/spi/spi-mpc52xx-psc.c index 3d18d93..de532aa 100644 --- a/drivers/spi/spi-mpc52xx-psc.c +++ b/drivers/spi/spi-mpc52xx-psc.c @@ -247,7 +247,8 @@ static void mpc52xx_psc_spi_work(struct work_struct *work) } m->status = status; - m->complete(m->context); + if (m->complete) + m->complete(m->context); if (status || !cs_change) mpc52xx_psc_spi_deactivate_cs(spi); diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c index aac2a5d..b07db4b 100644 --- a/drivers/spi/spi-mpc52xx.c +++ b/drivers/spi/spi-mpc52xx.c @@ -234,7 +234,8 @@ static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms, dev_err(&ms->master->dev, "mode fault\n"); mpc52xx_spi_chipsel(ms, 0); 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; return FSM_CONTINUE; } @@ -288,7 +289,8 @@ mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data) ms->msg_count++; mpc52xx_spi_chipsel(ms, 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; return FSM_CONTINUE; } diff --git a/drivers/spi/spi-sh.c b/drivers/spi/spi-sh.c index f6f2c70..03edf5e 100644 --- a/drivers/spi/spi-sh.c +++ b/drivers/spi/spi-sh.c @@ -322,7 +322,8 @@ static void spi_sh_work(struct work_struct *work) spin_lock_irqsave(&ss->lock, flags); mesg->status = 0; - mesg->complete(mesg->context); + if (mesg->complete) + mesg->complete(mesg->context); } clear_fifo(ss); @@ -340,7 +341,8 @@ static void spi_sh_work(struct work_struct *work) error: 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_CR1); diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c index 820b499..5f183ba 100644 --- a/drivers/spi/spi-txx9.c +++ b/drivers/spi/spi-txx9.c @@ -262,7 +262,8 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) exit: m->status = status; - m->complete(m->context); + if (m->complete) + m->complete(m->context); /* normally deactivate chipselect ... unless no error and * cs_change has hinted that the next message will probably