Skip to contentSkip to conversation

clk drivers: Terminate clk_div_table with sentinel element

PATCH Superseded Jonathan Neuschäfer 2 participants 11 messages Feb 5, 2022

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover clk drivers: Terminate clk_div_table with sentinel element

I noticed that some of the clk_div_tables in different drivers are not terminated with a sentinel element. This may cause the code in clk-divider.c to read garbage that happens to be beyond the end.

This patchset fixed all instances of this bug that I could find, except for a case in drivers/phy/ti/phy-j721e-wiz.c that is already fixed in linux-next:
https://lore.kernel.org/lkml/[email protected]/

v3:
- Change the Actions patch according to Mani's comment

v2:
- Add Fixes tags

Jonathan Neuschäfer (4):
clk: actions: Terminate clk_div_table with sentinel element
clk: loongson1: Terminate clk_div_table with sentinel element
clk: hisilicon: Terminate clk_div_table with sentinel element
clk: clps711x: Terminate clk_div_table with sentinel element

 drivers/clk/actions/owl-s700.c         | 1 +
 drivers/clk/actions/owl-s900.c         | 2 +-
 drivers/clk/clk-clps711x.c             | 2 ++
 drivers/clk/hisilicon/clk-hi3559a.c    | 4 ++--
 drivers/clk/loongson1/clk-loongson1c.c | 1 +
 5 files changed, 7 insertions(+), 3 deletions(-)

--
2.34.1

#1 lore raw

PATCH v3 1/4 clk: actions: Terminate clk_div_table with sentinel element

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

In owl-s900.s, the { 0, 8 } element was probably meant to be just that, so this patch changes { 0, 8 } to { 0, 0 }.

Fixes d47317ca4ade1 ("clk: actions: Add S700 SoC clock support")
Fixes d85d20053e195 ("clk: actions: Add S900 SoC clock support")

---

v3:
- Interpret { 0, 8 } as a typo of { 0, 0 }, the sentinel element
- Add R-b tag

v2:
- Add Fixes tags

---
 drivers/clk/actions/owl-s700.c | 1 +
 drivers/clk/actions/owl-s900.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/clk/actions/owl-s700.c +1 -0
index a2f34d13fb543..617174644f728 100644
@@ -162,6 +162,7 @@ static struct clk_div_table hdmia_div_table[] = {
 
 static struct clk_div_table rmii_div_table[] = {
 	{0, 4},   {1, 10},
+	{0, 0},
 };
 
 /* divider clocks */
drivers/clk/actions/owl-s900.c +1 -1
index 790890978424a..63c4097c07ac7 100644
@@ -140,7 +140,7 @@ static struct clk_div_table rmii_ref_div_table[] = {
 
 static struct clk_div_table usb3_mac_div_table[] = {
 	{ 1, 2 }, { 2, 3 }, { 3, 4 },
-	{ 0, 8 },
+	{ 0, 0 },
 };
 
 static struct clk_div_table i2s_div_table[] = {

--
2.34.1

#2 lore raw

Re: [PATCH v3 1/4] clk: actions: Terminate clk_div_table with sentinel element

Quoted 28 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

In owl-s900.s, the { 0, 8 } element was probably meant to be just that, so this patch changes { 0, 8 } to { 0, 0 }.

Fixes d47317ca4ade1 ("clk: actions: Add S700 SoC clock support")
Fixes d85d20053e195 ("clk: actions: Add S900 SoC clock support")

---

v3:
- Interpret { 0, 8 } as a typo of { 0, 0 }, the sentinel element
- Add R-b tag

v2:
- Add Fixes tags

---
  drivers/clk/actions/owl-s700.c | 1 +
  drivers/clk/actions/owl-s900.c | 2 +-
  2 files changed, 2 insertions(+), 1 deletion(-)
drivers/clk/actions/owl-s700.c +0 -0
index a2f34d13fb543..617174644f728 100644

drivers/clk/actions/owl-s700.c static struct clk_div_table hdmia_div_table[] = { · line 165

Quoted 4 lines
drivers/clk/actions/owl-s700.c +1 -0
@@ -162,6 +162,7 @@ static struct clk_div_table hdmia_div_table[] = {
 
  static struct clk_div_table rmii_div_table[] = {
  	{0, 4},   {1, 10},
+	{0, 0},

Again, clearer to use:

        { /* sentinel */ }

(without the trailing comma, to enforce this is the last entry).

Quoted 19 lines
drivers/clk/actions/owl-s700.c +0 -0
  };
 
  /* divider clocks */
drivers/clk/actions/owl-s900.c +1 -2
index 790890978424a..63c4097c07ac7 100644
@@ -140,7 +140,7 @@ static struct clk_div_table rmii_ref_div_table[] = {
 
  static struct clk_div_table usb3_mac_div_table[] = {
  	{ 1, 2 }, { 2, 3 }, { 3, 4 },
-	{ 0, 8 },
+	{ 0, 0 },
  };
 
  static struct clk_div_table i2s_div_table[] = {
--

2.34.1

#3 lore raw

Re: [PATCH v3 1/4] clk: actions: Terminate clk_div_table with sentinel element

Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

In owl-s900.s, the { 0, 8 } element was probably meant to be just that, so this patch changes { 0, 8 } to { 0, 0 }.

Fixes d47317ca4ade1 ("clk: actions: Add S700 SoC clock support")
Fixes d85d20053e195 ("clk: actions: Add S900 SoC clock support")

---

[...]

Quoted 9 lines

drivers/clk/actions/owl-s700.c static struct clk_div_table hdmia_div_table[] = { · line 165

Quoted 3 lines

static struct clk_div_table rmii_div_table[] = {
{0, 4}, {1, 10},

drivers/clk/actions/owl-s700.c +1 -0
+	{0, 0},

Again, clearer to use:

        { /* sentinel */ }

(without the trailing comma, to enforce this is the last entry).

This style is locally consistent in the file, so anyone who reads the file will encounter { 0, 0 } elements anyway.

So, I think it makes sense to:

- Keep this patch as is (except for the trailing comma, I'll remove that)
- Add a second patch that replaces all the sentinel elements with { /* sentinel */ }

This patch can go into stable branches, and the style cleanup doesn't have to.

Best regards,
Jonathan

#4 lore raw

PATCH v3 2/4 clk: loongson1: Terminate clk_div_table with sentinel element

In reply to Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes b4626a7f4892 ("CLK: Add Loongson1C clock support")

---

v3:
- no changes

v2:
- Add Fixes and R-b tags

---
 drivers/clk/loongson1/clk-loongson1c.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/loongson1/clk-loongson1c.c +1 -0
index 703f87622cf5f..a6f9f20fc8b99 100644
@@ -37,6 +37,7 @@ static const struct clk_div_table ahb_div_table[] = {
 	[1] = { .val = 1, .div = 4 },
 	[2] = { .val = 2, .div = 3 },
 	[3] = { .val = 3, .div = 3 },
+	[4] = { /* sentinel */ },
 };
 
 void __init ls1x_clk_init(void)

--
2.34.1

#5 lore raw

Re: [PATCH v3 2/4] clk: loongson1: Terminate clk_div_table with sentinel element

Quoted 22 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes b4626a7f4892 ("CLK: Add Loongson1C clock support")

---

v3:
- no changes

v2:
- Add Fixes and R-b tags

---
  drivers/clk/loongson1/clk-loongson1c.c | 1 +
  1 file changed, 1 insertion(+)
drivers/clk/loongson1/clk-loongson1c.c +0 -0
index 703f87622cf5f..a6f9f20fc8b99 100644

drivers/clk/loongson1/clk-loongson1c.c static const struct clk_div_table ahb_div_table[] = { · line 40

Quoted 4 lines
drivers/clk/loongson1/clk-loongson1c.c +1 -0
@@ -37,6 +37,7 @@ static const struct clk_div_table ahb_div_table[] = {
  	[1] = { .val = 1, .div = 4 },
  	[2] = { .val = 2, .div = 3 },
  	[3] = { .val = 3, .div = 3 },
+	[4] = { /* sentinel */ },

Sorry for being nitpicky here, but we don't need the trailing comma, since this is the last entry.

Quoted 6 lines
drivers/clk/loongson1/clk-loongson1c.c +0 -1
  };
 
  void __init ls1x_clk_init(void)
--

2.34.1

#6 lore raw

Re: [PATCH v3 2/4] clk: loongson1: Terminate clk_div_table with sentinel element

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes b4626a7f4892 ("CLK: Add Loongson1C clock support")

---

v3:
- no changes

v2:
- Add Fixes and R-b tags

---
  drivers/clk/loongson1/clk-loongson1c.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/clk/loongson1/clk-loongson1c.c static const struct clk_div_table ahb_div_table[] = { · line 40

Quoted 9 lines
drivers/clk/loongson1/clk-loongson1c.c +1 -0
index 703f87622cf5f..a6f9f20fc8b99 100644
@@ -37,6 +37,7 @@ static const struct clk_div_table ahb_div_table[] = {
  	[1] = { .val = 1, .div = 4 },
  	[2] = { .val = 2, .div = 3 },
  	[3] = { .val = 3, .div = 3 },
+	[4] = { /* sentinel */ },

Sorry for being nitpicky here, but we don't need the trailing comma, since this is the last entry.

Good point.

Thanks,
Jonathan

#7 lore raw

PATCH v3 3/4 clk: hisilicon: Terminate clk_div_table with sentinel element

In reply to Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes 6c81966107dc0 ("clk: hisilicon: Add clock driver for hi3559A SoC")

---

v3:
- no changes

v2:
- Add Fixes tag

---
 drivers/clk/hisilicon/clk-hi3559a.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/hisilicon/clk-hi3559a.c +2 -2
index 56012a3d02192..28c2a0630474d 100644
@@ -611,8 +611,8 @@ static struct hisi_mux_clock hi3559av100_shub_mux_clks[] = {
 
 
 /* shub div clk */
-static struct clk_div_table shub_spi_clk_table[] = {{0, 8}, {1, 4}, {2, 2}};
-static struct clk_div_table shub_uart_div_clk_table[] = {{1, 8}, {2, 4}};
+static struct clk_div_table shub_spi_clk_table[] = {{0, 8}, {1, 4}, {2, 2}, {}};
+static struct clk_div_table shub_uart_div_clk_table[] = {{1, 8}, {2, 4}, {}};
 
 static struct hisi_divider_clock hi3559av100_shub_div_clks[] = {
 	{ HI3559AV100_SHUB_SPI_SOURCE_CLK, "clk_spi_clk", "shub_clk", 0, 0x20, 24, 2,

--
2.34.1

#8 lore raw

PATCH v3 4/4 clk: clps711x: Terminate clk_div_table with sentinel element

In reply to Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes 631c53478973d ("clk: Add CLPS711X clk driver")

---

v3:
- no changes

v2:
- Add Fixes tag

---
 drivers/clk/clk-clps711x.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/clk-clps711x.c +2 -0
index a2c6486ef1708..d96d96c8752c7 100644
@@ -28,11 +28,13 @@ static const struct clk_div_table spi_div_table[] = {
 	{ .val = 1, .div = 8, },
 	{ .val = 2, .div = 2, },
 	{ .val = 3, .div = 1, },
+	{}
 };
 
 static const struct clk_div_table timer_div_table[] = {
 	{ .val = 0, .div = 256, },
 	{ .val = 1, .div = 1, },
+	{}
 };
 
 struct clps711x_clk {

--
2.34.1

Reviewed-by on v3 4/4
#9 lore raw

Re: [PATCH v3 4/4] clk: clps711x: Terminate clk_div_table with sentinel element

Quoted 21 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes 631c53478973d ("clk: Add CLPS711X clk driver")

---

v3:
- no changes

v2:
- Add Fixes tag

---
  drivers/clk/clk-clps711x.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/clk/clk-clps711x.c +0 -0
index a2c6486ef1708..d96d96c8752c7 100644

drivers/clk/clk-clps711x.c static const struct clk_div_table spi_div_table[] = { · line 31

Quoted 4 lines
drivers/clk/clk-clps711x.c +1 -0
@@ -28,11 +28,13 @@ static const struct clk_div_table spi_div_table[] = {
  	{ .val = 1, .div = 8, },
  	{ .val = 2, .div = 2, },
  	{ .val = 3, .div = 1, },
+	{}

Why not use the same style on all patches? Others developers looking at this code will directly grab this is a sentinel section, instead of wondering why this empty section is here.

        { /* sentinel */ }

Anyhow the patch logic is correct, so:

drivers/clk/clk-clps711x.c static const struct clk_div_table spi_div_table[] = { · line 37

Quoted 6 lines
drivers/clk/clk-clps711x.c +1 -0
  };
 
  static const struct clk_div_table timer_div_table[] = {
  	{ .val = 0, .div = 256, },
  	{ .val = 1, .div = 1, },
+	{}

(same comment)

Quoted 6 lines
drivers/clk/clk-clps711x.c +0 -1
  };
 
  struct clps711x_clk {
--

2.34.1

#10 lore raw

Re: [PATCH v3 4/4] clk: clps711x: Terminate clk_div_table with sentinel element

Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Jonathan Neuschäfer

In order that the end of a clk_div_table can be detected, it must be terminated with a sentinel element (.div = 0).

Fixes 631c53478973d ("clk: Add CLPS711X clk driver")

---

v3:
- no changes

v2:
- Add Fixes tag

---
  drivers/clk/clk-clps711x.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/clk/clk-clps711x.c +0 -0
index a2c6486ef1708..d96d96c8752c7 100644

drivers/clk/clk-clps711x.c static const struct clk_div_table spi_div_table[] = { · line 31

Quoted 4 lines
drivers/clk/clk-clps711x.c +1 -0
@@ -28,11 +28,13 @@ static const struct clk_div_table spi_div_table[] = {
  	{ .val = 1, .div = 8, },
  	{ .val = 2, .div = 2, },
  	{ .val = 3, .div = 1, },
+	{}

Why not use the same style on all patches? Others developers looking at this code will directly grab this is a sentinel section, instead of wondering why this empty section is here.

Quoted 1 line
        { /* sentinel */ }

I found the {} style sufficient.
But ok, I'll go with { /* sentinel */ } now.

Quoted 3 lines

Anyhow the patch logic is correct, so:

Thanks!

Jonathan