From patchwork Fri Aug 9 16:34:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 2842017 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 58F009F271 for ; Fri, 9 Aug 2013 16:35:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 366F0200E3 for ; Fri, 9 Aug 2013 16:35:28 +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 04D54200DB for ; Fri, 9 Aug 2013 16:35:27 +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 1V7ped-00035d-1n; Fri, 09 Aug 2013 16:35:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7peW-0002ks-4E; Fri, 09 Aug 2013 16:35:00 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7peJ-0002iu-Vn for linux-arm-kernel@lists.infradead.org; Fri, 09 Aug 2013 16:34:48 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MR900GTYVDJPBM0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Sat, 10 Aug 2013 01:34:32 +0900 (KST) X-AuditID: cbfee61b-b7efe6d000007b11-75-52051a177334 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 2A.BF.31505.71A15025; Sat, 10 Aug 2013 01:34:32 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MR900KZ8VCXG190@mmp2.samsung.com>; Sat, 10 Aug 2013 01:34:31 +0900 (KST) From: Sylwester Nawrocki To: linux@arm.linux.org.uk, mturquette@linaro.org Subject: [PATCH RFC 2/2] clkdev: Fix race condition in clock lookup from device tree Date: Fri, 09 Aug 2013 18:34:06 +0200 Message-id: <1376066046-16037-3-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1376066046-16037-1-git-send-email-s.nawrocki@samsung.com> References: <1376066046-16037-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOLMWRmVeSWpSXmKPExsVy+t9jQV0JKdYgg1nXWC0O/NnBaHG26Q27 xabHQO7ty7wWTydcZLM4vOIAk8XhN+2sFutnvGZx4PBoae5h81jw+Qq7x51re9g8Ni+p9+jb sooxgDWKyyYlNSezLLVI3y6BK+Plm5NsBX95Ki4t+cHcwHiXq4uRk0NCwETi4v6VzBC2mMSF e+vZuhi5OIQEpjNKvF/zhB3C6WCS2NV+lgmkik3AUKL3aB8jiC0CZH89+ZYJpIhZYBejxIxp 91lAEsICYRJPP7ewgtgsAqoS36f/Amrg4OAVcJOY32wPYkoIKEjMmWQDUsEp4C6xbPt1sPFC QBXv/z5gmcDIu4CRYRWjaGpBckFxUnqukV5xYm5xaV66XnJ+7iZGcHA9k97BuKrB4hCjAAej Eg/vhF8sQUKsiWXFlbmHGCU4mJVEeF9zsQYJ8aYkVlalFuXHF5XmpBYfYpTmYFES5z3Yah0o JJCeWJKanZpakFoEk2Xi4JRqYBRzzVdtuZh84L1ubMnKkt+LX4jd8PmVsmrH1cOHQx+eiDle +Vi7++oRhS/zFhaouZbZsS8yiXpQ/nMtzym7kgUMl0Ld9hyZZZe9U3m/dmOe06fHD5fIZW/a pHa274tC0aYpwq9zXN6+fJio8WDaQ7bEDvHLR6/McVv+2ssls2+5+sL1MyN6LB8qsRRnJBpq MRcVJwIAGO0v8SoCAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130809_123448_237688_D3BE9B39 X-CRM114-Status: GOOD ( 12.29 ) X-Spam-Score: -6.9 (------) Cc: t.figa@samsung.com, rob.herring@calxeda.com, kyungmin.park@samsung.com, Sylwester Nawrocki , grant.likely@linaro.org, linux-arm-kernel@lists.infradead.org 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 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. For example, 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 --- drivers/clk/clkdev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 1.7.9.5 diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 442a313..4f5c4ef 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -39,7 +39,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 +163,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; }