Skip to contentSkip to conversation

clk: ti: divider: try to fix ti_clk_register_divider

PATCH Applied Arnd Bergmann 4 participants 9 messages Apr 19, 2017 – Apr 28, 2017

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

PATCH 1/2 clk: ti: divider: try to fix ti_clk_register_divider

The newly introduced function is entirely bogus as I found when looking at this warning:

drivers/clk/ti/divider.c: In function 'ti_clk_register_divider':
drivers/clk/ti/divider.c:460:8: error: 'reg' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Treating a 'u32' variable as a structure leads to a stack overflow here, and the register address we pass down is never initialized.

As the code in its original form makes no sense, I can only guess what the intention was, and change it to take the address from div->reg.ptr instead.

Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")
---
 drivers/clk/ti/divider.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/clk/ti/divider.c +6 -11
index d6dcb283b72b..a6d3bbfbbd31 100644
@@ -428,22 +428,17 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
 
 struct clk *ti_clk_register_divider(struct ti_clk *setup)
 {
-	struct ti_clk_divider *div;
-	struct clk_omap_reg *reg_setup;
-	u32 reg;
+	struct ti_clk_divider *div = setup->data;
+	struct clk_omap_reg reg_setup = {
+		.index = div->module,
+		.offset = div->reg,
+	};
 	u8 width;
 	u32 flags = 0;
 	u8 div_flags = 0;
 	const struct clk_div_table *table;
 	struct clk *clk;
 
-	div = setup->data;
-
-	reg_setup = (struct clk_omap_reg *)®
-
-	reg_setup->index = div->module;
-	reg_setup->offset = div->reg;
-
 	if (div->flags & CLKF_INDEX_STARTS_AT_ONE)
 		div_flags |= CLK_DIVIDER_ONE_BASED;
 
@@ -458,7 +453,7 @@ struct clk *ti_clk_register_divider(struct ti_clk *setup)
 		return (struct clk *)table;
 
 	clk = _register_divider(NULL, setup->name, div->parent,
-				flags, (void __iomem *)reg, div->bit_shift,
+				flags, &reg_setup, div->bit_shift,
 				width, div_flags, table);
 
 	if (IS_ERR(clk))
Signature · 1 line
2.9.0
#1 lore raw

PATCH 2/2 clk: ti: fix building without legacy omap3

When CONFIG_ATAGS or CONFIG_OMAP3 is disabled, we get a build error:

In file included from include/linux/clk-provider.h:15:0,

                 from drivers/clk/ti/clk.c:19:

drivers/clk/ti/clk.c: In function 'ti_clk_add_aliases':
drivers/clk/ti/clk.c:438:29: error: 'simple_clk_match_table' undeclared (first use in this function); did you mean 'simple_attr_write'?

Moving the match table down fixes it.

Fixes c17435c56bb1 ("clk: ti: add API for creating aliases automatically for simple clock types")
---
 drivers/clk/ti/clk.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clk/ti/clk.c +6 -6
index ddbad7e8d7c9..e5a1c8297a1d 100644
@@ -371,12 +371,6 @@ struct clk __init *ti_clk_register_clk(struct ti_clk *setup)
 	return clk;
 }
 
-static const struct of_device_id simple_clk_match_table[] __initconst = {
-	{ .compatible = "fixed-clock" },
-	{ .compatible = "fixed-factor-clock" },
-	{ }
-};
-
 int __init ti_clk_register_legacy_clks(struct ti_clk_alias *clks)
 {
 	struct clk *clk;
@@ -425,6 +419,12 @@ int __init ti_clk_register_legacy_clks(struct ti_clk_alias *clks)
 }
 #endif
 
+static const struct of_device_id simple_clk_match_table[] __initconst = {
+	{ .compatible = "fixed-clock" },
+	{ .compatible = "fixed-factor-clock" },
+	{ }
+};
+
 /**
  * ti_clk_add_aliases - setup clock aliases
  *
Signature · 1 line
2.9.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] clk: ti: fix building without legacy omap3

Quoted 11 lines · Arnd Bergmann

When CONFIG_ATAGS or CONFIG_OMAP3 is disabled, we get a build error:

In file included from include/linux/clk-provider.h:15:0,

                 from drivers/clk/ti/clk.c:19:

drivers/clk/ti/clk.c: In function 'ti_clk_add_aliases':
drivers/clk/ti/clk.c:438:29: error: 'simple_clk_match_table' undeclared (first use in this function); did you mean 'simple_attr_write'?

Moving the match table down fixes it.

Fixes c17435c56bb1 ("clk: ti: add API for creating aliases automatically for simple clock types")

This one is clear... I think I should start running the single SoC build testing script again before posting stuff, this is an area where I seem to fail repeatedly... sorry about that.

Quoted 35 lines
---
 drivers/clk/ti/clk.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clk/ti/clk.c +6 -6
index ddbad7e8d7c9..e5a1c8297a1d 100644
@@ -371,12 +371,6 @@ struct clk __init *ti_clk_register_clk(struct ti_clk *setup)
 	return clk;
 }
 
-static const struct of_device_id simple_clk_match_table[] __initconst = {
-	{ .compatible = "fixed-clock" },
-	{ .compatible = "fixed-factor-clock" },
-	{ }
-};
-
 int __init ti_clk_register_legacy_clks(struct ti_clk_alias *clks)
 {
 	struct clk *clk;
@@ -425,6 +419,12 @@ int __init ti_clk_register_legacy_clks(struct ti_clk_alias *clks)
 }
 #endif
 
+static const struct of_device_id simple_clk_match_table[] __initconst = {
+	{ .compatible = "fixed-clock" },
+	{ .compatible = "fixed-factor-clock" },
+	{ }
+};
+
 /**
  * ti_clk_add_aliases - setup clock aliases
  *
Applied
#3 lore raw

Re: [PATCH 2/2] clk: ti: fix building without legacy omap3

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

When CONFIG_ATAGS or CONFIG_OMAP3 is disabled, we get a build error:

In file included from include/linux/clk-provider.h:15:0,

                 from drivers/clk/ti/clk.c:19:
Quoted 8 lines

drivers/clk/ti/clk.c: In function 'ti_clk_add_aliases':
drivers/clk/ti/clk.c:438:29: error: 'simple_clk_match_table' undeclared (first use in this function); did you mean 'simple_attr_write'?

Moving the match table down fixes it.

Fixes c17435c56bb1 ("clk: ti: add API for creating aliases automatically for simple clock types")

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw
In reply to Arnd Bergmann
Quoted 52 lines · Arnd Bergmann

The newly introduced function is entirely bogus as I found when looking at this warning:

drivers/clk/ti/divider.c: In function 'ti_clk_register_divider':
drivers/clk/ti/divider.c:460:8: error: 'reg' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Treating a 'u32' variable as a structure leads to a stack overflow here, and the register address we pass down is never initialized.

As the code in its original form makes no sense, I can only guess what the intention was, and change it to take the address from div->reg.ptr instead.

Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")
---
 drivers/clk/ti/divider.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/clk/ti/divider.c +5 -10
index d6dcb283b72b..a6d3bbfbbd31 100644
@@ -428,22 +428,17 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
 
 struct clk *ti_clk_register_divider(struct ti_clk *setup)
 {
-	struct ti_clk_divider *div;
-	struct clk_omap_reg *reg_setup;
-	u32 reg;
+	struct ti_clk_divider *div = setup->data;
+	struct clk_omap_reg reg_setup = {
+		.index = div->module,
+		.offset = div->reg,
+	};
 	u8 width;
 	u32 flags = 0;
 	u8 div_flags = 0;
 	const struct clk_div_table *table;
 	struct clk *clk;
 
-	div = setup->data;
-
-	reg_setup = (struct clk_omap_reg *)®
-
-	reg_setup->index = div->module;
-	reg_setup->offset = div->reg;
-
 	if (div->flags & CLKF_INDEX_STARTS_AT_ONE)
 		div_flags |= CLK_DIVIDER_ONE_BASED;
 

drivers/clk/ti/divider.c struct clk *ti_clk_register_divider(struct ti_clk *setup) · line 459

Quoted 8 lines
drivers/clk/ti/divider.c +1 -1
@@ -458,7 +453,7 @@ struct clk *ti_clk_register_divider(struct ti_clk *setup)
 		return (struct clk *)table;
 
 	clk = _register_divider(NULL, setup->name, div->parent,
-				flags, (void __iomem *)reg, div->bit_shift,
+				flags, &reg_setup, div->bit_shift,
 				width, div_flags, table);
 
 	if (IS_ERR(clk))

Yeah seems broken. I wonder if this explains some of the omapdrm issues we're seeing in next?

Regards,

Tony

#5 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

The newly introduced function is entirely bogus as I found when looking at this warning:

drivers/clk/ti/divider.c: In function 'ti_clk_register_divider':
drivers/clk/ti/divider.c:460:8: error: 'reg' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 6 lines

Treating a 'u32' variable as a structure leads to a stack overflow here, and the register address we pass down is never initialized.

As the code in its original form makes no sense, I can only guess what the intention was, and change it to take the address from div->reg.ptr instead.

Actually, I believe the code you are fixing works before this commit:

commit 6c0afb503937a12a8d20a805fcf263e31afa9871

Author: Tero Kristo <[email protected]>
Date:   Thu Feb 9 11:24:37 2017 +0200

clk: ti: convert to use proper register definition for all accesses

... it attempted to convert all the register accesses to the new format and change the size of the clk_omap_reg in bulk but I missed converting this one. Previously the size of the clk_omap_reg definition was u32, but this was confusing and bug prone so I changed it.

The failing piece of code is only executed for legacy boot mode OMAP3 right now, which could be potentially stripped out of the kernel already (I think Tony removed the support for non-DT boot OMAP3 boards already...?) This explains why I didn't notice the issue in my local testing either.

Quoted 3 lines
Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")

So, this patch itself is fine, but the desc should be updated to reflect the above somehow.

And the "Fixes:" line should be updated to point to the commit mentioned above also.

-Tero

Quoted 10 lines
---
 drivers/clk/ti/divider.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/clk/ti/divider.c +0 -0
index d6dcb283b72b..a6d3bbfbbd31 100644
@@ -428,22 +428,17 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
 

drivers/clk/ti/divider.c struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup) · line 435

Quoted 10 lines
drivers/clk/ti/divider.c +5 -3
 struct clk *ti_clk_register_divider(struct ti_clk *setup)
 {
-	struct ti_clk_divider *div;
-	struct clk_omap_reg *reg_setup;
-	u32 reg;
+	struct ti_clk_divider *div = setup->data;
+	struct clk_omap_reg reg_setup = {
+		.index = div->module,
+		.offset = div->reg,
+	};

reg_setup here could be just named as 'reg' as I've done elsewhere.

-Tero

Quoted 26 lines
drivers/clk/ti/divider.c +1 -8
 	u8 width;
 	u32 flags = 0;
 	u8 div_flags = 0;
 	const struct clk_div_table *table;
 	struct clk *clk;
 
-	div = setup->data;
-
-	reg_setup = (struct clk_omap_reg *)&reg;
-
-	reg_setup->index = div->module;
-	reg_setup->offset = div->reg;
-
 	if (div->flags & CLKF_INDEX_STARTS_AT_ONE)
 		div_flags |= CLK_DIVIDER_ONE_BASED;
 
@@ -458,7 +453,7 @@ struct clk *ti_clk_register_divider(struct ti_clk *setup)
 		return (struct clk *)table;
 
 	clk = _register_divider(NULL, setup->name, div->parent,
-				flags, (void __iomem *)reg, div->bit_shift,
+				flags, &reg_setup, div->bit_shift,
 				width, div_flags, table);
 
 	if (IS_ERR(clk))
#6 lore raw
Quoted 36 lines · Tero Kristo
Quoted 6 lines · Arnd Bergmann

The newly introduced function is entirely bogus as I found when looking at this warning:

drivers/clk/ti/divider.c: In function 'ti_clk_register_divider':
drivers/clk/ti/divider.c:460:8: error: 'reg' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 6 lines

Treating a 'u32' variable as a structure leads to a stack overflow here, and the register address we pass down is never initialized.

As the code in its original form makes no sense, I can only guess what the intention was, and change it to take the address from div->reg.ptr instead.

Actually, I believe the code you are fixing works before this commit:

commit 6c0afb503937a12a8d20a805fcf263e31afa9871

Author: Tero Kristo <[email protected]>
Date:   Thu Feb 9 11:24:37 2017 +0200

clk: ti: convert to use proper register definition for all accesses

... it attempted to convert all the register accesses to the new format and change the size of the clk_omap_reg in bulk but I missed converting this one. Previously the size of the clk_omap_reg definition was u32, but this was confusing and bug prone so I changed it.

The failing piece of code is only executed for legacy boot mode OMAP3 right now, which could be potentially stripped out of the kernel already (I think Tony removed the support for non-DT boot OMAP3 boards already...?) This explains why I didn't notice the issue in my local testing either.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines
Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")

So, this patch itself is fine, but the desc should be updated to reflect the above somehow.

And the "Fixes:" line should be updated to point to the commit mentioned above also.

Waiting for Arnd to agree. I can also rename reg_setup to reg.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw
Quoted 12 lines · Stephen Boyd
Quoted 11 lines · Tero Kristo

On 19/04/17 20:44, Arnd Bergmann wrote:
The failing piece of code is only executed for legacy boot mode OMAP3 right now, which could be potentially stripped out of the kernel already (I think Tony removed the support for non-DT boot OMAP3 boards already...?) This explains why I didn't notice the issue in my local testing either.

Quoted 3 lines
Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")
Quoted 8 lines
Quoted 6 lines

So, this patch itself is fine, but the desc should be updated to reflect the above somehow.

And the "Fixes:" line should be updated to point to the commit mentioned above also.

Waiting for Arnd to agree. I can also rename reg_setup to reg.

Yes, it would be great if you could update the patch description that way so I don't have to send a new version. Thanks,

Arnd

#8 lore raw
Quoted 16 lines · Arnd Bergmann
Quoted 15 lines · Stephen Boyd
Quoted 14 lines · Tero Kristo

On 19/04/17 20:44, Arnd Bergmann wrote:
The failing piece of code is only executed for legacy boot mode OMAP3 right now, which could be potentially stripped out of the kernel already (I think Tony removed the support for non-DT boot OMAP3 boards already...?) This explains why I didn't notice the issue in my local testing either.

Quoted 3 lines
Fixes d96f774b2538 ("clk: ti: divider: add support for legacy divider init")

So, this patch itself is fine, but the desc should be updated to reflect the above somehow.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

And the "Fixes:" line should be updated to point to the commit mentioned above also.

Waiting for Arnd to agree. I can also rename reg_setup to reg.

Yes, it would be great if you could update the patch description that way so I don't have to send a new version. Thanks,

Ok. I came up with something and applied it to clk-next.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project