From patchwork Wed Apr 15 08:00:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huiquan Zhong X-Patchwork-Id: 6219141 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 0C416BF4A6 for ; Wed, 15 Apr 2015 07:48:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 165B120376 for ; Wed, 15 Apr 2015 07:48:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 320C220377 for ; Wed, 15 Apr 2015 07:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753184AbbDOHsd (ORCPT ); Wed, 15 Apr 2015 03:48:33 -0400 Received: from mga09.intel.com ([134.134.136.24]:61432 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751834AbbDOHsd (ORCPT ); Wed, 15 Apr 2015 03:48:33 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 15 Apr 2015 00:48:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,581,1422950400"; d="scan'208";a="709295756" Received: from huiquan.sh.intel.com ([10.239.153.82]) by fmsmga002.fm.intel.com with ESMTP; 15 Apr 2015 00:48:31 -0700 From: Huiquan Zhong To: linux-spi@vger.kernel.org, broonie@kernel.org Cc: huiquanz.zhong@intel.com, Huiquan Zhong Subject: [PATCH] spi: fix one potential spin_lock issue Date: Wed, 15 Apr 2015 16:00:32 +0800 Message-Id: <1429084832-8953-1-git-send-email-huiquan.zhong@intel.com> X-Mailer: git-send-email 1.7.9.5 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 master->pump_messages workqueue can be queued by spi_start_queue(), __spi_queued_transfer(). there is one case that if one resume thread call spi_start_queue(), and at the same time another spi_device thread call spi_queued_transfer() to do spi transfer, then the first workqueue will start the spi transfer, but the next workqueue queued before SPI transfer complete, will unusual terminate spi transfer. Add spin_lock protection to avoid this case. Signed-off-by: Huiquan Zhong --- drivers/spi/spi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index d5d7d22..2bc387b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1017,9 +1017,11 @@ static int spi_start_queue(struct spi_master *master) master->running = true; master->cur_msg = NULL; - spin_unlock_irqrestore(&master->queue_lock, flags); - queue_kthread_work(&master->kworker, &master->pump_messages); + if (!list_empty(&master->queue)) + queue_kthread_work(&master->kworker, &master->pump_messages); + + spin_unlock_irqrestore(&master->queue_lock, flags); return 0; }