Skip to content

Commit 17d49b7

Browse files
nathanchancesre
authored andcommitted
power: supply: bq24190_charger: Fix "initializer element is not constant" error
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: ClangBuiltLinux#1973 Fixes: b150a70 ("power: supply: bq24190_charger: Add support for BQ24296") Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Justin Stitt <justinstitt@google.com> Link: https://lore.kernel.org/r/20240103-fix-bq24190_charger-vbus_desc-non-const-v1-1-115ddf798c70@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 05599b5 commit 17d49b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/power/supply/bq24190_charger.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct bq24190_dev_info {
246246
struct bq24190_chip_info {
247247
int ichg_array_size;
248248
#ifdef CONFIG_REGULATOR
249-
const struct regulator_desc vbus_desc;
249+
const struct regulator_desc *vbus_desc;
250250
#endif
251251
int (*check_chip)(struct bq24190_dev_info *bdi);
252252
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)
728728
else
729729
cfg.init_data = &bq24190_vbus_init_data;
730730
cfg.driver_data = bdi;
731-
reg = devm_regulator_register(bdi->dev, &bdi->info->vbus_desc, &cfg);
731+
reg = devm_regulator_register(bdi->dev, bdi->info->vbus_desc, &cfg);
732732
if (IS_ERR(reg)) {
733733
ret = PTR_ERR(reg);
734734
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[] = {
19751975
[BQ24190] = {
19761976
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
19771977
#ifdef CONFIG_REGULATOR
1978-
.vbus_desc = bq24190_vbus_desc,
1978+
.vbus_desc = &bq24190_vbus_desc,
19791979
#endif
19801980
.check_chip = bq24190_check_chip,
19811981
.set_chg_config = bq24190_battery_set_chg_config,
@@ -1986,7 +1986,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
19861986
[BQ24192] = {
19871987
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
19881988
#ifdef CONFIG_REGULATOR
1989-
.vbus_desc = bq24190_vbus_desc,
1989+
.vbus_desc = &bq24190_vbus_desc,
19901990
#endif
19911991
.check_chip = bq24190_check_chip,
19921992
.set_chg_config = bq24190_battery_set_chg_config,
@@ -1997,7 +1997,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
19971997
[BQ24192i] = {
19981998
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
19991999
#ifdef CONFIG_REGULATOR
2000-
.vbus_desc = bq24190_vbus_desc,
2000+
.vbus_desc = &bq24190_vbus_desc,
20012001
#endif
20022002
.check_chip = bq24190_check_chip,
20032003
.set_chg_config = bq24190_battery_set_chg_config,
@@ -2008,7 +2008,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
20082008
[BQ24196] = {
20092009
.ichg_array_size = ARRAY_SIZE(bq24190_ccc_ichg_values),
20102010
#ifdef CONFIG_REGULATOR
2011-
.vbus_desc = bq24190_vbus_desc,
2011+
.vbus_desc = &bq24190_vbus_desc,
20122012
#endif
20132013
.check_chip = bq24190_check_chip,
20142014
.set_chg_config = bq24190_battery_set_chg_config,
@@ -2019,7 +2019,7 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
20192019
[BQ24296] = {
20202020
.ichg_array_size = BQ24296_CCC_ICHG_VALUES_LEN,
20212021
#ifdef CONFIG_REGULATOR
2022-
.vbus_desc = bq24296_vbus_desc,
2022+
.vbus_desc = &bq24296_vbus_desc,
20232023
#endif
20242024
.check_chip = bq24296_check_chip,
20252025
.set_chg_config = bq24296_battery_set_chg_config,

0 commit comments

Comments
 (0)