From patchwork Wed Sep 16 13:25:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 7194781 Return-Path: X-Original-To: patchwork-linux-nvdimm@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 DE73B9F380 for ; Wed, 16 Sep 2015 13:25:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1EA64203F3 for ; Wed, 16 Sep 2015 13:25:45 +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 4A2DF202D1 for ; Wed, 16 Sep 2015 13:25:44 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3F7C360B6D; Wed, 16 Sep 2015 06:25:44 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) (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 8F42F60AFB for ; Wed, 16 Sep 2015 06:25:42 -0700 (PDT) Received: by pacex6 with SMTP id ex6so210019811pac.0 for ; Wed, 16 Sep 2015 06:25:42 -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:in-reply-to :references:content-type:mime-version:content-transfer-encoding; bh=2AoHtKQtmwiTq1DMMueg2uW3A/qq71/FkYxfA4zmiIo=; b=jsF7f6voSi2m5u/wPsWlPsZPY9ygOFQaz6K7wLIF6O3fikUyDQgQVhEhEFoJkdc0pk BVfKgkNi1jiwlSaRVFk5vLHRx4HmpncKn65+w0Avw3Z21EtH8No9hzP/G6fvCUhDWsbg 9GTKhHntx8kqX1AgsNNIF4ijdEALrXcTXVEbnTvOOuqHCFH0PT+lefYkqmc0YoS3iOY8 5BMauzQLr+FXiaKPnj8G2YFVeUzyfgDsfyRt80S/e6aUiHm2J1Yx+VhshePtpikiAAs0 WnIrJ+4kNz78cynQpucEBetTL0B/CsfrMB6rO5XfaIX4MEJve/fISBZS8Lvm5RPmRJVa cV3g== X-Gm-Message-State: ALoCoQnqFJOmb+uMz9VxuNQ+QZEjdqBtQ3lxu1c6uwdS1mchLjkBMFuac6hGW+7nJc8WPlXdx7dQ X-Received: by 10.68.98.34 with SMTP id ef2mr59634104pbb.45.1442409942257; Wed, 16 Sep 2015 06:25:42 -0700 (PDT) Received: from phoenix (36-239-213-31.dynamic-ip.hinet.net. [36.239.213.31]) by smtp.gmail.com with ESMTPSA id g5sm26567568pat.21.2015.09.16.06.25.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 06:25:41 -0700 (PDT) Message-ID: <1442409938.6868.2.camel@ingics.com> Subject: [PATCH 2/2] libnvdimm: pfn_devs: Fix locking in namespace_store From: Axel Lin To: Dan Williams Date: Wed, 16 Sep 2015 21:25:38 +0800 In-Reply-To: <1442409887.6868.1.camel@ingics.com> References: <1442409887.6868.1.camel@ingics.com> 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/pfn_devs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 3fd7d0d..71805a1 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -148,13 +148,13 @@ static ssize_t namespace_store(struct device *dev, struct nd_pfn *nd_pfn = to_nd_pfn(dev); ssize_t rc; - nvdimm_bus_lock(dev); device_lock(dev); + nvdimm_bus_lock(dev); rc = nd_namespace_store(dev, &nd_pfn->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; }