Skip to contentSkip to conversation

clk: Declare mux tables as const u32[]

PATCH Applied Jonathan Neuschäfer 2 participants 18 messages Feb 5, 2022 – Mar 12, 2022

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

v2 cover clk: Declare mux tables as const u32[]

I noticed that the 'table' parameter to clk_register_mux_table is never used for modifying the table elements, and so it can be declared const.

In version 2 I'm addressing two warnings in the clk-lpc18xx-cgu driver that I previously missed.

Jonathan Neuschäfer (7):
clk: nxp: Remove unused variable
clk: nxp: Declare mux table parameter as const u32 *
clk: mux: Declare u32 *table parameter as const
clk: hisilicon: Remove unnecessary cast of mux table to u32 *
clk: mmp: Declare mux tables as const u32[]
clk: qcom: Declare mux table as const u32[]
clk: pistachio: Declare mux table as const u32[]

 drivers/clk/clk-mux.c                 | 10 +++++-----
 drivers/clk/hisilicon/clk.c           |  2 +-
 drivers/clk/mmp/clk-of-mmp2.c         |  4 ++--
 drivers/clk/nxp/clk-lpc18xx-cgu.c     |  5 ++---
 drivers/clk/pistachio/clk-pistachio.c |  2 +-
 drivers/clk/qcom/kpss-xcc.c           |  2 +-
 include/linux/clk-provider.h          | 12 ++++++------
 7 files changed, 18 insertions(+), 19 deletions(-)

--
2.34.1

#1 lore raw

PATCH v2 1/7 clk: nxp: Remove unused variable

GCC warns:

Quoted 4 lines

../drivers/clk/nxp/clk-lpc18xx-cgu.c: In function ‘lpc18xx_pll1_recalc_rate’:
../drivers/clk/nxp/clk-lpc18xx-cgu.c:460:13: warning: variable ‘stat’ set but not used [-Wunused-but-set-variable]

  460 |         u32 stat, ctrl;
      |             ^~~~

Get rid of the (apparently) useless read from the PLL1_STAT register and the declaration of stat.

Fixes b04e0b8fd5443 ("clk: add lpc18xx cgu clk driver")

---

If the register read is actually useful because of a side-effect, please speak up.

v2:
- New patch to address this warning

---
 drivers/clk/nxp/clk-lpc18xx-cgu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/nxp/clk-lpc18xx-cgu.c +1 -2
index 8b686da5577b3..349eebf69ed93 100644
@@ -457,9 +457,8 @@ static unsigned long lpc18xx_pll1_recalc_rate(struct clk_hw *hw,
 	struct lpc18xx_pll *pll = to_lpc_pll(hw);
 	u16 msel, nsel, psel;
 	bool direct, fbsel;
-	u32 stat, ctrl;
+	u32 ctrl;
 
-	stat = readl(pll->reg + LPC18XX_CGU_PLL1_STAT);
 	ctrl = readl(pll->reg + LPC18XX_CGU_PLL1_CTRL);
 
 	direct = (ctrl & LPC18XX_PLL1_CTRL_DIRECT) ? true : false;

--
2.34.1

maintainer Applied
#2 lore raw

Re: [PATCH v2 1/7] clk: nxp: Remove unused variable

Quoting Jonathan Neuschäfer (2022-02-05 02:36:07)

Quoted 7 lines

GCC warns:

Quoted 4 lines

../drivers/clk/nxp/clk-lpc18xx-cgu.c: In function ‘lpc18xx_pll1_recalc_rate’:
../drivers/clk/nxp/clk-lpc18xx-cgu.c:460:13: warning: variable ‘stat’ set but not used [-Wunused-but-set-variable]

  460 |         u32 stat, ctrl;
      |             ^~~~
Quoted 7 lines

Get rid of the (apparently) useless read from the PLL1_STAT register and the declaration of stat.

Fixes b04e0b8fd5443 ("clk: add lpc18xx cgu clk driver")

---

Applied to clk-next

#3 lore raw

PATCH v2 2/7 clk: nxp: Declare mux table parameter as const u32 *

In reply to Jonathan Neuschäfer

lpc18xx_fill_parent_names's "id" parameter isn't used for writing, so let's make it const.

---

v2:
- New patch

---
 drivers/clk/nxp/clk-lpc18xx-cgu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/nxp/clk-lpc18xx-cgu.c +1 -1
index 349eebf69ed93..c23ac463ab0fa 100644
@@ -522,7 +522,7 @@ static struct lpc18xx_cgu_pll_clk lpc18xx_cgu_src_clk_plls[] = {
 	LPC1XX_CGU_CLK_PLL(PLL1,	pll1_src_ids, pll1_ops),
 };
 
-static void lpc18xx_fill_parent_names(const char **parent, u32 *id, int size)
+static void lpc18xx_fill_parent_names(const char **parent, const u32 *id, int size)
 {
 	int i;
 

--
2.34.1

maintainer Applied
#4 lore raw

Re: [PATCH v2 2/7] clk: nxp: Declare mux table parameter as const u32 *

Quoting Jonathan Neuschäfer (2022-02-05 02:36:08)

Quoted 5 lines

lpc18xx_fill_parent_names's "id" parameter isn't used for writing, so let's make it const.

---

Applied to clk-next

#5 lore raw

PATCH v2 3/7 clk: mux: Declare u32 *table parameter as const

In reply to Jonathan Neuschäfer

The elements of the table are never modified in clk-mux.c. To make this clear to clock drivers, declare the parameter as const u32 *table.

---

v2:
- no changes

---
 drivers/clk/clk-mux.c        | 10 +++++-----
 include/linux/clk-provider.h | 12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/clk/clk-mux.c +5 -5
index 20582aae7a35f..214045f6e9895 100644
@@ -40,7 +40,7 @@ static inline void clk_mux_writel(struct clk_mux *mux, u32 val)
 		writel(val, mux->reg);
 }
 
-int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags,
+int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
 			 unsigned int val)
 {
 	int num_parents = clk_hw_get_num_parents(hw);
@@ -67,7 +67,7 @@ int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags,
 }
 EXPORT_SYMBOL_GPL(clk_mux_val_to_index);
 
-unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index)
+unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index)
 {
 	unsigned int val = index;
 
@@ -152,7 +152,7 @@ struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
 		const struct clk_hw **parent_hws,
 		const struct clk_parent_data *parent_data,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock)
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock)
 {
 	struct clk_mux *mux;
 	struct clk_hw *hw;
@@ -218,7 +218,7 @@ struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node
 		const struct clk_hw **parent_hws,
 		const struct clk_parent_data *parent_data,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock)
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock)
 {
 	struct clk_hw **ptr, *hw;
 
@@ -244,7 +244,7 @@ EXPORT_SYMBOL_GPL(__devm_clk_hw_register_mux);
 struct clk *clk_register_mux_table(struct device *dev, const char *name,
 		const char * const *parent_names, u8 num_parents,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock)
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock)
 {
 	struct clk_hw *hw;
 
include/linux/clk-provider.h +6 -6
index 2faa6f7aa8a87..27be575288747 100644
@@ -888,7 +888,7 @@ void clk_hw_unregister_divider(struct clk_hw *hw);
 struct clk_mux {
 	struct clk_hw	hw;
 	void __iomem	*reg;
-	u32		*table;
+	const u32	*table;
 	u32		mask;
 	u8		shift;
 	u8		flags;
@@ -913,18 +913,18 @@ struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
 		const struct clk_hw **parent_hws,
 		const struct clk_parent_data *parent_data,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock);
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
 struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
 		const char *name, u8 num_parents,
 		const char * const *parent_names,
 		const struct clk_hw **parent_hws,
 		const struct clk_parent_data *parent_data,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock);
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
 struct clk *clk_register_mux_table(struct device *dev, const char *name,
 		const char * const *parent_names, u8 num_parents,
 		unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
-		u8 clk_mux_flags, u32 *table, spinlock_t *lock);
+		u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
 
 #define clk_register_mux(dev, name, parent_names, num_parents, flags, reg,    \
 			 shift, width, clk_mux_flags, lock)		      \
@@ -962,9 +962,9 @@ struct clk *clk_register_mux_table(struct device *dev, const char *name,
 			      (shift), BIT((width)) - 1, (clk_mux_flags),     \
 			      NULL, (lock))
 
-int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags,
+int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
 			 unsigned int val);
-unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
+unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index);
 
 void clk_unregister_mux(struct clk *clk);
 void clk_hw_unregister_mux(struct clk_hw *hw);

--
2.34.1

maintainer Applied
#6 lore raw

Re: [PATCH v2 3/7] clk: mux: Declare u32 *table parameter as const

Quoting Jonathan Neuschäfer (2022-02-05 02:36:09)

Quoted 5 lines

The elements of the table are never modified in clk-mux.c. To make this clear to clock drivers, declare the parameter as const u32 *table.

---

Applied to clk-next

#7 lore raw

PATCH v2 4/7 clk: hisilicon: Remove unnecessary cast of mux table to u32 *

In reply to Jonathan Neuschäfer

Now that clk_register_mux_table takes a const u32 *, we don't need the cast anymore.

---

v2:
- no changes

---
 drivers/clk/hisilicon/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/hisilicon/clk.c +1 -1
index 9361fba7cd4cf..54d9fdc935990 100644
@@ -162,7 +162,7 @@ int hisi_clk_register_mux(const struct hisi_mux_clock *clks,
 					clks[i].num_parents, clks[i].flags,
 					base + clks[i].offset, clks[i].shift,
 					mask, clks[i].mux_flags,
-					(u32 *)clks[i].table, &hisi_clk_lock);
+					clks[i].table, &hisi_clk_lock);
 		if (IS_ERR(clk)) {
 			pr_err("%s: failed to register clock %s\n",
 			       __func__, clks[i].name);

--
2.34.1

maintainer Applied
#8 lore raw

Re: [PATCH v2 4/7] clk: hisilicon: Remove unnecessary cast of mux table to u32 *

Quoting Jonathan Neuschäfer (2022-02-05 02:36:10)

Quoted 5 lines

Now that clk_register_mux_table takes a const u32 *, we don't need the cast anymore.

---

Applied to clk-next

#9 lore raw

PATCH v2 5/7 clk: mmp: Declare mux tables as const u32[]

In reply to Jonathan Neuschäfer

Now that clk_register_mux_table takes a const u32 *, we can declare the mux tables as const u32[].

---

v2:
- no changes

---
 drivers/clk/mmp/clk-of-mmp2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/mmp/clk-of-mmp2.c +2 -2
index 0839fb2049e94..50a780274ba0c 100644
@@ -317,9 +317,9 @@ static const char * const ccic_parent_names[] = {"pll1_2", "pll1_16", "vctcxo"};
 
 static DEFINE_SPINLOCK(gpu_lock);
 static const char * const mmp2_gpu_gc_parent_names[] =  {"pll1_2", "pll1_3", "pll2_2", "pll2_3", "pll2", "usb_pll"};
-static u32 mmp2_gpu_gc_parent_table[] =          { 0x0000,   0x0040,   0x0080,   0x00c0,   0x1000, 0x1040   };
+static const u32 mmp2_gpu_gc_parent_table[] = { 0x0000,   0x0040,   0x0080,   0x00c0,   0x1000, 0x1040   };
 static const char * const mmp2_gpu_bus_parent_names[] = {"pll1_4", "pll2",   "pll2_2", "usb_pll"};
-static u32 mmp2_gpu_bus_parent_table[] =         { 0x0000,   0x0020,   0x0030,   0x4020   };
+static const u32 mmp2_gpu_bus_parent_table[] = { 0x0000,   0x0020,   0x0030,   0x4020   };
 static const char * const mmp3_gpu_bus_parent_names[] = {"pll1_4", "pll1_6", "pll1_2", "pll2_2"};
 static const char * const mmp3_gpu_gc_parent_names[] =  {"pll1",   "pll2",   "pll1_p", "pll2_p"};
 

--
2.34.1

maintainer Applied
#10 lore raw

Re: [PATCH v2 5/7] clk: mmp: Declare mux tables as const u32[]

Quoting Jonathan Neuschäfer (2022-02-05 02:36:11)

Quoted 5 lines

Now that clk_register_mux_table takes a const u32 *, we can declare the mux tables as const u32[].

---

Applied to clk-next

#11 lore raw

PATCH v2 6/7 clk: qcom: Declare mux table as const u32[]

In reply to Jonathan Neuschäfer

Now that clk_register_mux_table takes a const u32 *, we can declare the mux tables as const u32[].

---

v2:
- no changes

---
 drivers/clk/qcom/kpss-xcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/kpss-xcc.c +1 -1
index 4fec1f9142b82..88d4b33ac0cc3 100644
@@ -17,7 +17,7 @@ static const char *aux_parents[] = {
 	"pxo",
 };
 
-static unsigned int aux_parent_map[] = {
+static const u32 aux_parent_map[] = {
 	3,
 	0,
 };

--
2.34.1

maintainer Applied
#12 lore raw

Re: [PATCH v2 6/7] clk: qcom: Declare mux table as const u32[]

Quoting Jonathan Neuschäfer (2022-02-05 02:36:12)

Quoted 5 lines

Now that clk_register_mux_table takes a const u32 *, we can declare the mux tables as const u32[].

---

Applied to clk-next

#13 lore raw

PATCH v2 7/7 clk: pistachio: Declare mux table as const u32[]

In reply to Jonathan Neuschäfer

Now that clk_register_mux_table takes a const u32 *, we can declare the mux table as const u32[].

---

v2:
- no changes

---
 drivers/clk/pistachio/clk-pistachio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/pistachio/clk-pistachio.c +1 -1
index 76f492c7e917e..2a6d583237dc7 100644
@@ -154,7 +154,7 @@ static struct pistachio_pll pistachio_plls[] __initdata = {
 PNAME(mux_debug) = { "mips_pll_mux", "rpu_v_pll_mux",
 		     "rpu_l_pll_mux", "sys_pll_mux",
 		     "wifi_pll_mux", "bt_pll_mux" };
-static u32 mux_debug_idx[] = { 0x0, 0x1, 0x2, 0x4, 0x8, 0x10 };
+static const u32 mux_debug_idx[] = { 0x0, 0x1, 0x2, 0x4, 0x8, 0x10 };
 
 static unsigned int pistachio_critical_clks_core[] __initdata = {
 	CLK_MIPS

--
2.34.1

maintainer Applied
#14 lore raw

Re: [PATCH v2 7/7] clk: pistachio: Declare mux table as const u32[]

Quoting Jonathan Neuschäfer (2022-02-05 02:36:13)

Quoted 5 lines

Now that clk_register_mux_table takes a const u32 *, we can declare the mux table as const u32[].

---

Applied to clk-next

maintainer
#15 lore raw
In reply to Jonathan Neuschäfer

Quoting Jonathan Neuschäfer (2022-02-05 02:36:06)

Quoted 5 lines

I noticed that the 'table' parameter to clk_register_mux_table is never used for modifying the table elements, and so it can be declared const.

In version 2 I'm addressing two warnings in the clk-lpc18xx-cgu driver that I previously missed.

The format of these patches deeply confused my scripts that use git interpret-trailer. I fixed it now, hopefully it keeps working. In the future, please don't add more triple dash '---' sections to the patch. It looks like those extra sections for the changelog messed everything up. Or there's a new bug in interpret-trailers. Either way, interpret-trailers was adding tags after the entire patch contents because I think it looks for the last triple dash instead of the first triple dash. Not sure why it's done that way. I resorted to reconstructing the patch after splitting it with mailinfo.

#16 lore raw
Quoted 7 lines · Stephen Boyd

Quoting Jonathan Neuschäfer (2022-02-05 02:36:06)

Quoted 5 lines

I noticed that the 'table' parameter to clk_register_mux_table is never used for modifying the table elements, and so it can be declared const.

In version 2 I'm addressing two warnings in the clk-lpc18xx-cgu driver that I previously missed.

Quoted 9 lines

The format of these patches deeply confused my scripts that use git interpret-trailer. I fixed it now, hopefully it keeps working. In the future, please don't add more triple dash '---' sections to the patch. It looks like those extra sections for the changelog messed everything up. Or there's a new bug in interpret-trailers. Either way, interpret-trailers was adding tags after the entire patch contents because I think it looks for the last triple dash instead of the first triple dash. Not sure why it's done that way. I resorted to reconstructing the patch after splitting it with mailinfo.

Hmm, sorry about that.

I've used this format for a while, because it conveniently lets me keep my remarks in a git commit (rather than a patch file), until I use git format-patch to generate the final patch file.

I'm not very familiar with git interpret-trailers, but git 2.34.1 doesn't seem to get confused on my patches (or I didn't pass the right options to cause it to happen).

Jonathan

maintainer
#17 lore raw

Quoting Jonathan Neuschäfer (2022-02-26 04:40:19)

Quoted 20 lines · Stephen Boyd
Quoted 7 lines

Quoting Jonathan Neuschäfer (2022-02-05 02:36:06)

Quoted 5 lines

I noticed that the 'table' parameter to clk_register_mux_table is never used for modifying the table elements, and so it can be declared const.

In version 2 I'm addressing two warnings in the clk-lpc18xx-cgu driver that I previously missed.

Quoted 9 lines

The format of these patches deeply confused my scripts that use git interpret-trailer. I fixed it now, hopefully it keeps working. In the future, please don't add more triple dash '---' sections to the patch. It looks like those extra sections for the changelog messed everything up. Or there's a new bug in interpret-trailers. Either way, interpret-trailers was adding tags after the entire patch contents because I think it looks for the last triple dash instead of the first triple dash. Not sure why it's done that way. I resorted to reconstructing the patch after splitting it with mailinfo.

Hmm, sorry about that.

Quoted 8 lines

I've used this format for a while, because it conveniently lets me keep my remarks in a git commit (rather than a patch file), until I use git format-patch to generate the final patch file.

I'm not very familiar with git interpret-trailers, but git 2.34.1 doesn't seem to get confused on my patches (or I didn't pass the right options to cause it to happen).

It's possible it's a git bug. No worries!