[PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper

Raag Jadav posted 3 patches 1 year, 11 months ago
There is a newer version of this series
[PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper
Posted by Raag Jadav 1 year, 11 months ago
Use to_pci_dev() helper to get pci device reference.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/pwm/pwm-dwc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c
index 8f8035b047c1..f5fcea4e69e2 100644
--- a/drivers/pwm/pwm-dwc.c
+++ b/drivers/pwm/pwm-dwc.c
@@ -100,7 +100,7 @@ static void dwc_pwm_remove(struct pci_dev *pci)
 
 static int dwc_pwm_suspend(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
 
@@ -120,7 +120,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 pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
 
-- 
2.35.3
Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper
Posted by Andy Shevchenko 1 year, 11 months ago
On Mon, Jan 22, 2024 at 08:32:38AM +0530, Raag Jadav wrote:
> Use to_pci_dev() helper to get pci device reference.

PCI

...

>  static int dwc_pwm_suspend(struct device *dev)
>  {
> -	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
> +	struct pci_dev *pdev = to_pci_dev(dev);
>  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
>  	int i;
>  
> @@ -120,7 +120,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 pci_dev *pdev = to_pci_dev(dev);
>  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
>  	int i;

I don't see how pdev is being used. That said, why dev_get_drvdata() is not
suffice?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper
Posted by Uwe Kleine-König 1 year, 11 months ago
Hello,

On Sun, Jan 28, 2024 at 04:46:48PM +0200, Andy Shevchenko wrote:
> On Mon, Jan 22, 2024 at 08:32:38AM +0530, Raag Jadav wrote:
> > Use to_pci_dev() helper to get pci device reference.
> 
> PCI
> 
> ...
> 
> >  static int dwc_pwm_suspend(struct device *dev)
> >  {
> > -	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
> > +	struct pci_dev *pdev = to_pci_dev(dev);
> >  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
> >  	int i;
> >  
> > @@ -120,7 +120,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 pci_dev *pdev = to_pci_dev(dev);
> >  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
> >  	int i;
> 
> I don't see how pdev is being used. That said, why dev_get_drvdata() is not
> suffice?

I would even consider using dev_get_drvdata() a nice cleanup given that
pci_get_drvdata() works because dwc_pwm_alloc() called dev_set_drvdata()
(and not pci_set_drvdata()).

Not so long ago (i.e. before commit a357d1493f0c ("pwm: dwc: Move memory
allocation to own function")) the dwc driver was pci only and used
pci_set_drvdata(). Then the upside of first converting the struct device
to a struct pci_dev was not to hard code knowledge about the
implementation of pci_[gs]et_drvdata().

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper
Posted by Raag Jadav 1 year, 10 months ago
On Sun, Jan 28, 2024 at 05:55:00PM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> On Sun, Jan 28, 2024 at 04:46:48PM +0200, Andy Shevchenko wrote:
> > On Mon, Jan 22, 2024 at 08:32:38AM +0530, Raag Jadav wrote:
> > > Use to_pci_dev() helper to get pci device reference.
> > 
> > PCI
> > 
> > ...
> > 
> > >  static int dwc_pwm_suspend(struct device *dev)
> > >  {
> > > -	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
> > > +	struct pci_dev *pdev = to_pci_dev(dev);
> > >  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
> > >  	int i;
> > >  
> > > @@ -120,7 +120,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 pci_dev *pdev = to_pci_dev(dev);
> > >  	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
> > >  	int i;
> > 
> > I don't see how pdev is being used. That said, why dev_get_drvdata() is not
> > suffice?
> 
> I would even consider using dev_get_drvdata() a nice cleanup given that
> pci_get_drvdata() works because dwc_pwm_alloc() called dev_set_drvdata()
> (and not pci_set_drvdata()).

Makes sense. Will update in v2.

Raag