From patchwork Thu Apr 23 07:56:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 6260121 Return-Path: X-Original-To: patchwork-linux-spi@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 07CDEBF4A6 for ; Thu, 23 Apr 2015 07:56:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B0EC2037C for ; Thu, 23 Apr 2015 07:56:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46EDF20379 for ; Thu, 23 Apr 2015 07:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933019AbbDWH4K (ORCPT ); Thu, 23 Apr 2015 03:56:10 -0400 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163]:47550 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932963AbbDWH4K (ORCPT ); Thu, 23 Apr 2015 03:56:10 -0400 Received: from raspb.intern.sperl.org (account martin@sperl.org [10.10.10.32] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6320788; Thu, 23 Apr 2015 07:56:07 +0000 From: kernel@martin.sperl.org To: Mark Brown , linux-spi@vger.kernel.org Cc: Martin Sperl Subject: [PATCH] spi: spidev: use spi_sync instead of spi_async Date: Thu, 23 Apr 2015 07:56:01 +0000 Message-Id: <1429775761-3149-1-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20150422194133.GI22845@sirena.org.uk> References: <20150422194133.GI22845@sirena.org.uk> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@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 From: Martin Sperl This has the benefit that the "optimization" of the framework in regards to spi_sync will also benefit spidev users directly and allow running spi transfers without a necessary context-switch to message-pump. Signed-off-by: Martin Sperl --- drivers/spi/spidev.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 92c909e..b00ae96 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -95,37 +95,25 @@ MODULE_PARM_DESC(bufsiz, "data bytes in biggest supported SPI message"); /*-------------------------------------------------------------------------*/ -/* - * We can't use the standard synchronous wrappers for file I/O; we - * need to protect against async removal of the underlying spi_device. - */ -static void spidev_complete(void *arg) -{ - complete(arg); -} - static ssize_t spidev_sync(struct spidev_data *spidev, struct spi_message *message) { DECLARE_COMPLETION_ONSTACK(done); int status; - - message->complete = spidev_complete; - message->context = &done; + struct spi_device *spi; spin_lock_irq(&spidev->spi_lock); - if (spidev->spi == NULL) + spi = spidev->spi; + spin_unlock_irq(&spidev->spi_lock); + + if (spi == NULL) status = -ESHUTDOWN; else - status = spi_async(spidev->spi, message); - spin_unlock_irq(&spidev->spi_lock); + status = spi_sync(spi, message); + + if (status == 0) + status = message->actual_length; - if (status == 0) { - wait_for_completion(&done); - status = message->status; - if (status == 0) - status = message->actual_length; - } return status; }