[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0jaFsGc23pNVumxnA955PtGpJjry07CU+2eMJEx=CDw4A@mail.gmail.com>
Date: Tue, 24 Jan 2023 15:07:14 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Bjorn Helgaas <helgaas@...nel.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Len Brown <len.brown@...el.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
Bjorn Helgaas <bhelgaas@...gle.com>
Subject: Re: [PATCH] PM: runtime: Simplify __rpm_get_callback()
On Tue, Jan 24, 2023 at 12:20 PM Geert Uytterhoeven
<geert@...ux-m68k.org> wrote:
>
> Hi Bjorn,
>
> On Thu, Dec 15, 2022 at 7:23 PM Bjorn Helgaas <helgaas@...nel.org> wrote:
> > From: Bjorn Helgaas <bhelgaas@...gle.com>
> >
> > Simplify __rpm_get_callback() slightly by returning as soon as the return
> > value is known. No functional change intended.
> >
> > Signed-off-by: Bjorn Helgaas <bhelgaas@...gle.com>
>
> Thanks for your patch, which is now commit 650bdddb6b311705 ("PM:
> runtime: Simplify __rpm_get_callback()") in pm/linux-next.
>
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -20,8 +20,7 @@ typedef int (*pm_callback_t)(struct device *);
> >
> > static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset)
> > {
> > - pm_callback_t cb;
> > - const struct dev_pm_ops *ops;
> > + const struct dev_pm_ops *ops = NULL;
> >
> > if (dev->pm_domain)
> > ops = &dev->pm_domain->ops;
> > @@ -31,18 +30,14 @@ static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset)
> > ops = dev->class->pm;
> > else if (dev->bus && dev->bus->pm)
> > ops = dev->bus->pm;
> > - else
> > - ops = NULL;
> >
> > if (ops)
> > - cb = *(pm_callback_t *)((void *)ops + cb_offset);
> > - else
> > - cb = NULL;
> > + return *(pm_callback_t *)((void *)ops + cb_offset);
>
> This is a change in behavior in case the callback turns out to be NULL:
> - before, it would fall back to the driver-specific callback below,
> - after, it always returns NULL.
Good point and sorry for missing this!
> >
> > - if (!cb && dev->driver && dev->driver->pm)
> > - cb = *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);
> > + if (dev->driver && dev->driver->pm)
> > + return *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);
> >
> > - return cb;
> > + return NULL;
> > }
>
Something like the patch below (modulo gmail-induced whitespace
breakage) should restore the previous behavior if I'm not mistaken:
---
drivers/base/power/runtime.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
Index: linux-pm/drivers/base/power/runtime.c
===================================================================
--- linux-pm.orig/drivers/base/power/runtime.c
+++ linux-pm/drivers/base/power/runtime.c
@@ -31,8 +31,13 @@ static pm_callback_t __rpm_get_callback(
else if (dev->bus && dev->bus->pm)
ops = dev->bus->pm;
- if (ops)
- return *(pm_callback_t *)((void *)ops + cb_offset);
+ if (ops) {
+ pm_callback_t cb;
+
+ cb = *(pm_callback_t *)((void *)ops + cb_offset);
+ if (cb)
+ return cb;
+ }
if (dev->driver && dev->driver->pm)
return *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);
Powered by blists - more mailing lists