2022-03-01 14:17:12

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] ASoC: fsi: Add check for clk_enable

On Tue, Mar 01, 2022 at 03:39:49PM +0800, Jiasheng Jiang wrote:
> As the potential failure of the clk_enable(),
> it should be better to check it and return error
> if fails.

> - clk_enable(clock->xck);
> - clk_enable(clock->ick);
> - clk_enable(clock->div);
> + ret = clk_enable(clock->xck);
> + if (ret)
> + goto err;
> + ret = clk_enable(clock->ick);
> + if (ret)
> + goto err;
> + ret = clk_enable(clock->div);
> + if (ret)
> + goto err;
>
> clock->count++;
> }
>
> return ret;
> +
> +err:
> + clk_disable(clock->xck);
> + clk_disable(clock->ick);
> + clk_disable(clock->div);

You need separate labels for each enable so that we don't end up
disabling clocks we didn't enable, that would also be a bug.


Attachments:
(No filename) (765.00 B)
signature.asc (499.00 B)
Download all attachments

2022-03-02 11:06:16

by Jiasheng Jiang

[permalink] [raw]
Subject: Re: Re: [PATCH] ASoC: fsi: Add check for clk_enable

On Tue, Mar 01, 2022 at 08:44:12PM +0800, Mark Brown wrote:
>> +err:
>> + clk_disable(clock->xck);
>> + clk_disable(clock->ick);
>> + clk_disable(clock->div);
>
> You need separate labels for each enable so that we don't end up
> disabling clocks we didn't enable, that would also be a bug.

Thanks, I have submitted a v2 to fix it.

Jiang