From patchwork Fri Aug 23 15:03:44 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: 2848869 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 ABFCABF546 for ; Fri, 23 Aug 2013 15:07:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 853C42034F for ; Fri, 23 Aug 2013 15:07:00 +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 1A6C72028F for ; Fri, 23 Aug 2013 15:06:59 +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 1VCswQ-0007cb-Vu; Fri, 23 Aug 2013 15:06:23 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VCsw8-00064x-8M; Fri, 23 Aug 2013 15:06:04 +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 1VCsvW-00060q-HK for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2013 15:05:28 +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 <0MRZ00IADOKCLPU0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Sat, 24 Aug 2013 00:05:00 +0900 (KST) X-AuditID: cbfee61b-b7f776d0000016c8-b4-52177a1b3077 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 01.3C.05832.B1A77125; Sat, 24 Aug 2013 00:05:00 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MRZ00M18OIHS210@mmp1.samsung.com>; Sat, 24 Aug 2013 00:04:59 +0900 (KST) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/5] clkdev: Fix race condition in clock lookup from device tree Date: Fri, 23 Aug 2013 17:03:44 +0200 Message-id: <1377270227-1030-3-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1377270227-1030-1-git-send-email-s.nawrocki@samsung.com> References: <1377270227-1030-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRmVeSWpSXmKPExsVy+t9jAV2ZKvEgg9YvPBZTHz5hs3i/cR6T Rc+fSouzTW/YLTonLmG32PT4GqvF5V1z2CwmTJ3EbjHnzxRmi9uXeS0OPFnOZvF0wkU2i9uN K9gsLu1RsTj8pp3V4v1PR4un65YwW6yf8ZrFYmHDF3aLmxN+MDuIeLQ097B5rJzu7XH5+xtm j52z7rJ7fPgY5zG7Yyarx/zpj5g9Nq3qZPO4c20Pm8fRlWuZPDYvqffY/bWJ0aNvyypGj8+b 5AL4orhsUlJzMstSi/TtErgylk+Zw16wiL9i7t+XjA2MR3m6GDk5JARMJL42L2eFsMUkLtxb z9bFyMUhJLCIUaJh8R5GCKeDSeLV9kcsIFVsAoYSvUf7GEFsEQENiSldj9lBipgFelkkpky+ CVYkLBAqsfDJdCYQm0VAVeJMfwtYA6+Aq8TePbeBajiA1ilIzJlkAxLmFHCTaF5zlgkkLARU 8neL5gRG3gWMDKsYRVMLkguKk9JzjfSKE3OLS/PS9ZLzczcxgmPkmfQOxlUNFocYBTgYlXh4 JziLBQmxJpYVV+YeYpTgYFYS4d2ZJx4kxJuSWFmVWpQfX1Sak1p8iFGag0VJnPdgq3WgkEB6 YklqdmpqQWoRTJaJg1OqgdHshNRVV63fTzY4nd/7fY9ofe0j9hXJJhFsi4XCaut3Ozipz1wv MW39mu5VWl9ateMX/d2gpKeeVNQZVPvYrmM2Qzjr9f+PEuedC5Fht3nz37zcurv3XK2m6/Tr b05PdlAWFPmU4b3jw54qg3D+HeevOiyWvdmoIPHvqa0j677JyjMZwsSOrFBiKc5INNRiLipO BAA9eQ9gjQIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130823_110526_874460_FA981B4C X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -9.7 (---------) 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, Sylwester Nawrocki , 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=-7.0 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. I.e. 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 Acked-by: Russell King Reviewed-by: Mike Turquette --- Changes since v2: - none. Changes since v1: - include "clk.h". --- drivers/clk/clkdev.c | 12 ++++++++++-- 1 file 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; }