google_battery: populate sysfs nodes in driver probe
Move the invocation of sysfs nodes populating functions batt_init_fs() & batt_bpst_init_fs() from driver init_work to driver probe to avoid unexpected racing when accessing from init.rc
Bug: 231461256
Test: all the populated nodes are chown to system:system
Signed-off-by: Ken Yang <[email protected]>
Change-Id: Ief9bc4e7ced1afabf3c2e845376d67d40de30e46
diff --git a/google_battery.c b/google_battery.c
index 724522d..d21155e 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -6734,7 +6734,6 @@
static int batt_init_fs(struct batt_drv *batt_drv)
{
- struct dentry *de = NULL;
int ret;
/* stats */
@@ -6907,6 +6906,14 @@
if (ret)
dev_err(&batt_drv->psy->dev, "Failed to create dev sn\n");
+ return 0;
+
+}
+
+static int batt_init_debugfs(struct batt_drv *batt_drv)
+{
+ struct dentry *de = NULL;
+
de = debugfs_create_dir("google_battery", 0);
if (IS_ERR_OR_NULL(de))
return 0;
@@ -6980,7 +6987,6 @@
/* bpst detection */
static int batt_bpst_init_fs(struct batt_drv *batt_drv)
{
- struct dentry *de = NULL;
int ret;
if (!batt_drv->bpst_state.bpst_enable)
@@ -6993,6 +6999,14 @@
if (ret)
dev_err(&batt_drv->psy->dev, "Failed to create bpst_detect_disable\n");
+ return 0;
+
+}
+
+static int batt_bpst_init_debugfs(struct batt_drv *batt_drv)
+{
+ struct dentry *de = NULL;
+
de = debugfs_create_dir("bpst", 0);
if (IS_ERR_OR_NULL(de))
return 0;
@@ -8559,10 +8573,10 @@
}
/* debugfs */
- (void)batt_init_fs(batt_drv);
+ (void)batt_init_debugfs(batt_drv);
/* single battery disconnect */
- (void)batt_bpst_init_fs(batt_drv);
+ (void)batt_bpst_init_debugfs(batt_drv);
/* these don't require nvm storage */
ret = gbms_storage_register(&batt_prop_dsc, "battery", batt_drv);
@@ -8776,6 +8790,10 @@
batt_drv->aacr_cycle_max = AACR_MAX_CYCLE_DEFAULT;
batt_drv->aacr_state = BATT_AACR_DISABLED;
+ /* create the sysfs node */
+ batt_init_fs(batt_drv);
+ batt_bpst_init_fs(batt_drv);
+
/* give time to fg driver to start */
schedule_delayed_work(&batt_drv->init_work,
msecs_to_jiffies(BATT_DELAY_INIT_MS));