From patchwork Sat Aug 24 15:19:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylwester Nawrocki X-Patchwork-Id: 2849230 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A8B20BF546 for ; Sat, 24 Aug 2013 15:22:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF8FE20272 for ; Sat, 24 Aug 2013 15:22:05 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4AA72026F for ; Sat, 24 Aug 2013 15:22:04 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDFf1-0008DR-2B; Sat, 24 Aug 2013 15:21:55 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDFeu-0001HY-TW; Sat, 24 Aug 2013 15:21:48 +0000 Received: from mail-ea0-x235.google.com ([2a00:1450:4013:c01::235]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDFee-0001EV-8a for linux-arm-kernel@lists.infradead.org; Sat, 24 Aug 2013 15:21:33 +0000 Received: by mail-ea0-f181.google.com with SMTP id d10so797756eaj.40 for ; Sat, 24 Aug 2013 08:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NgGX+zY00StOYWBr1davkK2MYMmqt7vTY/i6a56VFyU=; b=YCLnIzfB5PwvPe0sGI6NjhO1QERVZpJsoD13mK8YOrhY8PkPh6xlV5z8aPUxykFJKo klc9ljXJ5vdqnWMSHG7x578mQTKEw6g0c4X/xiGX6w7eszW1XlsyZJIqvkpKdu/cTt9e xxE4Thz1Y/6SDu0aF+wQR+5ewtQrJylZU5BlvXot/LxM9P8zmIhxNnueoTV3NLO3NTX8 obCJN8p3MifN64moYObysNz1DfCyKc6jZml2Ew+te+azKNzLRmMp0EpVowcFlc22yHoV YHF78Ruxsbi4I6LuGdy9fuS1pj3j9cNH9rBosVWIw4Dq15fs5eh1s/L3f22ppdCXCRyH xANw== X-Received: by 10.15.48.67 with SMTP id g43mr8766311eew.17.1377357670531; Sat, 24 Aug 2013 08:21:10 -0700 (PDT) Received: from localhost.localdomain (093105185086.warszawa.vectranet.pl. [93.105.185.86]) by mx.google.com with ESMTPSA id x47sm7415825eea.16.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 24 Aug 2013 08:21:09 -0700 (PDT) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/5] clkdev: Fix race condition in clock lookup from device tree Date: Sat, 24 Aug 2013 17:19:46 +0200 Message-Id: <1377357589-13242-3-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1377357589-13242-1-git-send-email-s.nawrocki@samsung.com> References: <1377357589-13242-1-git-send-email-s.nawrocki@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130824_112132_485989_FD18F7A0 X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: -2.0 (--) Cc: linux-mips@linux-mips.org, mturquette@linaro.org, linux-sh@vger.kernel.org, jiada_wang@mentor.com, t.figa@samsung.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, ralf@linux-mips.org, kyungmin.park@samsung.com, broonie@kernel.org, vapier@gentoo.org, myungjoo.ham@samsung.com, s.nawrocki@samsung.com, uclinux-dist-devel@blackfin.uclinux.org, linux@arm.linux.org.uk, shawn.guo@linaro.org, LW@KARO-electronics.de, g.liakhovetski@gmx.de, sebastian.hesselbarth@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 There is currently a race condition in the device tree part of clk_get() function, since the pointer returned from of_clk_get_by_name() may become invalid before __clk_get() call. E.g. due to the clock provider driver remove() callback being called in between of_clk_get_by_name() and __clk_get(). Fix this by doing both the look up and __clk_get() operations with the clock providers list mutex held. This ensures that the clock pointer returned from __of_clk_get_from_provider() call and passed to __clk_get() is valid, as long as the clock supplier module first removes its clock provider instance and then does clk_unregister() on the corresponding clocks. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Reviewed-by: Mike Turquette Acked-by: Russell King --- Changes since v2: - none. Changes since v1: - include "clk.h". --- drivers/clk/clkdev.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 442a313..48f6721 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -21,6 +21,8 @@ #include #include +#include "clk.h" + static LIST_HEAD(clocks); static DEFINE_MUTEX(clocks_mutex); @@ -39,7 +41,13 @@ struct clk *of_clk_get(struct device_node *np, int index) if (rc) return ERR_PTR(rc); - clk = of_clk_get_from_provider(&clkspec); + of_clk_lock(); + clk = __of_clk_get_from_provider(&clkspec); + + if (!IS_ERR(clk) && !__clk_get(clk)) + clk = ERR_PTR(-ENOENT); + + of_clk_unlock(); of_node_put(clkspec.np); return clk; } @@ -157,7 +165,7 @@ struct clk *clk_get(struct device *dev, const char *con_id) if (dev) { clk = of_clk_get_by_name(dev->of_node, con_id); - if (!IS_ERR(clk) && __clk_get(clk)) + if (!IS_ERR(clk)) return clk; }