* [PATCH] power: supply: bq24190_charger: Fix "initializer element is not constant" error
@ 2024-01-03 16:57 Nathan Chancellor
2024-01-05 21:59 ` Justin Stitt
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2024-01-03 16:57 UTC (permalink / raw)
To: sre; +Cc: chenhuiz, linux-pm, llvm, patches, Nathan Chancellor
When building with a version of GCC prior to 8.x, there is an error
around non-constant initializer elements:
drivers/power/supply/bq24190_charger.c:1978:16: error: initializer element is not constant
.vbus_desc = bq24190_vbus_desc,
^~~~~~~~~~~~~~~~~
drivers/power/supply/bq24190_charger.c:1978:16: note: (near initialization for 'bq24190_chip_info_tbl[0].vbus_desc')
drivers/power/supply/bq24190_charger.c:1989:16: error: initializer element is not constant
.vbus_desc = bq24190_vbus_desc,
^~~~~~~~~~~~~~~~~
drivers/power/supply/bq24190_charger.c:1989:16: note: (near initialization for 'bq24190_chip_info_tbl[1].vbus_desc')
drivers/power/supply/bq24190_charger.c:2000:16: error: initializer element is not constant
.vbus_desc = bq24190_vbus_desc,
^~~~~~~~~~~~~~~~~
drivers/power/supply/bq24190_charger.c:2000:16: note: (near initialization for 'bq24190_chip_info_tbl[2].vbus_desc')
drivers/power/supply/bq24190_charger.c:2011:16: error: initializer element is not constant
.vbus_desc = bq24190_vbus_desc,
^~~~~~~~~~~~~~~~~
drivers/power/supply/bq24190_charger.c:2011:16: note: (near initialization for 'bq24190_chip_info_tbl[3].vbus_desc')
drivers/power/supply/bq24190_charger.c:2022:16: error: initializer element is not constant
.vbus_desc = bq24296_vbus_desc,
^~~~~~~~~~~~~~~~~
drivers/power/supply/bq24190_charger.c:2022:16: note: (near initialization for 'bq24190_chip_info_tbl[4].vbus_desc')
Clang versions prior to 17.x show a similar error:
drivers/power/supply/bq24190_charger.c:1978:16: error: initializer element is not a compile-time constant
.vbus_desc = bq24190_vbus_desc,
^~~~~~~~~~~~~~~~~
1 error generated.
Newer compilers have decided to accept these structures as compile time
constants as an extension. To resolve this issue for all supported
compilers, change the vbus_desc member in 'struct bq24190_chip_info' to
a pointer, as it is only ever passed by reference anyways, and adjust
the assignments accordingly.
Closes: https://github.com/ClangBuiltLinux/linux/issues/1973
Fixes: b150a703b56f ("power: supply: bq24190_charger: Add support for BQ24296")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
drivers/power/supply/bq24190_charger.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index a8995a21fadb..2b393eb5c282 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -246,7 +246,7 @@ struct bq24190_dev_info {
struct bq24190_chip_info {
int ichg_array_size;
#ifdef CONFIG_REGULATOR
- const struct regulator_desc vbus_desc;
+ const struct regulator_desc *vbus_desc;
#endif
int (*check_chip)(struct bq24190_dev_info *bdi);
int (*set_chg_config)(struct bq24190_dev_info *bdi, const u8 chg_config);
@@ -728,7 +728,7 @@ static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
else
cfg.init_data = &bq24190_vbus_init_data;
cfg.driver_data = bdi;
- reg = devm_regulator_register(bdi->dev, &bdi->info->vbus_desc, &cfg);
+ reg = devm_regulator_register(bdi->dev, bdi->info->vbus_desc, &cfg);
if (IS_ERR(reg)) {
ret = PTR_ERR(reg);
dev_err(bdi->dev, "Can't register regulator: %d\n", ret);
@@ -1975,7 +1975,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
[BQ24190] = {
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
#ifdef CONFIG_REGULATOR
- .vbus_desc = bq24190_vbus_desc,
+ .vbus_desc = &bq24190_vbus_desc,
#endif
.check_chip = bq24190_check_chip,
.set_chg_config = bq24190_battery_set_chg_config,
@@ -1986,7 +1986,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
[BQ24192] = {
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
#ifdef CONFIG_REGULATOR
- .vbus_desc = bq24190_vbus_desc,
+ .vbus_desc = &bq24190_vbus_desc,
#endif
.check_chip = bq24190_check_chip,
.set_chg_config = bq24190_battery_set_chg_config,
@@ -1997,7 +1997,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
[BQ24192i] = {
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
#ifdef CONFIG_REGULATOR
- .vbus_desc = bq24190_vbus_desc,
+ .vbus_desc = &bq24190_vbus_desc,
#endif
.check_chip = bq24190_check_chip,
.set_chg_config = bq24190_battery_set_chg_config,
@@ -2008,7 +2008,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
[BQ24196] = {
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
#ifdef CONFIG_REGULATOR
- .vbus_desc = bq24190_vbus_desc,
+ .vbus_desc = &bq24190_vbus_desc,
#endif
.check_chip = bq24190_check_chip,
.set_chg_config = bq24190_battery_set_chg_config,
@@ -2019,7 +2019,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
[BQ24296] = {
.ichg_array_size = BQ24296_CCC_ICHG_VALUES_LEN,
#ifdef CONFIG_REGULATOR
- .vbus_desc = bq24296_vbus_desc,
+ .vbus_desc = &bq24296_vbus_desc,
#endif
.check_chip = bq24296_check_chip,
.set_chg_config = bq24296_battery_set_chg_config,
---
base-commit: b150a703b56fb6eb282d059b421652ccd9155c23
change-id: 20240103-fix-bq24190_charger-vbus_desc-non-const-c6bf001dc69d
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: bq24190_charger: Fix "initializer element is not constant" error
2024-01-03 16:57 [PATCH] power: supply: bq24190_charger: Fix "initializer element is not constant" error Nathan Chancellor
@ 2024-01-05 21:59 ` Justin Stitt
0 siblings, 0 replies; 2+ messages in thread
From: Justin Stitt @ 2024-01-05 21:59 UTC (permalink / raw)
To: Nathan Chancellor; +Cc: sre, chenhuiz, linux-pm, llvm, patches
On Wed, Jan 03, 2024 at 09:57:07AM -0700, Nathan Chancellor wrote:
> When building with a version of GCC prior to 8.x, there is an error
> around non-constant initializer elements:
>
> drivers/power/supply/bq24190_charger.c:1978:16: error: initializer element is not constant
> .vbus_desc = bq24190_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> drivers/power/supply/bq24190_charger.c:1978:16: note: (near initialization for 'bq24190_chip_info_tbl[0].vbus_desc')
> drivers/power/supply/bq24190_charger.c:1989:16: error: initializer element is not constant
> .vbus_desc = bq24190_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> drivers/power/supply/bq24190_charger.c:1989:16: note: (near initialization for 'bq24190_chip_info_tbl[1].vbus_desc')
> drivers/power/supply/bq24190_charger.c:2000:16: error: initializer element is not constant
> .vbus_desc = bq24190_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> drivers/power/supply/bq24190_charger.c:2000:16: note: (near initialization for 'bq24190_chip_info_tbl[2].vbus_desc')
> drivers/power/supply/bq24190_charger.c:2011:16: error: initializer element is not constant
> .vbus_desc = bq24190_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> drivers/power/supply/bq24190_charger.c:2011:16: note: (near initialization for 'bq24190_chip_info_tbl[3].vbus_desc')
> drivers/power/supply/bq24190_charger.c:2022:16: error: initializer element is not constant
> .vbus_desc = bq24296_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> drivers/power/supply/bq24190_charger.c:2022:16: note: (near initialization for 'bq24190_chip_info_tbl[4].vbus_desc')
>
> Clang versions prior to 17.x show a similar error:
>
> drivers/power/supply/bq24190_charger.c:1978:16: error: initializer element is not a compile-time constant
> .vbus_desc = bq24190_vbus_desc,
> ^~~~~~~~~~~~~~~~~
> 1 error generated.
>
> Newer compilers have decided to accept these structures as compile time
> constants as an extension. To resolve this issue for all supported
> compilers, change the vbus_desc member in 'struct bq24190_chip_info' to
> a pointer, as it is only ever passed by reference anyways, and adjust
> the assignments accordingly.
>
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1973
> Fixes: b150a703b56f ("power: supply: bq24190_charger: Add support for BQ24296")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
Since vbus_desc is only ever used as a reference this change to a
pointer is valid and shouldn't require any further changes other than
the ones present in this patch.
Reviewed-by: Justin Stitt <justinstitt@google.com>
> drivers/power/supply/bq24190_charger.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
> index a8995a21fadb..2b393eb5c282 100644
> --- a/drivers/power/supply/bq24190_charger.c
> +++ b/drivers/power/supply/bq24190_charger.c
> @@ -246,7 +246,7 @@ struct bq24190_dev_info {
> struct bq24190_chip_info {
> int ichg_array_size;
> #ifdef CONFIG_REGULATOR
> - const struct regulator_desc vbus_desc;
> + const struct regulator_desc *vbus_desc;
> #endif
> int (*check_chip)(struct bq24190_dev_info *bdi);
> int (*set_chg_config)(struct bq24190_dev_info *bdi, const u8 chg_config);
> @@ -728,7 +728,7 @@ static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
> else
> cfg.init_data = &bq24190_vbus_init_data;
> cfg.driver_data = bdi;
> - reg = devm_regulator_register(bdi->dev, &bdi->info->vbus_desc, &cfg);
> + reg = devm_regulator_register(bdi->dev, bdi->info->vbus_desc, &cfg);
> if (IS_ERR(reg)) {
> ret = PTR_ERR(reg);
> dev_err(bdi->dev, "Can't register regulator: %d\n", ret);
> @@ -1975,7 +1975,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
> [BQ24190] = {
> .ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
> #ifdef CONFIG_REGULATOR
> - .vbus_desc = bq24190_vbus_desc,
> + .vbus_desc = &bq24190_vbus_desc,
> #endif
> .check_chip = bq24190_check_chip,
> .set_chg_config = bq24190_battery_set_chg_config,
> @@ -1986,7 +1986,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
> [BQ24192] = {
> .ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
> #ifdef CONFIG_REGULATOR
> - .vbus_desc = bq24190_vbus_desc,
> + .vbus_desc = &bq24190_vbus_desc,
> #endif
> .check_chip = bq24190_check_chip,
> .set_chg_config = bq24190_battery_set_chg_config,
> @@ -1997,7 +1997,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
> [BQ24192i] = {
> .ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
> #ifdef CONFIG_REGULATOR
> - .vbus_desc = bq24190_vbus_desc,
> + .vbus_desc = &bq24190_vbus_desc,
> #endif
> .check_chip = bq24190_check_chip,
> .set_chg_config = bq24190_battery_set_chg_config,
> @@ -2008,7 +2008,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
> [BQ24196] = {
> .ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
> #ifdef CONFIG_REGULATOR
> - .vbus_desc = bq24190_vbus_desc,
> + .vbus_desc = &bq24190_vbus_desc,
> #endif
> .check_chip = bq24190_check_chip,
> .set_chg_config = bq24190_battery_set_chg_config,
> @@ -2019,7 +2019,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
> [BQ24296] = {
> .ichg_array_size = BQ24296_CCC_ICHG_VALUES_LEN,
> #ifdef CONFIG_REGULATOR
> - .vbus_desc = bq24296_vbus_desc,
> + .vbus_desc = &bq24296_vbus_desc,
> #endif
> .check_chip = bq24296_check_chip,
> .set_chg_config = bq24296_battery_set_chg_config,
>
> ---
> base-commit: b150a703b56fb6eb282d059b421652ccd9155c23
> change-id: 20240103-fix-bq24190_charger-vbus_desc-non-const-c6bf001dc69d
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>
Thanks
Justin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-05 21:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-03 16:57 [PATCH] power: supply: bq24190_charger: Fix "initializer element is not constant" error Nathan Chancellor
2024-01-05 21:59 ` Justin Stitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox