[PATCH v2 4/6] devfreq: Add module owner to devfreq governor

Jie Zhan zhanjie9 at hisilicon.com
Fri May 15 03:32:26 PDT 2026



On 5/14/2026 2:14 PM, Yaxiong Tian wrote:
> 
> 在 2026/5/13 17:38, Jie Zhan 写道:
>> Add an 'owner' member to struct devfreq_governor, such that we can find
>> the module that holds the governor code when it's compiled as a kernel
>> module.  This allows the devfreq core to properly manage the lifecycle
>> of governors.
>>
>> Update devfreq_add_governor() and devm_devfreq_add_governor() to
>> automatically set 'owner' to THIS_MODULE via helper macros.
>>
>> This is a prerequisite for implementing governor reference counting to
>> prevent a governor module from being unloaded (except for force unload)
>> while a governor is in use.
>>
>> Signed-off-by: Jie Zhan <zhanjie9 at hisilicon.com>
>> ---
>>   drivers/devfreq/devfreq.c        | 26 +++++++++-----------------
>>   include/linux/devfreq-governor.h | 26 +++++++++++++++++++++++---
>>   2 files changed, 32 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>> index 9e3e6a7348f8..e1363ab69173 100644
>> --- a/drivers/devfreq/devfreq.c
>> +++ b/drivers/devfreq/devfreq.c
>> @@ -1301,11 +1301,8 @@ void devfreq_resume(void)
>>       mutex_unlock(&devfreq_list_lock);
>>   }
>>   -/**
>> - * devfreq_add_governor() - Add devfreq governor
>> - * @governor:    the devfreq governor to be added
>> - */
>> -int devfreq_add_governor(struct devfreq_governor *governor)
>> +int __devfreq_add_governor(struct devfreq_governor *governor,
>> +               struct module *mod)
>>   {
>>       struct devfreq_governor *g;
>>   @@ -1322,37 +1319,32 @@ int devfreq_add_governor(struct devfreq_governor *governor)
>>           return -EINVAL;
>>       }
>>   +    governor->owner = mod;
>>       list_add(&governor->node, &devfreq_governor_list);
>>         return 0;
>>   }
>> -EXPORT_SYMBOL(devfreq_add_governor);
>> +EXPORT_SYMBOL(__devfreq_add_governor);
> 
> It's a bit strange to use the __ symbol here. Generally speaking, functions exported with EXPORT_SYMBOL are public, while __ indicates internal.
> 
> The same applies below.
> 
Actually it's common (typically in some kernel core code) to do this for
keeping the API the same while extending an existing ABI with more
parameters, such that those callers (in our case, governor code) don't have
to change.

If this is not favoured, we can also touch the existing governors and make
them assign 'governor->owner'.

I'm happy with both.

Thanks,
Jie

[ ... ]



More information about the linux-arm-kernel mailing list