All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan@pereq.eu>
To: Yaohan Li <shunsheng1218@gmail.com>
Cc: Dan Carpenter <error27@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	oe-kbuild@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	lkp@intel.com
Subject: Re: [broonie-regulator:for-7.5 6/6] drivers/regulator/qcom-labibb-regulator.c:444 qcom_labibb_setup_ocp_irq() warn: 'vreg->ocp_irq' from request_threaded_irq() not released on lines: 444.
Date: Fri, 27 Nov 2026 09:14:56 +0300	[thread overview]
Message-ID: <awkf4CNhSPz-lcEk@stanley.mountain> (raw)
In-Reply-To: <179567739729.2548149.711673218230357357@gmail.com>

When I send these emails, the only context I have is what's in the
email itself.  But I have now downloaded the git tree.  The init
process is a mess if "->done_this = true" flags.  That's a nightmare.

The better way is spelled out in my blog:
https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

In this way every function either succeeds or cleans up.  We only
have to keep track of the last thing we have allocated so we don't
need ->done_this flags to keep track of it all.  There is only just
the last thing to keep track of.

Looking at qcom_labibb_ocp_hw_enable() now, can those regmap_update_bits()
calls even fail?  It's not clear if we're undoing the "Clear irq latch
status" or the "Enable OCP HW interrupt"...  If we did the clean up inside
the qcom_labibb_ocp_hw_enable() instead of the caller, that would make
it more clear.

There are two callers so this weird error handling is probably done
deliberately,  that makes it even less clear what is failing and what
we are trying to do.  I would prefer to have a normal function the cleaned
up after itself and a weird-o qcom_labibb_ocp_hw_enable_no_cleanup()
function that had comments explaining why we left it in an inconsistent
state.

I asked Claude to review it without any context.  Here is the prompt:
"Review qcom_labibb_set_ocp() from drivers/regulator/qcom-labibb-regulator.c
to ensure that error handing and cleanup is correct.  The error handling
ideally should undo all the things that were done so we can fix whatever
caused the breakage and retry.  Ensure that we don't leave the driver in
an usable state."

I haven't looked at Claude's response carefully but it complained about
the same code said that there were simpler ways to write this:

  @@ static int qcom_labibb_setup_ocp_irq(struct labibb_regulator *vreg)
          ret = qcom_labibb_ocp_hw_enable(vreg->rdev);
  -       if (ret)
  -               qcom_labibb_ocp_hw_disable(vreg->rdev);
  +       if (ret) {
  +               if (!vreg->ocp_hw_enabled)
  +                       qcom_labibb_ocp_hw_disable(vreg->rdev);
  +               return ret;
  +       }
  +       vreg->ocp_hw_enabled = true;
 
  -       return ret;
  +       return 0;
   }

  A simpler alternative: return early from qcom_labibb_setup_ocp_irq()
  when ocp_irq_done is already true and the source is known to be on.
  Re-applying the constraints then never touches a working setup.

regards,
dan carpenter

  reply	other threads:[~2026-11-27  6:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 17:55 [broonie-regulator:for-7.5 6/6] drivers/regulator/qcom-labibb-regulator.c:444 qcom_labibb_setup_ocp_irq() warn: 'vreg->ocp_irq' from request_threaded_irq() not released on lines: 444 kernel test robot
2026-11-26  5:56 ` Dan Carpenter
2026-11-26  7:16 ` Yaohan Li
2026-11-27  6:14   ` Dan Carpenter [this message]
2026-11-27  6:30     ` Dan Carpenter
2026-11-27  7:56     ` Yaohan Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awkf4CNhSPz-lcEk@stanley.mountain \
    --to=dan@pereq.eu \
    --cc=broonie@kernel.org \
    --cc=error27@gmail.com \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    --cc=shunsheng1218@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.