From patchwork Wed Sep 16 13:24:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 7194711 Return-Path: X-Original-To: patchwork-linux-nvdimm@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 9214ABEEC1 for ; Wed, 16 Sep 2015 13:24:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E4D220850 for ; Wed, 16 Sep 2015 13:24:54 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3881020838 for ; Wed, 16 Sep 2015 13:24:53 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0486760AB2; Wed, 16 Sep 2015 06:24:53 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C2ED160AA3 for ; Wed, 16 Sep 2015 06:24:51 -0700 (PDT) Received: by padhy16 with SMTP id hy16so209653508pad.1 for ; Wed, 16 Sep 2015 06:24:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=bt/cBLaYluDOw814pOBBM1sXupfKh6T56OINCQLjurc=; b=hQbGg7tXQdWCP9yKFvuro8Qnu3vj13X4sNWZGYOjg0Lw1jswIsJQLADpZPQsn8oB2e eGBTgqBkq4ywNZTGRxA7kT148fMNBHvI/NjeIU3aN4JNQQFwaKorQoc6m6Pw+qEdjKM4 9oXevPA3wVEFiUDI+5jIKa8Yv9CxImkrydeI0WdUhQ+RZu7nam8gAqjWvOcJnZWWrJPO elUr61KVO/5EIKD7nLnm3EWklq8C4wQhF6aSWS9eLgUNm7nJM3tsF4YeUTr+4I4uBrVb qoarX2Sz1a4hFkndtHwyEHFArIAeYIDs3yeNSdM3HSsDlyOVT/saWj0B1N1kwV9MUmDf Pe1w== X-Gm-Message-State: ALoCoQmJssN4iEPwhw89x+iGjIn/IlagcRzJOkWgNi0uCQKPlg9NJbW7S8hTlJDByBl5LjeBoasu X-Received: by 10.68.196.99 with SMTP id il3mr59026830pbc.166.1442409891434; Wed, 16 Sep 2015 06:24:51 -0700 (PDT) Received: from phoenix (36-239-213-31.dynamic-ip.hinet.net. [36.239.213.31]) by smtp.gmail.com with ESMTPSA id yq2sm25841189pbb.39.2015.09.16.06.24.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 06:24:50 -0700 (PDT) Message-ID: <1442409887.6868.1.camel@ingics.com> Subject: [PATCH 1/2] libnvdimm: btt_devs: Fix locking in namespace_store From: Axel Lin To: Dan Williams Date: Wed, 16 Sep 2015 21:24:47 +0800 X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Cc: linux-nvdimm@lists.01.org X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 Always take device_lock() before nvdimm_bus_lock() to prevent deadlock. Signed-off-by: Axel Lin --- drivers/nvdimm/btt_devs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index 59ad54a6..cb47751 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -128,13 +128,13 @@ static ssize_t namespace_store(struct device *dev, struct nd_btt *nd_btt = to_nd_btt(dev); ssize_t rc; - nvdimm_bus_lock(dev); device_lock(dev); + nvdimm_bus_lock(dev); rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len); dev_dbg(dev, "%s: result: %zd wrote: %s%s", __func__, rc, buf, buf[len - 1] == '\n' ? "" : "\n"); - device_unlock(dev); nvdimm_bus_unlock(dev); + device_unlock(dev); return rc; }