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: 10145873 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 BFA2560244 for ; Fri, 5 Jan 2018 00:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03A8728882 for ; Fri, 5 Jan 2018 00:42:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC73928885; Fri, 5 Jan 2018 00:42:42 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2B5B28882 for ; Fri, 5 Jan 2018 00:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751341AbeAEAkj (ORCPT ); Thu, 4 Jan 2018 19:40:39 -0500 Received: from vern.gendns.com ([206.190.152.46]:37635 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751108AbeAEAkg (ORCPT ); Thu, 4 Jan 2018 19:40:36 -0500 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 Cc: David Lechner , Michael Turquette , Stephen Boyd , Matthias Brugger , Heiko Stuebner , =?UTF-8?q?Emilio=20L=C3=B3pez?= , Maxime Ripard , Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.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 - vger.kernel.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: Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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[];