All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] clk: <linux/clk.h> fixes and improvements
@ 2025-12-01  9:42 Geert Uytterhoeven
  2025-12-01  9:42 ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2025-12-01  9:42 UTC (permalink / raw)
  To: Russell King, Michael Turquette, Stephen Boyd, Tero Kristo,
	Tony Lindgren, Keerthy, Russ Dill
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven

	Hi Russell, Stephen, Mike,

This patch series contains improvements for <linux/clk.h>.
The first patch fixes a bug reported by the kernel test robot.
The other patches improve readability.

Thanks for your comments!

Geert Uytterhoeven (3):
  clk: Move clk_{save,restore}_context() to COMMON_CLK section
  clk: Merge prepare and unprepare sections
  clk: Annotate #else and #endif

 include/linux/clk.h | 104 ++++++++++++++++++++++----------------------
 1 file changed, 52 insertions(+), 52 deletions(-)

-- 
2.43.0

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section
  2025-12-01  9:42 [PATCH 0/3] clk: <linux/clk.h> fixes and improvements Geert Uytterhoeven
@ 2025-12-01  9:42 ` Geert Uytterhoeven
  2025-12-01  9:42   ` [PATCH 2/3] clk: Merge prepare and unprepare sections Geert Uytterhoeven
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2025-12-01  9:42 UTC (permalink / raw)
  To: Russell King, Michael Turquette, Stephen Boyd, Tero Kristo,
	Tony Lindgren, Keerthy, Russ Dill
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven, kernel test robot

The clk_save_context() and clk_restore_context() helpers are only
implemented by the Common Clock Framework.  They are not available when
using legacy clock frameworks.  Dummy implementations are provided, but
only if no clock support is available at all.

Hence when CONFIG_HAVE_CLK=y, but CONFIG_COMMON_CLK is not enabled:

    m68k-linux-gnu-ld: drivers/net/phy/air_en8811h.o: in function `en8811h_resume':
    air_en8811h.c:(.text+0x83e): undefined reference to `clk_restore_context'
    m68k-linux-gnu-ld: drivers/net/phy/air_en8811h.o: in function `en8811h_suspend':
    air_en8811h.c:(.text+0x856): undefined reference to `clk_save_context'

Fix this by moving forward declarations and dummy implementions from the
HAVE_CLK to the COMMON_CLK section.

Fixes: 8b95d1ce3300c411 ("clk: Add functions to save/restore clock context en-masse")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202511301553.eaEz1nEW-lkp@intel.com/
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 include/linux/clk.h | 48 ++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index b607482ca77e987b..64ff118ffb1a1d7d 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -228,6 +228,23 @@ int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);
  */
 void clk_rate_exclusive_put(struct clk *clk);
 
+/**
+ * clk_save_context - save clock context for poweroff
+ *
+ * Saves the context of the clock register for powerstates in which the
+ * contents of the registers will be lost. Occurs deep within the suspend
+ * code so locking is not necessary.
+ */
+int clk_save_context(void);
+
+/**
+ * clk_restore_context - restore clock context after poweroff
+ *
+ * This occurs with all clocks enabled. Occurs deep within the resume code
+ * so locking is not necessary.
+ */
+void clk_restore_context(void);
+
 #else
 
 static inline int clk_notifier_register(struct clk *clk,
@@ -293,6 +310,13 @@ static inline int devm_clk_rate_exclusive_get(struct device *dev, struct clk *cl
 
 static inline void clk_rate_exclusive_put(struct clk *clk) {}
 
+static inline int clk_save_context(void)
+{
+	return 0;
+}
+
+static inline void clk_restore_context(void) {}
+
 #endif
 
 #ifdef CONFIG_HAVE_CLK_PREPARE
@@ -933,23 +957,6 @@ struct clk *clk_get_parent(struct clk *clk);
  */
 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
 
-/**
- * clk_save_context - save clock context for poweroff
- *
- * Saves the context of the clock register for powerstates in which the
- * contents of the registers will be lost. Occurs deep within the suspend
- * code so locking is not necessary.
- */
-int clk_save_context(void);
-
-/**
- * clk_restore_context - restore clock context after poweroff
- *
- * This occurs with all clocks enabled. Occurs deep within the resume code
- * so locking is not necessary.
- */
-void clk_restore_context(void);
-
 #else /* !CONFIG_HAVE_CLK */
 
 static inline struct clk *clk_get(struct device *dev, const char *id)
@@ -1129,13 +1136,6 @@ static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
 	return NULL;
 }
 
-static inline int clk_save_context(void)
-{
-	return 0;
-}
-
-static inline void clk_restore_context(void) {}
-
 #endif
 
 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] clk: Merge prepare and unprepare sections
  2025-12-01  9:42 ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Geert Uytterhoeven
@ 2025-12-01  9:42   ` Geert Uytterhoeven
  2026-01-16  2:51     ` Stephen Boyd
  2025-12-01  9:42   ` [PATCH 3/3] clk: Annotate #else and #endif Geert Uytterhoeven
  2026-01-16  2:51   ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Stephen Boyd
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2025-12-01  9:42 UTC (permalink / raw)
  To: Russell King, Michael Turquette, Stephen Boyd, Tero Kristo,
	Tony Lindgren, Keerthy, Russ Dill
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven

<linux/clk.h> contains two consecutive #ifdef/#else/#endif sections
that check for CONFIG_HAVE_CLK_PREPARE: one for prepare-related
functionality, and a second for unprepare-related functionality.
Reduce #ifdef clutter by merging them.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 include/linux/clk.h | 46 ++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 64ff118ffb1a1d7d..9e5291f37c50c78a 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -329,8 +329,21 @@ static inline void clk_restore_context(void) {}
  * Must not be called from within atomic context.
  */
 int clk_prepare(struct clk *clk);
+
+/**
+ * clk_unprepare - undo preparation of a clock source
+ * @clk: clock source
+ *
+ * This undoes a previously prepared clock.  The caller must balance
+ * the number of prepare and unprepare calls.
+ *
+ * Must not be called from within atomic context.
+ */
+void clk_unprepare(struct clk *clk);
+
 int __must_check clk_bulk_prepare(int num_clks,
 				  const struct clk_bulk_data *clks);
+void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
 
 /**
  * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
@@ -355,41 +368,28 @@ static inline int clk_prepare(struct clk *clk)
 	return 0;
 }
 
-static inline int __must_check
-clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks)
+static inline void clk_unprepare(struct clk *clk)
 {
 	might_sleep();
-	return 0;
 }
 
-static inline bool clk_is_enabled_when_prepared(struct clk *clk)
-{
-	return false;
-}
-#endif
-
-/**
- * clk_unprepare - undo preparation of a clock source
- * @clk: clock source
- *
- * This undoes a previously prepared clock.  The caller must balance
- * the number of prepare and unprepare calls.
- *
- * Must not be called from within atomic context.
- */
-#ifdef CONFIG_HAVE_CLK_PREPARE
-void clk_unprepare(struct clk *clk);
-void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
-#else
-static inline void clk_unprepare(struct clk *clk)
+static inline int __must_check
+clk_bulk_prepare(int num_clks, const struct clk_bulk_data *clks)
 {
 	might_sleep();
+	return 0;
 }
+
 static inline void clk_bulk_unprepare(int num_clks,
 				      const struct clk_bulk_data *clks)
 {
 	might_sleep();
 }
+
+static inline bool clk_is_enabled_when_prepared(struct clk *clk)
+{
+	return false;
+}
 #endif
 
 #ifdef CONFIG_HAVE_CLK
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] clk: Annotate #else and #endif
  2025-12-01  9:42 ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Geert Uytterhoeven
  2025-12-01  9:42   ` [PATCH 2/3] clk: Merge prepare and unprepare sections Geert Uytterhoeven
@ 2025-12-01  9:42   ` Geert Uytterhoeven
  2026-01-16  2:52     ` Stephen Boyd
  2026-01-16  2:51   ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Stephen Boyd
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2025-12-01  9:42 UTC (permalink / raw)
  To: Russell King, Michael Turquette, Stephen Boyd, Tero Kristo,
	Tony Lindgren, Keerthy, Russ Dill
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven

Annotate the #else and #endif keywords in large #ifdef/#else/#endif
sections, to improve readability.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 include/linux/clk.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 9e5291f37c50c78a..efb91604d3f667e2 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -245,7 +245,7 @@ int clk_save_context(void);
  */
 void clk_restore_context(void);
 
-#else
+#else /* !CONFIG_COMMON_CLK */
 
 static inline int clk_notifier_register(struct clk *clk,
 					struct notifier_block *nb)
@@ -317,7 +317,7 @@ static inline int clk_save_context(void)
 
 static inline void clk_restore_context(void) {}
 
-#endif
+#endif /* !CONFIG_COMMON_CLK */
 
 #ifdef CONFIG_HAVE_CLK_PREPARE
 /**
@@ -361,7 +361,7 @@ void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks);
  * to be right.
  */
 bool clk_is_enabled_when_prepared(struct clk *clk);
-#else
+#else /* !CONFIG_HAVE_CLK_PREPARE */
 static inline int clk_prepare(struct clk *clk)
 {
 	might_sleep();
@@ -390,7 +390,7 @@ static inline bool clk_is_enabled_when_prepared(struct clk *clk)
 {
 	return false;
 }
-#endif
+#endif /* !CONFIG_HAVE_CLK_PREPARE */
 
 #ifdef CONFIG_HAVE_CLK
 /**
@@ -1136,7 +1136,7 @@ static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
 	return NULL;
 }
 
-#endif
+#endif /* !CONFIG_HAVE_CLK */
 
 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
 static inline int clk_prepare_enable(struct clk *clk)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section
  2025-12-01  9:42 ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Geert Uytterhoeven
  2025-12-01  9:42   ` [PATCH 2/3] clk: Merge prepare and unprepare sections Geert Uytterhoeven
  2025-12-01  9:42   ` [PATCH 3/3] clk: Annotate #else and #endif Geert Uytterhoeven
@ 2026-01-16  2:51   ` Stephen Boyd
  2 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2026-01-16  2:51 UTC (permalink / raw)
  To: Geert Uytterhoeven, Keerthy, Michael Turquette, Russ Dill,
	Russell King, Tero Kristo, Tony Lindgren
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven, kernel test robot

Quoting Geert Uytterhoeven (2025-12-01 02:42:26)
> The clk_save_context() and clk_restore_context() helpers are only
> implemented by the Common Clock Framework.  They are not available when
> using legacy clock frameworks.  Dummy implementations are provided, but
> only if no clock support is available at all.
> 
> Hence when CONFIG_HAVE_CLK=y, but CONFIG_COMMON_CLK is not enabled:
> 
>     m68k-linux-gnu-ld: drivers/net/phy/air_en8811h.o: in function `en8811h_resume':
>     air_en8811h.c:(.text+0x83e): undefined reference to `clk_restore_context'
>     m68k-linux-gnu-ld: drivers/net/phy/air_en8811h.o: in function `en8811h_suspend':
>     air_en8811h.c:(.text+0x856): undefined reference to `clk_save_context'
> 
> Fix this by moving forward declarations and dummy implementions from the
> HAVE_CLK to the COMMON_CLK section.
> 
> Fixes: 8b95d1ce3300c411 ("clk: Add functions to save/restore clock context en-masse")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202511301553.eaEz1nEW-lkp@intel.com/
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] clk: Merge prepare and unprepare sections
  2025-12-01  9:42   ` [PATCH 2/3] clk: Merge prepare and unprepare sections Geert Uytterhoeven
@ 2026-01-16  2:51     ` Stephen Boyd
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2026-01-16  2:51 UTC (permalink / raw)
  To: Geert Uytterhoeven, Keerthy, Michael Turquette, Russ Dill,
	Russell King, Tero Kristo, Tony Lindgren
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven

Quoting Geert Uytterhoeven (2025-12-01 02:42:27)
> <linux/clk.h> contains two consecutive #ifdef/#else/#endif sections
> that check for CONFIG_HAVE_CLK_PREPARE: one for prepare-related
> functionality, and a second for unprepare-related functionality.
> Reduce #ifdef clutter by merging them.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] clk: Annotate #else and #endif
  2025-12-01  9:42   ` [PATCH 3/3] clk: Annotate #else and #endif Geert Uytterhoeven
@ 2026-01-16  2:52     ` Stephen Boyd
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2026-01-16  2:52 UTC (permalink / raw)
  To: Geert Uytterhoeven, Keerthy, Michael Turquette, Russ Dill,
	Russell King, Tero Kristo, Tony Lindgren
  Cc: linux-clk, linux-kernel, Geert Uytterhoeven

Quoting Geert Uytterhoeven (2025-12-01 02:42:28)
> Annotate the #else and #endif keywords in large #ifdef/#else/#endif
> sections, to improve readability.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-16  2:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01  9:42 [PATCH 0/3] clk: <linux/clk.h> fixes and improvements Geert Uytterhoeven
2025-12-01  9:42 ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Geert Uytterhoeven
2025-12-01  9:42   ` [PATCH 2/3] clk: Merge prepare and unprepare sections Geert Uytterhoeven
2026-01-16  2:51     ` Stephen Boyd
2025-12-01  9:42   ` [PATCH 3/3] clk: Annotate #else and #endif Geert Uytterhoeven
2026-01-16  2:52     ` Stephen Boyd
2026-01-16  2:51   ` [PATCH 1/3] clk: Move clk_{save,restore}_context() to COMMON_CLK section Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.