RE: [PATCH v3 6/8] pwm: rzg2l-gpt: Add suspend/resume support
From: Biju Das
Date: Mon Dec 01 2025 - 10:50:42 EST
Hi Uwe,
> -----Original Message-----
> From: Uwe Kleine-König <ukleinek@xxxxxxxxxx>
> Sent: 01 December 2025 15:29
> Subject: Re: [PATCH v3 6/8] pwm: rzg2l-gpt: Add suspend/resume support
>
> Hello Biju,
>
> On Mon, Dec 01, 2025 at 03:04:08PM +0000, Biju Das wrote:
> > You mean to avoid unbalance between suspend()/resume(), we should not
> > do error handling in resume()??
>
> Consider the following resume function:
>
> static int myresume(...)
> {
> ret = enable_some_resource(...);
> if (ret)
> return ret;
>
> ret = enable_some_other_resource(...)
> if (ret) {
> disable_some_resource();
> return ret;
>
> }
>
> return 0;
> }
>
> If disable_some_resource() can fail it might happen that the first call to myresume() is left with
> some_resource enabled and some_other_resource disabled (i.e. if both enable_some_other_resource() and
> disable_some_resource() fail). Now if the resume is retried some_resource is enabled a second time
> without being tracked and a later suspend (or remove) won't bring the enable count to 0 and thus leak
> a resource.
OK, what about for making balanced usage count for suspend()/resume() to avoid resource
like below
static int myresume(...)
{
ret = enable_some_resource(...);
ret |= enable_some_other_resource(...);
return ret;
}
static int mysuspend(...)
{
disable_some_resource(...);
disable_some_other_resource(...)
return 0;
}