From patchwork Fri Mar 18 10:15:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 8617931 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB42F9F54C for ; Fri, 18 Mar 2016 10:15:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC711202E9 for ; Fri, 18 Mar 2016 10:15:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9C422024D for ; Fri, 18 Mar 2016 10:15:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754729AbcCRKPU (ORCPT ); Fri, 18 Mar 2016 06:15:20 -0400 Received: from gloria.sntech.de ([95.129.55.99]:59457 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754102AbcCRKPT (ORCPT ); Fri, 18 Mar 2016 06:15:19 -0400 Received: from ip9234b7c8.dynamic.kabel-deutschland.de ([146.52.183.200] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1agrR1-0000vb-SW; Fri, 18 Mar 2016 11:15:11 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Mark Brown Cc: Kevin Hilman , Vignesh R , Jon Hunter , linux-rockchip@lists.infradead.org, linux-spi@vger.kernel.org Subject: [PATCH v2] spi: fix possible deadlock between internal bus locks and bus_lock_flag Date: Fri, 18 Mar 2016 11:15:11 +0100 Message-ID: <1603558.KZbpLAQA15@diego> User-Agent: KMail/4.14.10 (Linux/4.2.0-1-amd64; KDE/4.14.14; x86_64; ; ) 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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 External users may use spi_bus_lock to get exclusive access. This will also grab the bus_lock_mutex and may therefore result in a deadlock if __spi_pump_messages also tries to get the mutex. Therefore adapt spi_pump_messages as well as spi_sync to preset the bus_locked parameter according to the master->bus_lock_flag. Fixes: 49023d2e4ead ("spi: core: Fix deadlock when sending messages") Signed-off-by: Heiko Stuebner Acked-by: Jon Hunter Tested-by: Kevin Hilman --- changes in v2: - move the second check from __spi_pump_messages to its calling functions spi_pump_messages and __spi_sync as suggested by Vignesh drivers/spi/spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index de2f2f9..0239b45 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1209,7 +1209,7 @@ static void spi_pump_messages(struct kthread_work *work) struct spi_master *master = container_of(work, struct spi_master, pump_messages); - __spi_pump_messages(master, true, false); + __spi_pump_messages(master, true, master->bus_lock_flag); } static int spi_init_queue(struct spi_master *master) @@ -2853,7 +2853,7 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message, */ int spi_sync(struct spi_device *spi, struct spi_message *message) { - return __spi_sync(spi, message, 0); + return __spi_sync(spi, message, spi->master->bus_lock_flag); } EXPORT_SYMBOL_GPL(spi_sync);