From patchwork Fri Jan 5 00:38:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10145849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E6DD460244 for ; Fri, 5 Jan 2018 00:41:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2917B28882 for ; Fri, 5 Jan 2018 00:41:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DC4628885; Fri, 5 Jan 2018 00:41:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C41EB28882 for ; Fri, 5 Jan 2018 00:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=g8Dy1Zj0eiaiZPQnglprnPEV3PlOu3yktgBhP9o6puo=; b=aiiD2zxL4pR1fbrA0mS+/hnFMe mpSlKI6GLbE/wEsPq0ajsJDZ8J9aK7xDAtl1csC5SUU/S9Ot5p8DBArhveP2WORaL5sxa9uyjbST7 zu89zcUo55Tlg4CiA6lNku5q1djHYyqVC8apVN+jWhdkx7paZAb/Wtcp0K6LY0hbwZ56eAUZQ/5Rn QKTLeuDQ3kQLMEJezP0MLDVTF/eAd8c74LeExHMHeMPTw0PFlnR/7NVEB2QcJMRFEcWGlCRSH4gx0 1gtbWHzYw2g7svDHrachkXXriNis0Q4QwKzNluaDZlgFTpB+icLi4gBNVsApppGcPYvWwtLnmQKPN JrsusAQQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eXG4T-0002Da-6d; Fri, 05 Jan 2018 00:41:17 +0000 Received: from vern.gendns.com ([206.190.152.46]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eXG3w-0001ph-Do; Fri, 05 Jan 2018 00:40:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=etc6sUlYivloQS2nSLtzC6QVj1PLePJfJDs2VSHyoro=; b=zjbeWYA2eW3ycaWS6lBHlCWe9 1KdOsGm9VOQZ0xY4FD+NQj7eEfsTgYaxdHHbdmZVYT067hgf91kdPgPGydZPoXLaqf5anhEwPmLPr Zv10Y3TFdJ5vkz+xIwNORxCbUsplWEKsIFgATLS32nZX5M22aw+RN4juur2NTyiPSsZij35zpQLSS LxJLTD6AlPo/M7ZHOjJSm7Ay5Memso+8lK7zN+a+hk99acCQjBsRPp32Zm9Wv9qgIjKzydoKi7pa1 LLUI2SUDBXuAN1LdXfupufndkbGlU/xao17REsQTaKC1oX+ctE6P7QDtBxKD6XODeakxBK4Vz5rCO sIi2mG6Mg==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:37626 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89) (envelope-from ) id 1eXG3h-003bYU-P2; Thu, 04 Jan 2018 19:40:30 -0500 From: David Lechner To: linux-clk@vger.kernel.org Subject: [PATCH 1/7] clk: add helper functions for managing clk_onecell_data Date: Thu, 4 Jan 2018 18:38:06 -0600 Message-Id: <1515112695-3160-2-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515112695-3160-1-git-send-email-david@lechnology.com> References: <1515112695-3160-1-git-send-email-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180104_164044_551342_B18C1DC1 X-CRM114-Status: UNSURE ( 8.39 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lechner , =?UTF-8?q?Emilio=20L=C3=B3pez?= , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Chen-Yu Tsai , linux-mediatek@lists.infradead.org, Matthias Brugger , Maxime Ripard , linux-arm-kernel@lists.infradead.org, Heiko Stuebner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds helper functions for allocating and freeing struct clk_onecell_data. Signed-off-by: David Lechner --- drivers/clk/clk.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 3 +++ 2 files changed, 52 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index e24968f..83c8df7 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3551,6 +3551,55 @@ struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data) } EXPORT_SYMBOL_GPL(of_clk_hw_simple_get); +/** + * clk_alloc_onecell_data - allocate new struct clk_onecell_data + * @num_clks: Number of clock pointers to allocate + * + * An array of clock pointers is allocated and each clock pointer is + * initialized to ERR_PTR(-ENOENT). + * + * Returns: Pointer to struct clk_onecell_data or NULL on failure. + */ +struct clk_onecell_data *clk_alloc_onecell_data(size_t num_clks) +{ + struct clk_onecell_data *clk_data; + int i; + + clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); + if (!clk_data) + return NULL; + + clk_data->clks = kcalloc(num_clks, sizeof(*clk_data->clks), GFP_KERNEL); + if (!clk_data->clks) { + kfree(clk_data); + return NULL; + } + + for (i = 0; i < num_clks; i++) + clk_data->clks[i] = ERR_PTR(-ENOENT); + + clk_data->clk_num = num_clks; + + return clk_data; +} +EXPORT_SYMBOL_GPL(clk_alloc_onecell_data); + +/** + * clk_free_onecell_data - frees @clk_data and associated resources + * @clk_data: Pointer to struct clk_onecelldata that was allocated with + * clk_alloc_onecell_data() + * + * It is safe to call this function even if @clk_data is NULL or an error value. + */ +void clk_free_onecell_data(struct clk_onecell_data *clk_data) +{ + if (IS_ERR_OR_NULL(clk_data)) + return; + + kfree(clk_data->clks); + kfree(clk_data); +} + struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) { struct clk_onecell_data *clk_data = data; diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 175a62a..b1f51f7 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -786,6 +786,9 @@ struct clk_onecell_data { unsigned int clk_num; }; +struct clk_onecell_data *clk_alloc_onecell_data(size_t num_clks); +void clk_free_onecell_data(struct clk_onecell_data *clk_data); + struct clk_hw_onecell_data { unsigned int num; struct clk_hw *hws[];