Skip to contentSkip to conversation

pwm: dwc: Use dev_get_drvdata() directly in PM callbacks

PATCH In review Jarkko Nikula 2 participants 4 messages Mar 17, 2021 – Apr 8, 2021 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: dwc: Use dev_get_drvdata() directly in PM callbacks

Instead of figuring out struct pci_dev pointer from device pointer and then pci_get_drvdata() we can use directly dev_get_drvdata() to get the pointer to struct dwc_pwm.

---
 drivers/pwm/pwm-dwc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pwm/pwm-dwc.c +2 -4
index f6c98e0d57c2..4d59a035c0c9 100644
@@ -258,8 +258,7 @@ static void dwc_pwm_remove(struct pci_dev *pci)
 #ifdef CONFIG_PM_SLEEP
 static int dwc_pwm_suspend(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
-	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
+	struct dwc_pwm *dwc = dev_get_drvdata(dev);
 	int i;
 
 	for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
@@ -278,8 +277,7 @@ static int dwc_pwm_suspend(struct device *dev)
 
 static int dwc_pwm_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
-	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
+	struct dwc_pwm *dwc = dev_get_drvdata(dev);
 	int i;
 
 	for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
Signature · 1 line
2.30.2
#1 lore raw

Hello Jarkko,

Quoted 14 lines · Jarkko Nikula

Instead of figuring out struct pci_dev pointer from device pointer and then pci_get_drvdata() we can use directly dev_get_drvdata() to get the pointer to struct dwc_pwm.

---
 drivers/pwm/pwm-dwc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pwm/pwm-dwc.c +0 -0
index f6c98e0d57c2..4d59a035c0c9 100644

drivers/pwm/pwm-dwc.c static void dwc_pwm_remove(struct pci_dev *pci) · line 262

Quoted 7 lines
drivers/pwm/pwm-dwc.c +1 -2
@@ -258,8 +258,7 @@ static void dwc_pwm_remove(struct pci_dev *pci)
 #ifdef CONFIG_PM_SLEEP
 static int dwc_pwm_suspend(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
-	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
+	struct dwc_pwm *dwc = dev_get_drvdata(dev);
 	int i;

I'm a bit ambivalent here. I'd consider it an implementation detail of the PCI framework that pci_get_drvdata is dev_get_drvdata on the related struct device. So even though the PCI guys probably will never change that, it feels a bit like a layer violation to rely on this behaviour.

As additionally the status quo isn't less effective (unless I miss something) than the alternative proposed in your patch, I tend to not like your change.

Best regards
Uwe

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

Hello Jarkko,

Quoted 14 lines · Jarkko Nikula

Instead of figuring out struct pci_dev pointer from device pointer and then pci_get_drvdata() we can use directly dev_get_drvdata() to get the pointer to struct dwc_pwm.

---
  drivers/pwm/pwm-dwc.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/pwm/pwm-dwc.c +0 -0
index f6c98e0d57c2..4d59a035c0c9 100644

drivers/pwm/pwm-dwc.c static void dwc_pwm_remove(struct pci_dev *pci) · line 262

Quoted 7 lines
drivers/pwm/pwm-dwc.c +1 -2
@@ -258,8 +258,7 @@ static void dwc_pwm_remove(struct pci_dev *pci)
  #ifdef CONFIG_PM_SLEEP
  static int dwc_pwm_suspend(struct device *dev)
  {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
-	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
+	struct dwc_pwm *dwc = dev_get_drvdata(dev);
  	int i;

I'm a bit ambivalent here. I'd consider it an implementation detail of the PCI framework that pci_get_drvdata is dev_get_drvdata on the related struct device. So even though the PCI guys probably will never change that, it feels a bit like a layer violation to rely on this behaviour.

Quoted 4 lines

As additionally the status quo isn't less effective (unless I miss something) than the alternative proposed in your patch, I tend to not like your change.

Yeah, agree, it is a bit confusing to see mix of pci_set_drvdata() and dev_get_drvdata(). Got the idea for this patch from another driver and similar commits.

Better would be to switch entirely to dev_set_drvdata() in probe and dev_get_drvdata() in all other functions. Perhaps not worth of effort (does here 4 insertions(+), 6 deletions(-)) and not many PCI drivers seem to use dev_set_drvdata() in their probe (additional confusion?).

Jarkko

#3 lore raw

Hello,

Quoted 16 lines · Jarkko Nikula
Quoted 11 lines · Uwe Kleine-König

drivers/pwm/pwm-dwc.c static void dwc_pwm_remove(struct pci_dev *pci) · line 262

Quoted 4 lines · Jarkko Nikula
drivers/pwm/pwm-dwc.c +1 -2
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
-	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
+	struct dwc_pwm *dwc = dev_get_drvdata(dev);
  	int i;

I'm a bit ambivalent here. I'd consider it an implementation detail of the PCI framework that pci_get_drvdata is dev_get_drvdata on the related struct device. So even though the PCI guys probably will never change that, it feels a bit like a layer violation to rely on this behaviour.

Quoted 4 lines

As additionally the status quo isn't less effective (unless I miss something) than the alternative proposed in your patch, I tend to not like your change.

Quoted 8 lines

Yeah, agree, it is a bit confusing to see mix of pci_set_drvdata() and dev_get_drvdata(). Got the idea for this patch from another driver and similar commits.

Better would be to switch entirely to dev_set_drvdata() in probe and dev_get_drvdata() in all other functions. Perhaps not worth of effort (does here 4 insertions(+), 6 deletions(-)) and not many PCI drivers seem to use dev_set_drvdata() in their probe (additional confusion?).

ok, I'll discard this patch in our patchwork.

Best regards
Uwe

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