devfreq: track governor usage count

Prevent governor from unexpectedly getting unloaded when it is in used.

Bug 5394611

Change-Id: I84b2ee3ce7666d4107096d958971d28700e744b4
Signed-off-by: Johnny Liu <johnliu@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3408797
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
This commit is contained in:
Johnny Liu
2025-07-15 16:25:50 +00:00
committed by Jon Hunter
parent 49ebbfc3ed
commit 408c3a8bb3
2 changed files with 8 additions and 0 deletions

View File

@@ -326,6 +326,9 @@ static int nvhost_pod_event_handler(struct devfreq *df,
switch (event) { switch (event) {
case DEVFREQ_GOV_START: case DEVFREQ_GOV_START:
if (!try_module_get(THIS_MODULE))
return -ENODEV;
mutex_lock(&df->lock); mutex_lock(&df->lock);
ret = nvhost_pod_init(df); ret = nvhost_pod_init(df);
mutex_unlock(&df->lock); mutex_unlock(&df->lock);
@@ -336,6 +339,7 @@ static int nvhost_pod_event_handler(struct devfreq *df,
mutex_lock(&df->lock); mutex_lock(&df->lock);
nvhost_pod_exit(df); nvhost_pod_exit(df);
mutex_unlock(&df->lock); mutex_unlock(&df->lock);
module_put(THIS_MODULE);
break; break;
case DEVFREQ_GOV_UPDATE_INTERVAL: case DEVFREQ_GOV_UPDATE_INTERVAL:
devfreq_update_interval(df, (unsigned int *)data); devfreq_update_interval(df, (unsigned int *)data);

View File

@@ -531,6 +531,9 @@ static int devfreq_tegra_wmark_event_handler(struct devfreq *df,
switch (event) { switch (event) {
case DEVFREQ_GOV_START: case DEVFREQ_GOV_START:
if (!try_module_get(THIS_MODULE))
return -ENODEV;
err = tegra_wmark_init(df); err = tegra_wmark_init(df);
if (err) if (err)
return err; return err;
@@ -542,6 +545,7 @@ static int devfreq_tegra_wmark_event_handler(struct devfreq *df,
wmark_config.lower_wmark_enabled = 0; wmark_config.lower_wmark_enabled = 0;
drvdata->update_wmark_threshold(df, &wmark_config); drvdata->update_wmark_threshold(df, &wmark_config);
tegra_wmark_exit(df); tegra_wmark_exit(df);
module_put(THIS_MODULE);
break; break;
case DEVFREQ_GOV_SUSPEND: case DEVFREQ_GOV_SUSPEND:
wmark_config.upper_wmark_enabled = 0; wmark_config.upper_wmark_enabled = 0;