[PATCH v4 03/11] power: supply: max17042_battery: Use bool for init_complete
From: Vincent Cloutier
Date: Sun Jul 26 2026 - 21:15:39 EST
From: Vincent Cloutier <vincent@xxxxxxxxxxx>
init_complete is a binary state. Change it from int to bool before adding
retry support.
The initialization worker and probe path update the flag while property
reads sample it. Use READ_ONCE() and WRITE_ONCE() to make those lockless
accesses explicit.
Assisted-by: OpenCode:gpt-5.6-sol
Signed-off-by: Vincent Cloutier <vincent@xxxxxxxxxxx>
---
drivers/power/supply/max17042_battery.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 70c5d5ce945d..e11d73681a67 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -69,11 +69,11 @@ struct max17042_chip {
enum max170xx_chip_type chip_type;
struct max17042_config_data *config_data;
struct work_struct work;
- int init_complete;
int irq;
int task_period;
bool enable_current_sense;
bool enable_por_init;
+ bool init_complete;
unsigned int r_sns;
int vmin; /* in millivolts */
int vmax; /* in millivolts */
@@ -256,7 +256,7 @@ static int max17042_get_property(struct power_supply *psy,
u32 data;
u64 data64;
- if (!chip->init_complete)
+ if (!READ_ONCE(chip->init_complete))
return -EAGAIN;
switch (psp) {
@@ -1006,7 +1006,7 @@ static void max17042_init_worker(struct work_struct *work)
return;
}
- chip->init_complete = 1;
+ WRITE_ONCE(chip->init_complete, true);
}
#ifdef CONFIG_OF
@@ -1256,7 +1256,7 @@ static int max17042_probe(struct i2c_client *client, struct device *dev, int irq
return ret;
schedule_work(&chip->work);
} else {
- chip->init_complete = 1;
+ WRITE_ONCE(chip->init_complete, true);
}
return 0;
--
2.55.0