diff mbox series

[v1,1/1] ACPI: VIOT: Do not dereference fwnode in struct device

Message ID 20220802193503.3092-1-andriy.shevchenko@linux.intel.com
State Accepted
Commit b0f2fe5a38389790a97334c5df1c5dec52c5d627
Headers show
Series [v1,1/1] ACPI: VIOT: Do not dereference fwnode in struct device | expand

Commit Message

Andy Shevchenko Aug. 2, 2022, 7:35 p.m. UTC
In order to make the underneath API easier to change in the future,
prevent users from dereferencing fwnode from struct device.
Instead, use the specific dev_fwnode() and device_match_fwnode()
APIs for that.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/viot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Eric Auger Aug. 3, 2022, 10:03 a.m. UTC | #1
Hi Andy,

On 8/2/22 21:35, Andy Shevchenko wrote:
> In order to make the underneath API easier to change in the future,
> prevent users from dereferencing fwnode from struct device.
> Instead, use the specific dev_fwnode() and device_match_fwnode()
> APIs for that.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric
> ---
>  drivers/acpi/viot.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/viot.c b/drivers/acpi/viot.c
> index 647f11cf165d..6132092dab2a 100644
> --- a/drivers/acpi/viot.c
> +++ b/drivers/acpi/viot.c
> @@ -88,7 +88,7 @@ static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
>  		return -ENODEV;
>  	}
>  
> -	fwnode = pdev->dev.fwnode;
> +	fwnode = dev_fwnode(&pdev->dev);
>  	if (!fwnode) {
>  		/*
>  		 * PCI devices aren't necessarily described by ACPI. Create a
> @@ -101,7 +101,7 @@ static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
>  		}
>  		set_primary_fwnode(&pdev->dev, fwnode);
>  	}
> -	viommu->fwnode = pdev->dev.fwnode;
> +	viommu->fwnode = dev_fwnode(&pdev->dev);
>  	pci_dev_put(pdev);
>  	return 0;
>  }
> @@ -314,7 +314,7 @@ static int viot_dev_iommu_init(struct device *dev, struct viot_iommu *viommu,
>  		return -ENODEV;
>  
>  	/* We're not translating ourself */
> -	if (viommu->fwnode == dev->fwnode)
> +	if (device_match_fwnode(dev, viommu->fwnode))
>  		return -EINVAL;
>  
>  	ops = iommu_ops_from_fwnode(viommu->fwnode);
Rafael J. Wysocki Aug. 8, 2022, 5:31 p.m. UTC | #2
On Wed, Aug 3, 2022 at 12:03 PM Eric Auger <eric.auger@redhat.com> wrote:
>
> Hi Andy,
>
> On 8/2/22 21:35, Andy Shevchenko wrote:
> > In order to make the underneath API easier to change in the future,
> > prevent users from dereferencing fwnode from struct device.
> > Instead, use the specific dev_fwnode() and device_match_fwnode()
> > APIs for that.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>

Applied, thanks!

> > ---
> >  drivers/acpi/viot.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/acpi/viot.c b/drivers/acpi/viot.c
> > index 647f11cf165d..6132092dab2a 100644
> > --- a/drivers/acpi/viot.c
> > +++ b/drivers/acpi/viot.c
> > @@ -88,7 +88,7 @@ static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
> >               return -ENODEV;
> >       }
> >
> > -     fwnode = pdev->dev.fwnode;
> > +     fwnode = dev_fwnode(&pdev->dev);
> >       if (!fwnode) {
> >               /*
> >                * PCI devices aren't necessarily described by ACPI. Create a
> > @@ -101,7 +101,7 @@ static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
> >               }
> >               set_primary_fwnode(&pdev->dev, fwnode);
> >       }
> > -     viommu->fwnode = pdev->dev.fwnode;
> > +     viommu->fwnode = dev_fwnode(&pdev->dev);
> >       pci_dev_put(pdev);
> >       return 0;
> >  }
> > @@ -314,7 +314,7 @@ static int viot_dev_iommu_init(struct device *dev, struct viot_iommu *viommu,
> >               return -ENODEV;
> >
> >       /* We're not translating ourself */
> > -     if (viommu->fwnode == dev->fwnode)
> > +     if (device_match_fwnode(dev, viommu->fwnode))
> >               return -EINVAL;
> >
> >       ops = iommu_ops_from_fwnode(viommu->fwnode);
>
diff mbox series

Patch

diff --git a/drivers/acpi/viot.c b/drivers/acpi/viot.c
index 647f11cf165d..6132092dab2a 100644
--- a/drivers/acpi/viot.c
+++ b/drivers/acpi/viot.c
@@ -88,7 +88,7 @@  static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
 		return -ENODEV;
 	}
 
-	fwnode = pdev->dev.fwnode;
+	fwnode = dev_fwnode(&pdev->dev);
 	if (!fwnode) {
 		/*
 		 * PCI devices aren't necessarily described by ACPI. Create a
@@ -101,7 +101,7 @@  static int __init viot_get_pci_iommu_fwnode(struct viot_iommu *viommu,
 		}
 		set_primary_fwnode(&pdev->dev, fwnode);
 	}
-	viommu->fwnode = pdev->dev.fwnode;
+	viommu->fwnode = dev_fwnode(&pdev->dev);
 	pci_dev_put(pdev);
 	return 0;
 }
@@ -314,7 +314,7 @@  static int viot_dev_iommu_init(struct device *dev, struct viot_iommu *viommu,
 		return -ENODEV;
 
 	/* We're not translating ourself */
-	if (viommu->fwnode == dev->fwnode)
+	if (device_match_fwnode(dev, viommu->fwnode))
 		return -EINVAL;
 
 	ops = iommu_ops_from_fwnode(viommu->fwnode);