linux: percpu_counter: Add initialized field

Add an 'initialized' field to struct percpu_counter to track whether
a counter has been properly initialized. Update percpu_counter_init()
to set this field and percpu_counter_initialized() to check it.

This is needed because ext4 uses percpu_counter_initialized() to check
if counters are ready before accessing them.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-30 10:55:32 -07:00
parent 24a1efb590
commit 40c2a0e3f6

View File

@@ -15,6 +15,7 @@
struct percpu_counter {
s64 count;
s64 counter; /* Alias for count - some code uses this name */
bool initialized; /* Track if counter has been initialized */
};
static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount,
@@ -22,6 +23,7 @@ static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount,
{
fbc->count = amount;
fbc->counter = amount;
fbc->initialized = true;
return 0;
}
@@ -76,7 +78,7 @@ static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
static inline bool percpu_counter_initialized(struct percpu_counter *fbc)
{
return true;
return fbc->initialized;
}
#endif /* _LINUX_PERCPU_COUNTER_H */