diff options
author | Chungro Lee <chungro@google.com> | 2024-03-08 03:19:30 +0000 |
---|---|---|
committer | Chungro Lee <chungro@google.com> | 2024-03-15 00:38:57 +0000 |
commit | 2d13547372a20fdfe6b8e18e87627c37f409282f (patch) | |
tree | eaa865a91c9b1125458d59901410dee0fef59d75 | |
parent | bcd18b860d97b7d6bca1b7ce8336d6d16c402c62 (diff) | |
download | bms-android-gs-shusky-5.15-android14-qpr3-beta.tar.gz |
RESTRICT AUTOMERGE: maxfg: add mutex while logs the latest entryandroid-u-qpr3-beta-2.1_r0.8android-gs-shusky-5.15-android14-qpr3-beta
during running of log_learning, capture buffer can be reset by other
thread and latest_entry can be null when calls maxfg_capture_to_cstr
Bug: 328065795
Change-Id: If78499debcdd64027bacd2fc1b72c54ccdd37222
Signed-off-by: Chungro Lee <chungro@google.com>
-rw-r--r-- | max1720x_battery.c | 17 | ||||
-rw-r--r-- | maxfg_logging.c | 19 |
2 files changed, 26 insertions, 10 deletions
diff --git a/max1720x_battery.c b/max1720x_battery.c index 619c2f9..a405aae 100644 --- a/max1720x_battery.c +++ b/max1720x_battery.c @@ -2283,19 +2283,28 @@ static int max1720x_current_offset_fix(struct max1720x_chip *chip) static int max1720x_monitor_log_learning(struct max1720x_chip *chip, bool force) { - const bool seed = !chip->cb_lh.latest_entry; - bool log_it; + bool log_it, seed; char *buf; int ret; + u16* last_entry; + + mutex_lock(&chip->cb_lh.cb_wr_lock); + seed = !chip->cb_lh.latest_entry; /* do nothing if no changes on dpacc/dqacc or relaxation */ log_it = force || seed || maxfg_ce_relaxed(&chip->regmap, MAX_M5_FSTAT_RELDT | MAX_M5_FSTAT_RELDT2, (u16 *)chip->cb_lh.latest_entry); - if (!log_it) + if (!log_it) { + mutex_unlock(&chip->cb_lh.cb_wr_lock); return 0; + } ret = maxfg_capture_registers(&chip->cb_lh); + last_entry = chip->cb_lh.latest_entry; + + mutex_unlock(&chip->cb_lh.cb_wr_lock); + if (ret < 0) { dev_dbg(chip->dev, "cannot read learning parameters (%d)\n", ret); return ret; @@ -2310,7 +2319,7 @@ static int max1720x_monitor_log_learning(struct max1720x_chip *chip, bool force) return -ENOMEM; ret = maxfg_capture_to_cstr(&chip->cb_lh.config, - (u16 *)chip->cb_lh.latest_entry, + last_entry, buf, PAGE_SIZE); if (ret > 0) gbms_logbuffer_devlog(chip->monitor_log, chip->dev, diff --git a/maxfg_logging.c b/maxfg_logging.c index d4acc0a..17f5a8b 100644 --- a/maxfg_logging.c +++ b/maxfg_logging.c @@ -73,15 +73,25 @@ int maxfg_alloc_capture_buf(struct maxfg_capture_buf *buf, int slots) void maxfg_clear_capture_buf(struct maxfg_capture_buf *buf) { + int head, tail; if (!buf) return; mutex_lock(&buf->cb_wr_lock); mutex_lock(&buf->cb_rd_lock); - buf->latest_entry = NULL; - buf->cb.head = 0; - buf->cb.tail = 0; + head = buf->cb.head; + tail = buf->cb.tail; + + if (CIRC_CNT(head, tail, buf->slots)) { + head = (head + 1) & (buf->slots - 1); + + smp_wmb(); + + /* make buffer empty by (head == tail) while preserving latest_entry as a seed */ + WRITE_ONCE(buf->cb.head, head); + WRITE_ONCE(buf->cb.tail, head); + } mutex_unlock(&buf->cb_rd_lock); mutex_unlock(&buf->cb_wr_lock); @@ -125,8 +135,6 @@ int maxfg_capture_registers(struct maxfg_capture_buf *buf) int head, tail, ret; u16 *reg_val; - mutex_lock(&buf->cb_wr_lock); - head = buf->cb.head; tail = READ_ONCE(buf->cb.tail); @@ -156,7 +164,6 @@ int maxfg_capture_registers(struct maxfg_capture_buf *buf) buf->latest_entry = latest_entry; exit_done: - mutex_unlock(&buf->cb_wr_lock); return ret; } |