PM: runtime: Simplify __rpm_get_callback()
Subsystems (4)
PATCH 1/1 PM: runtime: Simplify __rpm_get_callback()
From: Bjorn Helgaas <[email protected]>
Simplify __rpm_get_callback() slightly by returning as soon as the return value is known. No functional change intended.
--- drivers/base/power/runtime.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/base/power/runtime.c +5 -10
@@ -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); -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 ; }#define RPM_GET_CALLBACK (dev, callback) \
Signature · 1 line
2.25.1
Quoted 39 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/base/power/runtime.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)drivers/base/power/runtime.c +2
-8@@ -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); -if (!cb && dev->driver && dev->driver->pm)
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset)
Quoted 10 lines
drivers/base/power/runtime.c +3
-3- 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 ; }#define RPM_GET_CALLBACK (dev, callback) \ --
Applied as 6.3 material, thanks!
Hi Bjorn,
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>
Thanks for your patch, which is now commit 650bdddb6b311705 ("PM:
runtime: Simplify __rpm_get_callback()") in pm/linux-next.
Quoted 14 lines
drivers/base/power/runtime.c +1
-2@@ -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;
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 10 lines
drivers/base/power/runtime.c +1
-5else 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.
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 41
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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 ; }
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
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
Rafael J. Wysocki
maintainerQuoted 33 lines · Geert Uytterhoeven
Hi Bjorn,
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>Thanks for your patch, which is now commit
650bdddb6b311705("PM:
runtime: Simplify__rpm_get_callback()") in pm/linux-next.Quoted 19 lines
drivers/base/power/runtime.c +1
-4@@ -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 ;
Quoted 9 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 5 lines
drivers/base/power/runtime.c +1
-3if (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!
Quoted 10 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 40
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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(-)
drivers/base/power/runtime.c +7 -2
@@ -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);
Hi Rafael,
Quoted 75 lines · Rafael J. Wysocki
Quoted 33 lines · Geert Uytterhoeven
Hi Bjorn,
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>Thanks for your patch, which is now commit
650bdddb6b311705("PM:
runtime: Simplify__rpm_get_callback()") in pm/linux-next.Quoted 19 lines
drivers/base/power/runtime.c +1
-4@@ -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 ;Quoted 9 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 5 lines
drivers/base/power/runtime.c +1
-3if (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!
Quoted 10 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 40
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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
===================================================================drivers/base/power/runtime.c +0
-2@@ -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);
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback( · line 43
Quoted 10 lines
drivers/base/power/runtime.c +7
-0+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);
Which is now more complex than the original?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
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
Rafael J. Wysocki
maintainerQuoted 87 lines · Geert Uytterhoeven
Hi Rafael,
Quoted 83 lines · Rafael J. Wysocki
Quoted 33 lines · Geert Uytterhoeven
Hi Bjorn,
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>Thanks for your patch, which is now commit
650bdddb6b311705("PM:
runtime: Simplify__rpm_get_callback()") in pm/linux-next.Quoted 19 lines
drivers/base/power/runtime.c +1
-4@@ -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 ;Quoted 9 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 5 lines
drivers/base/power/runtime.c +1
-3if (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!
Quoted 10 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 40
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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
===================================================================drivers/base/power/runtime.c +7
-2@@ -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; + }
Quoted 4 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback( · line 43
Quoted 2 lines
drivers/base/power/runtime.c +0
-0if (dev->driver && dev->driver->pm)return *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);Which is now more complex than the original?
Arguably so.
OK, I'll drop the commit in question then, sorry Bjorn.
Quoted 82 lines · Rafael J. Wysocki
Quoted 81 lines · Geert Uytterhoeven
Quoted 80 lines · Rafael J. Wysocki
Quoted 30 lines · Geert Uytterhoeven
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>Thanks for your patch, which is now commit
650bdddb6b311705("PM:
runtime: Simplify__rpm_get_callback()") in pm/linux-next.Quoted 19 lines
drivers/base/power/runtime.c +1
-4@@ -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 ;Quoted 9 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 5 lines
drivers/base/power/runtime.c +1
-3if (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!
Quoted 10 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 40
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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
===================================================================drivers/base/power/runtime.c +7
-2@@ -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; + }
Quoted 8 lines
Quoted 4 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback( · line 43
Quoted 2 lines
drivers/base/power/runtime.c +0
-0if (dev->driver && dev->driver->pm)return *(pm_callback_t *)((void *)dev->driver->pm + cb_offset);Which is now more complex than the original?
Arguably so.
OK, I'll drop the commit in question then, sorry Bjorn.
Really sorry about this. Think I'm all out of brown paper bags :( Thanks for catching this, Geert, and sorry for all the time you had to spend debugging it.
Bjorn
Hi Bjorn,
Quoted 88 lines · Bjorn Helgaas
Quoted 87 lines · Rafael J. Wysocki
Quoted 85 lines · Geert Uytterhoeven
Quoted 72 lines · Rafael J. Wysocki
Quoted 30 lines · Geert Uytterhoeven
Quoted 6 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Simplify
__rpm_get_callback()slightly by returning as soon as the return value is known. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>Thanks for your patch, which is now commit
650bdddb6b311705("PM:
runtime: Simplify__rpm_get_callback()") in pm/linux-next.Quoted 19 lines
drivers/base/power/runtime.c +1
-4@@ -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 ;Quoted 9 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 35
Quoted 5 lines
drivers/base/power/runtime.c +1
-3if (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!
Quoted 10 lines
drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) · line 40
Quoted 9 lines
drivers/base/power/runtime.c +3
-3-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
===================================================================drivers/base/power/runtime.c +0
-2@@ -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);drivers/base/power/runtime.c static pm_callback_t __rpm_get_callback( · line 43
Quoted 10 lines
drivers/base/power/runtime.c +7
-0+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);Which is now more complex than the original?
Quoted 6 lines
Quoted 3 lines
Arguably so.
OK, I'll drop the commit in question then, sorry Bjorn.
Really sorry about this. Think I'm all out of brown paper bags :( Thanks for catching this, Geert, and sorry for all the time you had to
Np, no time was wasted on debugging.
I just noticed because I have some local debug code on top, which no longer applied 8^)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
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