summaryrefslogtreecommitdiff
path: root/drivers/opp/cpu.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2025-10-22 12:57:41 +0530
committerViresh Kumar <viresh.kumar@linaro.org>2025-10-23 11:58:05 +0530
commit173e02d674946ff3ef8da7f44a9d5b820b9af21c (patch)
tree9eeacfe682240c7e80f2a2ce8faf8b546a83b4ef /drivers/opp/cpu.c
parente6fdbe8feace22ba54ebcf20d6e200fc97c8e065 (diff)
OPP: Initialize scope-based pointers inline
Uninitialized pointers with `__free` attribute can cause undefined behaviour as the memory allocated to the pointer is freed automatically when the pointer goes out of scope. The OPP core doesn't have any bugs related to this as of now, but it is better to initialize pointers marked with `__free` attribute at declaration to simplify the code and ensure proper scope-based cleanup. Reported-by: Joe Perches <joe@perches.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Diffstat (limited to 'drivers/opp/cpu.c')
-rw-r--r--drivers/opp/cpu.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c
index 97989d4fe336..a6da7ee3ec76 100644
--- a/drivers/opp/cpu.c
+++ b/drivers/opp/cpu.c
@@ -56,10 +56,10 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev,
return -ENOMEM;
for (i = 0, rate = 0; i < max_opps; i++, rate++) {
- struct dev_pm_opp *opp __free(put_opp);
-
/* find next rate */
- opp = dev_pm_opp_find_freq_ceil(dev, &rate);
+ struct dev_pm_opp *opp __free(put_opp) =
+ dev_pm_opp_find_freq_ceil(dev, &rate);
+
if (IS_ERR(opp)) {
ret = PTR_ERR(opp);
goto out;
@@ -154,12 +154,13 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table);
int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev,
const struct cpumask *cpumask)
{
- struct opp_table *opp_table __free(put_opp_table);
struct opp_device *opp_dev;
struct device *dev;
int cpu;
- opp_table = _find_opp_table(cpu_dev);
+ struct opp_table *opp_table __free(put_opp_table) =
+ _find_opp_table(cpu_dev);
+
if (IS_ERR(opp_table))
return PTR_ERR(opp_table);
@@ -201,10 +202,11 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);
*/
int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
{
- struct opp_table *opp_table __free(put_opp_table);
struct opp_device *opp_dev;
- opp_table = _find_opp_table(cpu_dev);
+ struct opp_table *opp_table __free(put_opp_table) =
+ _find_opp_table(cpu_dev);
+
if (IS_ERR(opp_table))
return PTR_ERR(opp_table);