Re: [PATCH v3 6/8] pwm: rzg2l-gpt: Add suspend/resume support

From: Geert Uytterhoeven
Date: Mon Dec 01 2025 - 11:04:58 EST


Hi Biju,

On Mon, 1 Dec 2025 at 16:50, Biju Das <biju.das.jz@xxxxxxxxxxxxxx> wrote:
> > From: Uwe Kleine-König <ukleinek@xxxxxxxxxx>
> > 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(...)

What do you do when one of the disabling fails? See also
https://lore.kernel.org/CAMuHMdWDGpqdhCsA0MJqoL1JAiyVR-TA2YqDe+-S9Xf6c5O-gA@xxxxxxxxxxxxxx

> return 0;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds