Skip to contentSkip to conversation

clk: add devm_add_clk_disable_unprepare

PATCH In review Heiner Kallweit 3 participants 3 messages Feb 18, 2023 – Feb 21, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: add devm_add_clk_disable_unprepare

I'm aware that there have been numerous rejected attempts to add a devm_clk_prepare_enable(). The advice I've seen was:
If you need this functionality, use devm_add_action_or_reset(). As a result lots of callers implemented their own action wrapper for clk_disable_unprepare(). Just one example: dw8250_clk_disable_unprepare This can be avoided with a little bit of cast magic, as used by few drivers already.
Helper devm_add_clk_disable_unprepare() is supposed to reduce the code duplication caused by all these individual wrappers.

---
 drivers/clk/clk-devres.c |  6 ++++++
 include/linux/clk.h      | 11 +++++++++++
 2 files changed, 17 insertions(+)
drivers/clk/clk-devres.c +6 -0
index 4fb4fd4b0..97e7c33b6 100644
@@ -222,3 +222,9 @@ struct clk *devm_get_clk_from_child(struct device *dev,
 	return clk;
 }
 EXPORT_SYMBOL(devm_get_clk_from_child);
+
+int devm_add_clk_disable_unprepare(struct device *dev, struct clk *clk)
+{
+	return devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
+}
+EXPORT_SYMBOL_GPL(devm_add_clk_disable_unprepare);
include/linux/clk.h +11 -0
index 1ef013324..c4d3b1cc0 100644
@@ -732,6 +732,17 @@ void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks);
  */
 void devm_clk_put(struct device *dev, struct clk *clk);
 
+/**
+ * devm_add_clk_disable_unprepare - device-managed call to clk_disable_unprepare
+ * @dev: device used to acquire the clock
+ * @clk: clock source acquired with devm_clk_get() et al
+ *
+ * Notes:
+ * - should only be called if clock was acquired device-managed
+ * - should not be called from within interrupt context
+ */
+int devm_add_clk_disable_unprepare(struct device *dev, struct clk *clk);
+
 /*
  * The remaining APIs are optional for machine class support.
  */
Signature · 1 line
2.39.2
#1 lore raw
I love your patch! Perhaps something to improve:

Hi Heiner,

I love your patch! Perhaps something to improve:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v6.2-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Heiner-Kallweit/clk-add-devm_add_clk_disable_unprepare/20230219-070000
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/e5d7afd3-2e1a-ad5a-a455-8882fae9cc47%40gmail.com
patch subject: [PATCH] clk: add devm_add_clk_disable_unprepare
config: arm-buildonly-randconfig-r001-20230219 (https://download.01.org/0day-ci/archive/20230219/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project db89896bbbd2251fff457699635acbbedeead27f)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/intel-lab-lkp/linux/commit/c4da42247f42760cecce516094595706f88f4bc9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Heiner-Kallweit/clk-add-devm_add_clk_disable_unprepare/20230219-070000 git checkout c4da42247f42760cecce516094595706f88f4bc9
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/clk/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/clk/clk-devres.c:228:39: warning: cast from 'void (*)(struct clk *)' to 'void (*)(void *)' converts to incompatible function type [-Wcast-function-type-strict]
           return devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning generated.

vim +228 drivers/clk/clk-devres.c

225
226 int devm_add_clk_disable_unprepare(struct device *dev, struct clk *clk)
227 {

 > 228		return devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
maintainer
#2 lore raw
In reply to Heiner Kallweit

Quoting Heiner Kallweit (2023-02-18 14:58:54)

Quoted 2 lines

I'm aware that there have been numerous rejected attempts to add a devm_clk_prepare_enable(). The advice I've seen was:

See devm_clk_get_optional_enabled()

Quoted 9 lines

If you need this functionality, use devm_add_action_or_reset(). As a result lots of callers implemented their own action wrapper for clk_disable_unprepare(). Just one example: dw8250_clk_disable_unprepare This can be avoided with a little bit of cast magic, as used by few drivers already.
Helper devm_add_clk_disable_unprepare() is supposed to reduce the code duplication caused by all these individual wrappers.