Skip to contentSkip to conversation

clk: qcom: gpucc-sm8350: Fix "initializer element is not constant" error

PATCH Superseded Nathan Chancellor 2 participants 2 messages Jul 11, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: qcom: gpucc-sm8350: Fix "initializer element is not constant" error

When building with clang or GCC older than 8, errors along the following lines occur:

drivers/clk/qcom/gpucc-sm8350.c:111:2: error: initializer element is not a compile-time constant

          gpu_cc_parent,
          ^~~~~~~~~~~~~
  drivers/clk/qcom/gpucc-sm8350.c:126:2: error: initializer element is not a compile-time constant
          gpu_cc_parent,
          ^~~~~~~~~~~~~

2 errors generated.

The C standard allows an implementation to accept other forms of constant expressions, which GCC 8+ has chosen to do, but it is not required. To fix this error with clang and older supported versions of GCC, use a macro so that the expression can be used in a designated initializer.

Fixes 160758b05ab1 ("clk: qcom: add support for SM8350 GPUCC")
---
 drivers/clk/qcom/gpucc-sm8350.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/qcom/gpucc-sm8350.c +5 -5
index d13fa813d190..9390723f6e40 100644
@@ -51,9 +51,9 @@ static const struct alpha_pll_config gpu_cc_pll0_config = {
 	.user_ctl_hi1_val = 0x00000000,
 };
 
-static const struct clk_parent_data gpu_cc_parent = {
-	.fw_name = "bi_tcxo",
-};
+#define GPU_CC_PARENT_INIT { .fw_name = "bi_txco", }
+
+static const struct clk_parent_data gpu_cc_parent = GPU_CC_PARENT_INIT;
 
 static struct clk_alpha_pll gpu_cc_pll0 = {
 	.offset = 0x0,
@@ -108,7 +108,7 @@ static const struct parent_map gpu_cc_parent_map_0[] = {
 };
 
 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
-	gpu_cc_parent,
+	GPU_CC_PARENT_INIT,
 	{ .hw = &gpu_cc_pll0.clkr.hw },
 	{ .hw = &gpu_cc_pll1.clkr.hw },
 	{ .fw_name = "gcc_gpu_gpll0_clk_src" },
@@ -123,7 +123,7 @@ static const struct parent_map gpu_cc_parent_map_1[] = {
 };
 
 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
-	gpu_cc_parent,
+	GPU_CC_PARENT_INIT,
 	{ .hw = &gpu_cc_pll1.clkr.hw },
 	{ .fw_name = "gcc_gpu_gpll0_clk_src" },
 	{ .fw_name = "gcc_gpu_gpll0_div_clk_src" },

base-commit: 0dd8e16bfbc003b009f843e75fae4046daa08fe9

Signature · 1 line
2.37.0
#1 lore raw
Quoted 31 lines · Nathan Chancellor

When building with clang or GCC older than 8, errors along the following lines occur:

drivers/clk/qcom/gpucc-sm8350.c:111:2: error: initializer element is not a compile-time constant

          gpu_cc_parent,
          ^~~~~~~~~~~~~
  drivers/clk/qcom/gpucc-sm8350.c:126:2: error: initializer element is not a compile-time constant
          gpu_cc_parent,
          ^~~~~~~~~~~~~

2 errors generated.

The C standard allows an implementation to accept other forms of constant expressions, which GCC 8+ has chosen to do, but it is not required. To fix this error with clang and older supported versions of GCC, use a macro so that the expression can be used in a designated initializer.

Fixes 160758b05ab1 ("clk: qcom: add support for SM8350 GPUCC")
---
 drivers/clk/qcom/gpucc-sm8350.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/qcom/gpucc-sm8350.c +0 -0
index d13fa813d190..9390723f6e40 100644

drivers/clk/qcom/gpucc-sm8350.c static const struct alpha_pll_config gpu_cc_pll0_config = { · line 54

Quoted 7 lines
drivers/clk/qcom/gpucc-sm8350.c +1 -3
@@ -51,9 +51,9 @@ static const struct alpha_pll_config gpu_cc_pll0_config = {
        .user_ctl_hi1_val = 0x00000000,
 };
 
-static const struct clk_parent_data gpu_cc_parent = {
-       .fw_name = "bi_tcxo",
-};
+#define GPU_CC_PARENT_INIT { .fw_name = "bi_txco", }

Please inline this macro. It adds no additional value in my opinion

Quoted 28 lines
drivers/clk/qcom/gpucc-sm8350.c +4 -2
+
+static const struct clk_parent_data gpu_cc_parent = GPU_CC_PARENT_INIT;
 
 static struct clk_alpha_pll gpu_cc_pll0 = {
        .offset = 0x0,
@@ -108,7 +108,7 @@ static const struct parent_map gpu_cc_parent_map_0[] = {
 };
 
 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
-       gpu_cc_parent,
+       GPU_CC_PARENT_INIT,
        { .hw = &gpu_cc_pll0.clkr.hw },
        { .hw = &gpu_cc_pll1.clkr.hw },
        { .fw_name = "gcc_gpu_gpll0_clk_src" },
@@ -123,7 +123,7 @@ static const struct parent_map gpu_cc_parent_map_1[] = {
 };
 
 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
-       gpu_cc_parent,
+       GPU_CC_PARENT_INIT,
        { .hw = &gpu_cc_pll1.clkr.hw },
        { .fw_name = "gcc_gpu_gpll0_clk_src" },
        { .fw_name = "gcc_gpu_gpll0_div_clk_src" },

base-commit: 0dd8e16bfbc003b009f843e75fae4046daa08fe9 --
2.37.0

Signature · 2 lines
With best wishes
Dmitry