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: 2849260 Return-Path: X-Original-To: patchwork-linux-sh@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 8236F9F271 for ; Sat, 24 Aug 2013 18:29:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B17812024C for ; Sat, 24 Aug 2013 18:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5E1D2022A for ; Sat, 24 Aug 2013 18:29:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755516Ab3HXS2g (ORCPT ); Sat, 24 Aug 2013 14:28:36 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:48756 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755245Ab3HXS2e (ORCPT ); Sat, 24 Aug 2013 14:28:34 -0400 Received: by mail-ee0-f46.google.com with SMTP id c13so853838eek.33 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 Cc: linux@arm.linux.org.uk, mturquette@linaro.org, jiada_wang@mentor.com, linux-kernel@vger.kernel.org, uclinux-dist-devel@blackfin.uclinux.org, linux-mips@linux-mips.org, linux-sh@vger.kernel.org, s.nawrocki@samsung.com, Kyungmin Park 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> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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; }