From patchwork Tue Jul 19 09:21:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 72277 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp569958qga; Tue, 19 Jul 2016 02:20:19 -0700 (PDT) X-Received: by 10.98.23.134 with SMTP id 128mr53440593pfx.96.1468920019812; Tue, 19 Jul 2016 02:20:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hi6si22701065pac.108.2016.07.19.02.20.19; Tue, 19 Jul 2016 02:20:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753241AbcGSJUR (ORCPT + 29 others); Tue, 19 Jul 2016 05:20:17 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:51151 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752574AbcGSJUO (ORCPT ); Tue, 19 Jul 2016 05:20:14 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id u6J9JqMf000550; Tue, 19 Jul 2016 18:19:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com u6J9JqMf000550 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1468919994; bh=wHjtyEFhHnnzgvpYjRp/1eHE5XY1XuZQwRknT4LPAzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HeMFMdrJ84lb93IuJNaWoegIUapnIB3m21R3SVL8mk0sPm7vChcPtq3jmRPuH+Sg0 5Akji+8W8qEsp3jAzErpaMMlBlTNWpp+1399G56FOGSvkIWMA42pHX1CnGcbGN1Mij RU2U+SsQ1eC5xpcYXJmAg7hKl97SeiJglR/bb3CCBOADLbH4Bg0oiFLDmpiF9SKTZL WhhubjQQEDIq6uZ6Tta7/RiOwCXRUHjPTG9f8jSqlTv6TyuDDre0RnJ2pptk20/zsr G5Eds0Wjg7yO6EeUenLBQzsFsEDZd51C3Qi8KvGlGSh02B19n/XeAtyFzaNL1wuGcF qT0+R4Sa1kzlw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-clk@vger.kernel.org Cc: Masahiro Yamada , Stephen Boyd , Michael Turquette , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] clk: avoid adding clock provider multiple times for one node Date: Tue, 19 Jul 2016 18:21:35 +0900 Message-Id: <1468920098-8553-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468920098-8553-1-git-send-email-yamada.masahiro@socionext.com> References: <1468920098-8553-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is insane to add multiple OF clock providers against one device node. Let of_clk_add(_hw)_provider() fail with -EEXIST if the given node is already associated with an OF clock provider. Signed-off-by: Masahiro Yamada --- drivers/clk/clk.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index e8c79a7..7832343 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3038,15 +3038,24 @@ int of_clk_add_provider(struct device_node *np, struct of_clk_provider *cp; int ret; + mutex_lock(&of_clk_mutex); + + cp = __of_clk_find_provider(np); + if (cp) { + mutex_unlock(&of_clk_mutex); + return -EEXIST; + } + cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL); - if (!cp) + if (!cp) { + mutex_unlock(&of_clk_mutex); return -ENOMEM; + } cp->node = of_node_get(np); cp->data = data; cp->get = clk_src_get; - mutex_lock(&of_clk_mutex); list_add(&cp->link, &of_clk_providers); mutex_unlock(&of_clk_mutex); pr_debug("Added clock from %s\n", np->full_name); @@ -3073,15 +3082,24 @@ int of_clk_add_hw_provider(struct device_node *np, struct of_clk_provider *cp; int ret; + mutex_lock(&of_clk_mutex); + + cp = __of_clk_find_provider(np); + if (cp) { + mutex_unlock(&of_clk_mutex); + return -EEXIST; + } + cp = kzalloc(sizeof(*cp), GFP_KERNEL); - if (!cp) + if (!cp) { + mutex_unlock(&of_clk_mutex); return -ENOMEM; + } cp->node = of_node_get(np); cp->data = data; cp->get_hw = get; - mutex_lock(&of_clk_mutex); list_add(&cp->link, &of_clk_providers); mutex_unlock(&of_clk_mutex); pr_debug("Added clk_hw provider from %s\n", np->full_name);