From patchwork Thu Mar 17 23:18:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 8614991 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 52ABBC0553 for ; Thu, 17 Mar 2016 23:18:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 780F5201ED for ; Thu, 17 Mar 2016 23:18:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D54F201B4 for ; Thu, 17 Mar 2016 23:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031468AbcCQXS2 (ORCPT ); Thu, 17 Mar 2016 19:18:28 -0400 Received: from gloria.sntech.de ([95.129.55.99]:56442 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030931AbcCQXS2 (ORCPT ); Thu, 17 Mar 2016 19:18:28 -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 1aghBL-00075O-Tk; Fri, 18 Mar 2016 00:18:19 +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] spi: don't lock the bus in __spi_pump_messages if it is already locked Date: Fri, 18 Mar 2016 00:18:19 +0100 Message-ID: <1848110.TJtF6nar8z@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. Fixes: 49023d2e4ead ("spi: core: Fix deadlock when sending messages") Signed-off-by: Heiko Stuebner --- 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..62f962b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1160,7 +1160,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread, } } - if (!bus_locked) + if (!bus_locked && !master->bus_lock_flag) mutex_lock(&master->bus_lock_mutex); trace_spi_message_start(master->cur_msg); @@ -1192,7 +1192,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread, } out: - if (!bus_locked) + if (!bus_locked && !master->bus_lock_flag) mutex_unlock(&master->bus_lock_mutex); /* Prod the scheduler in case transfer_one() was busy waiting */