[PATCH 2/5] clk: Inline clk_get_*_optional

Sean Anderson seanga2 at gmail.com
Wed Dec 1 19:43:29 CET 2021


The optional varients of clk_get_* functions are just simple wrappers.
Reduce code size a bit by inlining them. On platforms where it is not used
(most of them), it will not be compiled in any more. On platforms where
they are used, the inlined branch should not cause any significant growth.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 drivers/clk/clk-uclass.c | 22 ---------------
 include/clk.h            | 58 ++++++++++++++++++++++++----------------
 2 files changed, 35 insertions(+), 45 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 18699d69e3..168fb67019 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -432,18 +432,6 @@ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk)
 	return clk_get_by_index_nodev(node, index, clk);
 }
 
-int clk_get_by_name_nodev_optional(ofnode node, const char *name,
-				   struct clk *clk)
-{
-	int ret;
-
-	ret = clk_get_by_name_nodev(node, name, clk);
-	if (ret == -ENODATA)
-		return 0;
-
-	return ret;
-}
-
 int clk_release_all(struct clk *clk, int count)
 {
 	int i, ret;
@@ -824,16 +812,6 @@ struct clk *devm_clk_get(struct udevice *dev, const char *id)
 	return clk;
 }
 
-struct clk *devm_clk_get_optional(struct udevice *dev, const char *id)
-{
-	struct clk *clk = devm_clk_get(dev, id);
-
-	if (PTR_ERR(clk) == -ENODATA)
-		return NULL;
-
-	return clk;
-}
-
 void devm_clk_put(struct udevice *dev, struct clk *clk)
 {
 	int rc;
diff --git a/include/clk.h b/include/clk.h
index 943c87f3c3..c3d4cc0ecf 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -193,22 +193,6 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
  */
 int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk);
 
-/**
- * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name
- *		without a device.
- * @node:	The client ofnode.
- * @name:	The name of the clock to request.
- * @name:	The name of the clock to request, within the client's list of
- *		clocks.
- * @clock:	A pointer to a clock struct to initialize.
- *
- * Behaves the same as clk_get_by_name_nodev() except where there is
- * no clock producer, in this case, skip the error number -ENODATA, and
- * the function returns 0.
- */
-int clk_get_by_name_nodev_optional(ofnode node, const char *name,
-				   struct clk *clk);
-
 /**
  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
  * @dev: device for clock "consumer"
@@ -238,7 +222,16 @@ struct clk *devm_clk_get(struct udevice *dev, const char *id);
  * Behaves the same as devm_clk_get() except where there is no clock producer.
  * In this case, instead of returning -ENOENT, the function returns NULL.
  */
-struct clk *devm_clk_get_optional(struct udevice *dev, const char *id);
+static inline struct clk *devm_clk_get_optional(struct udevice *dev,
+						const char *id)
+{
+	struct clk *clk = devm_clk_get(dev, id);
+
+	if (PTR_ERR(clk) == -ENODATA)
+		return NULL;
+
+	return clk;
+}
 
 /**
  * clk_release_all() - Disable (turn off)/Free an array of previously
@@ -291,18 +284,37 @@ clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk)
 	return -ENOSYS;
 }
 
-static inline int
-clk_get_by_name_nodev_optional(ofnode node, const char *name, struct clk *clk)
-{
-	return -ENOSYS;
-}
-
 static inline int clk_release_all(struct clk *clk, int count)
 {
 	return -ENOSYS;
 }
 #endif
 
+/**
+ * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name
+ *		without a device.
+ * @node:	The client ofnode.
+ * @name:	The name of the clock to request.
+ * @name:	The name of the clock to request, within the client's list of
+ *		clocks.
+ * @clock:	A pointer to a clock struct to initialize.
+ *
+ * Behaves the same as clk_get_by_name_nodev() except where there is
+ * no clock producer, in this case, skip the error number -ENODATA, and
+ * the function returns 0.
+ */
+static inline int clk_get_by_name_nodev_optional(ofnode node, const char *name,
+						 struct clk *clk)
+{
+	int ret;
+
+	ret = clk_get_by_name_nodev(node, name, clk);
+	if (ret == -ENODATA)
+		return 0;
+
+	return ret;
+}
+
 /**
  * enum clk_defaults_stage - What stage clk_set_defaults() is called at
  * @CLK_DEFAULTS_PRE: Called before probe. Setting of defaults for clocks owned
-- 
2.33.0



More information about the U-Boot mailing list