cpufreq: loongson: Check for error code from devm_mutex_init() call
Subsystems (2)
PATCH 1/1 cpufreq: loongson: Check for error code from devm_mutex_init() call
Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.
--- drivers/cpufreq/loongson3_cpufreq.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +5 -2
@@ -346,8 +346,11 @@ static int loongson3_cpufreq_probe(struct platform_device *pdev) {int i, ret; -for (i =0 ; i <MAX_PACKAGES ; i++) -devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +for (i =0 ; i <MAX_PACKAGES ; i++) { + ret =devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +if (ret) +return ret; + } ret =do_service_request (0 ,0 ,CMD_GET_VERSION ,0 ,0 );if (ret <=0 )
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Huacai Chen
maintainerHi, Andy,
Quoted 17 lines · Andy Shevchenko
Even if it's not critical, the avoidance of checking the error code from
devm_mutex_init()call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.Fixes ccf51454145b ("cpufreq: Add Loongson-3 CPUFreq driver support")Signed-off-by Andy Shevchenko <[email protected]>--- drivers/cpufreq/loongson3_cpufreq.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/cpufreq/loongson3_cpufreq.c +0
-0
drivers/cpufreq/loongson3_cpufreq.c static int loongson3_cpufreq_probe(struct platform_device *pdev) · line 351
Quoted 8 lines
drivers/cpufreq/loongson3_cpufreq.c +3
-2@@ -346,8 +346,11 @@ static int loongson3_cpufreq_probe(struct platform_device *pdev) {int i, ret; -for (i =0 ; i <MAX_PACKAGES ; i++) -devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +for (i =0 ; i <MAX_PACKAGES ; i++) { + ret =devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +if (ret)
Good catch, but I think "if (ret < 0)" is better? Sometimes a positive return value is legal, even if not in this case.
And it is better to use loongson3 rather than loongson because there is another loongson2 driver.
Huacai
Quoted 9 lines
drivers/cpufreq/loongson3_cpufreq.c +2
-1+return ret; + } ret =do_service_request (0 ,0 ,CMD_GET_VERSION ,0 ,0 );if (ret <=0 ) --2.43.0.rc1.1336.g36b5255a03ac
Quoted 2 lines · Huacai Chen
On Thu, Oct 31, 2024 at 12:29 AM Andy Shevchenko
<[email protected]> wrote:
...
Quoted 7 lines
drivers/cpufreq/loongson3_cpufreq.c static int loongson3_cpufreq_probe(struct platform_device *pdev) · line 351
Quoted 5 lines
drivers/cpufreq/loongson3_cpufreq.c +3
-2-for (i =0 ; i <MAX_PACKAGES ; i++) -devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +for (i =0 ; i <MAX_PACKAGES ; i++) { + ret =devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]); +if (ret)Good catch, but I think "if (ret < 0)" is better? Sometimes a positive return value is legal, even if not in this case.
I disagree on this.
During a tons of reviews I have done in the past this kind of check is impediment and always rises the Q "why?" It means that the author hasn't fully thought through the code and most likely done something is a cargo cult. On top of that, if the callee is changed at some point to actually return a positive code(s), the caller most likely has to be at least aware of that change. The proposed modification makes this silently compile and hides possible important details from the caller(s).
Quoted 2 lines
And it is better to use loongson3 rather than loongson because there
is another loongson2 driver.
Thanks, I will change that in v2 (I believe you are talking about Subject?).
Quoted 2 lines
Quoted 2 lines
drivers/cpufreq/loongson3_cpufreq.c +2
-0+return ret; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko