Re: [PATCH v1 1/1] cpufreq: loongson: Check for error code from devm_mutex_init() call

From: Huacai Chen
Date: Wed Oct 30 2024 - 21:31:18 EST


Hi, Andy,

On Thu, Oct 31, 2024 at 12:29 AM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> 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 <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> drivers/cpufreq/loongson3_cpufreq.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/loongson3_cpufreq.c b/drivers/cpufreq/loongson3_cpufreq.c
> index 61ebebf69455..bd34bf0fafa5 100644
> --- a/drivers/cpufreq/loongson3_cpufreq.c
> +++ b/drivers/cpufreq/loongson3_cpufreq.c
> @@ -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

> + return ret;
> + }
>
> ret = do_service_request(0, 0, CMD_GET_VERSION, 0, 0);
> if (ret <= 0)
> --
> 2.43.0.rc1.1336.g36b5255a03ac
>
>