Skip to contentSkip to conversation

counter: intel-qep: Mark PM callbacks with __maybe_unused

PATCH In review Jarkko Nikula 5 participants 11 messages Jun 11, 2021 – Jun 14, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 counter: intel-qep: Mark PM callbacks with __maybe_unused

Remove CONFIG_PM ifdef and mark PM callbacks with __maybe_unused.

---
 drivers/counter/intel-qep.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/counter/intel-qep.c +2 -4
index ab10ba33f46a..a8d3dccecc0f 100644
@@ -473,8 +473,7 @@ static void intel_qep_remove(struct pci_dev *pci)
 	intel_qep_writel(qep, INTEL_QEPCON, 0);
 }
 
-#ifdef CONFIG_PM
-static int intel_qep_suspend(struct device *dev)
+static int __maybe_unused intel_qep_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -486,7 +485,7 @@ static int intel_qep_suspend(struct device *dev)
 	return 0;
 }
 
-static int intel_qep_resume(struct device *dev)
+static int __maybe_unused intel_qep_resume(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -512,7 +511,6 @@ static int intel_qep_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static UNIVERSAL_DEV_PM_OPS(intel_qep_pm_ops,
 			    intel_qep_suspend, intel_qep_resume, NULL);
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 counter: intel-qep: Use to_pci_dev() helper

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

---
 drivers/counter/intel-qep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/counter/intel-qep.c +2 -2
index a8d3dccecc0f..8d7ae28fbd67 100644
@@ -475,7 +475,7 @@ static void intel_qep_remove(struct pci_dev *pci)
 
 static int __maybe_unused intel_qep_suspend(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
 
 	qep->qepcon = intel_qep_readl(qep, INTEL_QEPCON);
@@ -487,7 +487,7 @@ static int __maybe_unused intel_qep_suspend(struct device *dev)
 
 static int __maybe_unused intel_qep_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
 
 	/*
Signature · 1 line
2.30.2
maintainer
#9 lore raw
In reply to Jarkko Nikula
Quoted 4 lines · On Fri, 11 Jun 2021 14:55:57 +0300 Jarkko Nikula…

Remove CONFIG_PM ifdef and mark PM callbacks with __maybe_unused.

Both applied to the togreg branch of iio.git and pushed out as testing to let 0-day poke at them.

William, if you want to give feedback on these, still time for me to add tags etc. They just seem trivial enough its not worth wasting your time :)

Jonathan

Quoted 35 lines
---
 drivers/counter/intel-qep.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/counter/intel-qep.c +2 -4
index ab10ba33f46a..a8d3dccecc0f 100644
@@ -473,8 +473,7 @@ static void intel_qep_remove(struct pci_dev *pci)
 	intel_qep_writel(qep, INTEL_QEPCON, 0);
 }
 
-#ifdef CONFIG_PM
-static int intel_qep_suspend(struct device *dev)
+static int __maybe_unused intel_qep_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -486,7 +485,7 @@ static int intel_qep_suspend(struct device *dev)
 	return 0;
 }
 
-static int intel_qep_resume(struct device *dev)
+static int __maybe_unused intel_qep_resume(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -512,7 +511,6 @@ static int intel_qep_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static UNIVERSAL_DEV_PM_OPS(intel_qep_pm_ops,
 			    intel_qep_suspend, intel_qep_resume, NULL);
#10 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 11 Jun 2021 14:55:57 +0300 Jarkko Nikula…

Remove CONFIG_PM ifdef and mark PM callbacks with __maybe_unused.

Quoted 8 lines

Both applied to the togreg branch of iio.git and pushed out as testing to let 0-day poke at them.

William, if you want to give feedback on these, still time for me to add tags etc. They just seem trivial enough its not worth wasting your time :)

Jonathan

Yes, these are pretty trivial and both look good to me. Feel free to add my Ack to both patches if there's still time.

Quoted 36 lines
Quoted 35 lines
---
 drivers/counter/intel-qep.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/counter/intel-qep.c +2 -4
index ab10ba33f46a..a8d3dccecc0f 100644
@@ -473,8 +473,7 @@ static void intel_qep_remove(struct pci_dev *pci)
 	intel_qep_writel(qep, INTEL_QEPCON, 0);
 }
 
-#ifdef CONFIG_PM
-static int intel_qep_suspend(struct device *dev)
+static int __maybe_unused intel_qep_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -486,7 +485,7 @@ static int intel_qep_suspend(struct device *dev)
 	return 0;
 }
 
-static int intel_qep_resume(struct device *dev)
+static int __maybe_unused intel_qep_resume(struct device *dev)
 {
 	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 	struct intel_qep *qep = pci_get_drvdata(pdev);
@@ -512,7 +511,6 @@ static int intel_qep_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static UNIVERSAL_DEV_PM_OPS(intel_qep_pm_ops,
 			    intel_qep_suspend, intel_qep_resume, NULL);
#2 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

In reply to Jarkko Nikula
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

...

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct intel_qep *qep = pci_get_drvdata(pdev);

Why not change both lines to dev_get_drvdata()?

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct intel_qep *qep = pci_get_drvdata(pdev);

Ditto

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

Quoted 11 lines · On Sun, 13 Jun 2021 13:36:16 +0300 Andy Shevchenko <[email protected]>…
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

...

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct intel_qep *qep = pci_get_drvdata(pdev);  
Quoted 8 lines

Why not change both lines to dev_get_drvdata()?

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct intel_qep *qep = pci_get_drvdata(pdev);  

Ditto

Question when doing this is whether it is better to pair pci_get_drvdata with pci_set_drvdata rather than assuming it will always map to dev_get_drvdata().

I personally don't feel too strongly about this either way, but I know others are unhappy with mixing them.

Of course, could use dev_set_drvdata() in the first place then it would be less of an issue.

Jonathan

#4 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

Quoted 8 lines

...

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
         struct intel_qep *qep = pci_get_drvdata(pdev);

Why not change both lines to dev_get_drvdata()?

I thought it before and Uwe had a good point why it isn't necessarily a good idea:

https://www.spinics.net/lists/linux-pwm/msg15325.html

Jarkko

#5 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

+Uwe Kleine-König

Quoted 12 lines · Jarkko Nikula
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

...

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
         struct intel_qep *qep = pci_get_drvdata(pdev);
Quoted 6 lines
Quoted 2 lines

Why not change both lines to dev_get_drvdata()?

I thought it before and Uwe had a good point why it isn't necessarily a good idea:

https://www.spinics.net/lists/linux-pwm/msg15325.html

I understand this point, but the problem is that we often use different callbacks for different layers. For example, the PM callbacks are operating with generic 'struct device' and using the PCI device there is non-flexible layering violation, so in my opinion it's the opposite to what Uwe says. I.o.w. we need to use corresponding API to what we have in the callbacks. If the callback comes from generic level ==> generic APIs more appropriate.

Anyway, it's such a minor detail, that I'm not going to insist on either way independently on the arguments.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

Quoted 23 lines · Andy Shevchenko

+Uwe Kleine-König

Quoted 12 lines · Jarkko Nikula
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

...

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
         struct intel_qep *qep = pci_get_drvdata(pdev);
Quoted 6 lines
Quoted 2 lines

Why not change both lines to dev_get_drvdata()?

I thought it before and Uwe had a good point why it isn't necessarily a good idea:

https://www.spinics.net/lists/linux-pwm/msg15325.html

Quoted 7 lines

I understand this point, but the problem is that we often use different callbacks for different layers. For example, the PM callbacks are operating with generic 'struct device' and using the PCI device there is non-flexible layering violation, so in my opinion it's the opposite to what Uwe says. I.o.w. we need to use corresponding API to what we have in the callbacks. If the callback comes from generic level ==> generic APIs more appropriate.

Without having looked at the driver in question: I (think I) understand both sides here and both variants have their own downside.

- Using dev_get_drvdata() makes use of the fact that pci_set_drvdata() is a wrapper around dev_set_drvdata for the pcidev's struct device.

- Using pci_get_drvdata() adds overhead (for humans only though, the compiler doesn't care and creates the same code) and having the pci device in the callback isn't necessary.

My personal opinion is: The first is the graver layer violation because it relies on an implementation detail in the PCI framework. The latter is relying on a fact that is local to the driver only: All devices this driver is bound to are pci devices. The main benefit of explicitly using pci_get_drvdata ∘ to_pci_dev I see is that someone having only shallow knowledge of the PCI stuff can easier match a pci_get_drvdata() to the pci_set_drvdata() called in .probe() than a dev_get_drvdata() and so while it uses a function call/code line more, it is more explicit and more obviously correct.

And regarding your argument about the matching API: I think the above code uses the matching API, that is make a pci_dev from a device using to_pci_dev().

So this is about weighting up- and downsides. How you judge them is subjective. (Though my judgement is naturally the better one :-)

Just my 0.02€
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer
#7 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

Quoted 52 lines · On Mon, 14 Jun 2021 11:37:22 +0200 Uwe Kleine-König…
Quoted 23 lines · Andy Shevchenko

+Uwe Kleine-König

Quoted 12 lines · Jarkko Nikula
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Jarkko Nikula

Use to_pci_dev() helper instead of container_of(d, struct pci_dev, dev);

...

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
         struct intel_qep *qep = pci_get_drvdata(pdev);  
Quoted 6 lines
Quoted 2 lines

Why not change both lines to dev_get_drvdata()?

I thought it before and Uwe had a good point why it isn't necessarily a good idea:

https://www.spinics.net/lists/linux-pwm/msg15325.html

Quoted 7 lines

I understand this point, but the problem is that we often use different callbacks for different layers. For example, the PM callbacks are operating with generic 'struct device' and using the PCI device there is non-flexible layering violation, so in my opinion it's the opposite to what Uwe says. I.o.w. we need to use corresponding API to what we have in the callbacks. If the callback comes from generic level ==> generic APIs more appropriate.

Without having looked at the driver in question: I (think I) understand both sides here and both variants have their own downside.

- Using dev_get_drvdata() makes use of the fact that pci_set_drvdata() is a wrapper around dev_set_drvdata for the pcidev's struct device.

- Using pci_get_drvdata() adds overhead (for humans only though, the compiler doesn't care and creates the same code) and having the pci device in the callback isn't necessary.

My personal opinion is: The first is the graver layer violation because it relies on an implementation detail in the PCI framework. The latter is relying on a fact that is local to the driver only: All devices this driver is bound to are pci devices. The main benefit of explicitly using pci_get_drvdata ∘ to_pci_dev I see is that someone having only shallow knowledge of the PCI stuff can easier match a pci_get_drvdata() to the pci_set_drvdata() called in .probe() than a dev_get_drvdata() and so while it uses a function call/code line more, it is more explicit and more obviously correct.

Quoted 6 lines

And regarding your argument about the matching API: I think the above code uses the matching API, that is make a pci_dev from a device using to_pci_dev().

So this is about weighting up- and downsides. How you judge them is subjective. (Though my judgement is naturally the better one :-)

Personally I'm happy with either

dev_set_drvdata / dev_get_drvdata
or
pci_set_drvdata / pci_get_drvdata

In this particular case there is a convenient struct device *dev local variable anyway in the probe() (IIRC) so could have done option 1 with no loss of readability and a tiny saving in code.

Not worth changing it though is my 0.02€

Jonathan

Quoted 4 lines

Just my 0.02€
Uwe

#8 lore raw

Re: [PATCH 2/2] counter: intel-qep: Use to_pci_dev() helper

Quoted 9 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 14 Jun 2021 11:37:22 +0200 Uwe Kleine-König…
Quoted 6 lines · Andy Shevchenko

+Uwe Kleine-König

Quoted 3 lines · Jarkko Nikula
Quoted 2 lines · Andy Shevchenko

On Fri, Jun 11, 2021 at 2:57 PM Jarkko Nikula
<[email protected]> wrote:

...

Quoted 48 lines
Quoted 39 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

drivers/counter/intel-qep.c static void intel_qep_remove(struct pci_dev *pci) · line 479

Quoted 3 lines
drivers/counter/intel-qep.c +1 -1
-       struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+       struct pci_dev *pdev = to_pci_dev(dev);
         struct intel_qep *qep = pci_get_drvdata(pdev);

Why not change both lines to dev_get_drvdata()?

I thought it before and Uwe had a good point why it isn't necessarily a good idea:

https://www.spinics.net/lists/linux-pwm/msg15325.html

Quoted 7 lines

I understand this point, but the problem is that we often use different callbacks for different layers. For example, the PM callbacks are operating with generic 'struct device' and using the PCI device there is non-flexible layering violation, so in my opinion it's the opposite to what Uwe says. I.o.w. we need to use corresponding API to what we have in the callbacks. If the callback comes from generic level ==> generic APIs more appropriate.

Without having looked at the driver in question: I (think I) understand both sides here and both variants have their own downside.

- Using dev_get_drvdata() makes use of the fact that pci_set_drvdata() is a wrapper around dev_set_drvdata for the pcidev's struct device.

- Using pci_get_drvdata() adds overhead (for humans only though, the compiler doesn't care and creates the same code) and having the pci device in the callback isn't necessary.

My personal opinion is: The first is the graver layer violation because it relies on an implementation detail in the PCI framework. The latter is relying on a fact that is local to the driver only: All devices this driver is bound to are pci devices. The main benefit of explicitly using pci_get_drvdata ∘ to_pci_dev I see is that someone having only shallow knowledge of the PCI stuff can easier match a pci_get_drvdata() to the pci_set_drvdata() called in .probe() than a dev_get_drvdata() and so while it uses a function call/code line more, it is more explicit and more obviously correct.

Quoted 6 lines

And regarding your argument about the matching API: I think the above code uses the matching API, that is make a pci_dev from a device using to_pci_dev().

So this is about weighting up- and downsides. How you judge them is subjective. (Though my judgement is naturally the better one :-)

Personally I'm happy with either

Quoted 7 lines

dev_set_drvdata / dev_get_drvdata
or
pci_set_drvdata / pci_get_drvdata

In this particular case there is a convenient struct device *dev local variable anyway in the probe() (IIRC) so could have done option 1 with no loss of readability and a tiny saving in code.

As I said this is unflexible.
For example, we have quite a few drivers that split in the way of core part (as library) + glue driver(s)
How to implement callbacks that will use the same pairs of the callbacks?

I don't think it's possible in a good and neat way.

On top of that I think using the knowledge of the device nature in the generic callbacks _is_ a layering violation.

TL;DR: the simple rule of thumb may be:
if the callback uses struct device, that dev_get_drvdata(), otherwise based on what you have got as a parameter.
Does it make sense?

Quoted 1 line

Not worth changing it though is my 0.02€

Signature · 2 lines
With Best Regards,
Andy Shevchenko