pwm: dwc: Use dev_get_drvdata() directly in PM callbacks
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
@@ -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
Hello Jarkko,
Quoted 14 lines · Jarkko Nikula
Instead of figuring out struct
pci_devpointer from device pointer and thenpci_get_drvdata()we can use directlydev_get_drvdata()to get the pointer to structdwc_pwm.Signed-off-by Jarkko Nikula <[email protected]>--- drivers/pwm/pwm-dwc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/pwm/pwm-dwc.c +0
-0
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/ |
Quoted 30 lines · Uwe Kleine-König
Hello Jarkko,
Quoted 14 lines · Jarkko Nikula
Instead of figuring out struct
pci_devpointer from device pointer and thenpci_get_drvdata()we can use directlydev_get_drvdata()to get the pointer to structdwc_pwm.Signed-off-by Jarkko Nikula <[email protected]>--- drivers/pwm/pwm-dwc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/pwm/pwm-dwc.c +0
-0drivers/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_drvdataisdev_get_drvdataon 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
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_drvdataisdev_get_drvdataon 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()anddev_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 anddev_get_drvdata()in all other functions. Perhaps not worth of effort (does here 4 insertions(+), 6 deletions(-)) and not many PCI drivers seem to usedev_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/ |