From patchwork Fri Jan 31 07:49:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 3560381 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 44E9C9F381 for ; Fri, 31 Jan 2014 07:49:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D725201E7 for ; Fri, 31 Jan 2014 07:49:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24D9E201E9 for ; Fri, 31 Jan 2014 07:49:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751410AbaAaHtq (ORCPT ); Fri, 31 Jan 2014 02:49:46 -0500 Received: from mail-pb0-f46.google.com ([209.85.160.46]:52484 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751292AbaAaHtq (ORCPT ); Fri, 31 Jan 2014 02:49:46 -0500 Received: by mail-pb0-f46.google.com with SMTP id um1so4159279pbc.33 for ; Thu, 30 Jan 2014 23:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=WXVcZQZPniC8gMRtkOF9/RBKvLGdu6bkLucQjlTu59I=; b=WbrPu9y7vW877jLBkjzpANAZqGlP2ayfpXC7KWamxMh8xiIzLo7obbBrlXphYBR+dn 6tfHVrM5q/Rek03yeHAzCJsZ0WOMPH/iUC4UbOG0AkOsG5TJTk5iv+IYxxPJFg48U9ST 3PIIDw5mgyB5fNDFnCPQcKcbcKUjFfdQM6zmVKbuZHmQp40DaO5JqVzPUv5CEaUguitW BBhDEJQH9D/7qdt5wVMiKPwwAb0Hxs5HRrhUslmaHcjGEC0obI0DYq3QrxIKUlT7Of4Q V7IzxWYUi/Ofja+kPZsJZePSI/bMUw2/0cdnX6ZoN1wOG5jhM3LOD8bp660DOitTbj6A gPfQ== MIME-Version: 1.0 X-Received: by 10.66.142.233 with SMTP id rz9mr19364176pab.71.1391154585799; Thu, 30 Jan 2014 23:49:45 -0800 (PST) Received: by 10.70.28.195 with HTTP; Thu, 30 Jan 2014 23:49:45 -0800 (PST) In-Reply-To: <1391121536-10937-1-git-send-email-broonie@kernel.org> References: <1391121536-10937-1-git-send-email-broonie@kernel.org> Date: Fri, 31 Jan 2014 08:49:45 +0100 X-Google-Sender-Auth: rJsBO0V-tCpICfhW_AaPwHvommE Message-ID: Subject: Re: [PATCH] spi: Add a timeout when waiting for transfers From: Geert Uytterhoeven To: Mark Brown Cc: linux-spi , linaro-kernel@lists.linaro.org, Mark Brown 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.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Hi Mark, On Thu, Jan 30, 2014 at 11:38 PM, Mark Brown wrote: > From: Mark Brown > > Don't wait indefinitely for transfers to complete but time out after 10ms > more than we expect the transfer to take on the wire. > > Signed-off-by: Mark Brown > --- > drivers/spi/spi.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index 7f23cf9afa79..1826a50c2aaf 100644 > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -710,6 +710,7 @@ static int spi_transfer_one_message(struct spi_master *master, > bool cur_cs = true; > bool keep_cs = false; > int ret = 0; > + int ms = 1; > > spi_set_cs(msg->spi, true); > > @@ -727,7 +728,16 @@ static int spi_transfer_one_message(struct spi_master *master, > > if (ret > 0) { > ret = 0; > - wait_for_completion(&master->xfer_completion); > + ms = xfer->len * 8 * 1000 / xfer->speed_hz; > + ms += 10; /* some tolerance */ > + > + ms = wait_for_completion_timeout(&master->xfer_completion, > + msecs_to_jiffies(ms)); > + } > + > + if (ms == 0) { > + dev_err(&msg->spi->dev, "SPI transfer timed out\n"); > + msg->status = -ETIMEDOUT; > } > > trace_spi_transfer_stop(msg, xfer); What if it still completes in the driver a little bit later? The driver will also call spi_finalize_current_message(), and we'll get a NULL pointer dereference as master->cur_msg is now NULL. So I think we need a check like (whitespace damaged) below: Gr{oetje,eeting}s, Geert --- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -829,6 +829,9 @@ void spi_finalize_current_message(struct spi_master *master) queue_kthread_work(&master->kworker, &master->pump_messages); spin_unlock_irqrestore(&master->queue_lock, flags); + if (!mesg) + return NULL; + if (master->cur_msg_prepared && master->unprepare_message) { ret = master->unprepare_message(master, mesg); if (ret) {