From patchwork Sat Aug 24 18:27:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylwester Nawrocki X-Patchwork-Id: 2849259 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 77DB0BF546 for ; Sat, 24 Aug 2013 18:29:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4CB32024C for ; Sat, 24 Aug 2013 18:29:27 +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 B2FFD2022A for ; Sat, 24 Aug 2013 18:29:26 +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 1VDIaJ-0006EP-Ah; Sat, 24 Aug 2013 18:29:15 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDIaB-0003Gx-8q; Sat, 24 Aug 2013 18:29:07 +0000 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDIa0-0003Db-6E for linux-arm-kernel@lists.infradead.org; Sat, 24 Aug 2013 18:28:58 +0000 Received: by mail-ee0-f45.google.com with SMTP id c50so852453eek.4 for ; Sat, 24 Aug 2013 11:28:33 -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=dtrcORXBig6XUyQAzMMInh8ico4kRBNfaz6/dFsBpKA=; b=iQVgeP+qSbcoeLza9JfUDXQKpBx3xchr+O8As04feNf1mbpq0zkT49FS9815pG/c9X HDDgfVeJSQU+BdZUlapO5ACrrGg8CeP9pyEtEjEXniddUQ8pDZrss2TfHQzdgV/Ffsvo mC4A6piOw9XEjP5w2JtdrzGiTnqf6vlEesDOYn95DaK85qTBeIudokUs3J9p0Mdb6Qns yczkBs8DTM4qI+fG5ORjiFp7KyONoNMx1EuiUMJHX30+24bGbL6sK9+2S3eZ+j5WM96c 3Q0YkcSK2Zxl+BJEVzWS1VKdQM+FkOlGtE/Dt5MJBtlIg7qgaIr91DOvgRXVujMsP+6i CYmw== X-Received: by 10.14.88.65 with SMTP id z41mr9837510eee.38.1377368913400; Sat, 24 Aug 2013 11:28:33 -0700 (PDT) Received: from localhost.localdomain (093105185086.warszawa.vectranet.pl. [93.105.185.86]) by mx.google.com with ESMTPSA id b45sm8446922eef.4.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 24 Aug 2013 11:28:32 -0700 (PDT) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 2/5] clkdev: Fix race condition in clock lookup from device tree Date: Sat, 24 Aug 2013 20:27:02 +0200 Message-Id: <1377368825-30715-3-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1377368825-30715-1-git-send-email-s.nawrocki@samsung.com> References: <1377368825-30715-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_142856_480077_0BE25506 X-CRM114-Status: GOOD ( 13.96 ) X-Spam-Score: -2.0 (--) Cc: linux-mips@linux-mips.org, mturquette@linaro.org, linux-sh@vger.kernel.org, jiada_wang@mentor.com, linux-kernel@vger.kernel.org, Kyungmin Park , s.nawrocki@samsung.com, uclinux-dist-devel@blackfin.uclinux.org, linux@arm.linux.org.uk 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; }