public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: linux-clk@vger.kernel.org
Cc: "David Lechner" <david@lechnology.com>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@codeaurora.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Heiko Stuebner" <heiko@sntech.de>,
	"Emilio López" <emilio@elopez.com.ar>,
	"Maxime Ripard" <maxime.ripard@free-electrons.com>,
	"Chen-Yu Tsai" <wens@csie.org>,
	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	[thread overview]
Message-ID: <1515112695-3160-2-git-send-email-david@lechnology.com> (raw)
In-Reply-To: <1515112695-3160-1-git-send-email-david@lechnology.com>

This adds helper functions for allocating and freeing struct
clk_onecell_data.

Signed-off-by: David Lechner <david@lechnology.com>
---
 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[];
-- 
2.7.4

  reply	other threads:[~2018-01-05  0:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-05  0:38 [PATCH 0/7] clk: add helper functions for managing clk_onecell_data David Lechner
2018-01-05  0:38 ` David Lechner [this message]
2018-01-05  0:38 ` [PATCH 2/7] clk: mediatek: make use of clk_alloc_onecell_data() David Lechner
2018-01-05  0:38 ` [PATCH 3/7] clk: qoriq: " David Lechner
2018-01-05  0:38 ` [PATCH 4/7] clk: hisilicon: " David Lechner
2018-01-05  0:38 ` [PATCH 5/7] clk: rockchip: " David Lechner
2018-01-05  0:38 ` [PATCH 6/7] clk: st: " David Lechner
2018-01-05  0:38 ` [PATCH 7/7] clk: sunxi: " David Lechner
2018-03-16 22:29 ` [PATCH 0/7] clk: add helper functions for managing clk_onecell_data Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515112695-3160-2-git-send-email-david@lechnology.com \
    --to=david@lechnology.com \
    --cc=emilio@elopez.com.ar \
    --cc=heiko@sntech.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@codeaurora.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox