According to "Function return values and names" in coding-style.rst, the
dmar_ats_supported() function should return a boolean instead of an
integer. Also, rename "ret" to "supported" to be more straightforward.
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
drivers/iommu/intel/iommu.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index d8aa71305509..2778bfe14f36 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2760,10 +2760,11 @@ static struct dmar_satc_unit *dmar_find_matched_satc_unit(struct pci_dev *dev)
return satcu;
}
-static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
+static bool dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
{
- int i, ret = 1;
+ int i;
struct pci_bus *bus;
+ bool supported = true;
struct pci_dev *bridge = NULL;
struct device *tmp;
struct acpi_dmar_atsr *atsr;
@@ -2786,11 +2787,11 @@ static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
bridge = bus->self;
/* If it's an integrated device, allow ATS */
if (!bridge)
- return 1;
+ return true;
/* Connected via non-PCIe: no ATS */
if (!pci_is_pcie(bridge) ||
pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE)
- return 0;
+ return false;
/* If we found the root port, look it up in the ATSR */
if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
break;
@@ -2809,11 +2810,11 @@ static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
if (atsru->include_all)
goto out;
}
- ret = 0;
+ supported = false;
out:
rcu_read_unlock();
- return ret;
+ return supported;
}
int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)
--
2.43.0
On 2025/5/9 22:00, Wei Wang wrote:
> According to "Function return values and names" in coding-style.rst, the
> dmar_ats_supported() function should return a boolean instead of an
> integer. Also, rename "ret" to "supported" to be more straightforward.
>
seems just a recommendation since this is just internal helper. The
function was indeed not well written anyhow. :) not sure if Baolu wants
take it or not. Taking it may make history tracking harder. Patch itself
looks good to me.
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> ---
> drivers/iommu/intel/iommu.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index d8aa71305509..2778bfe14f36 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -2760,10 +2760,11 @@ static struct dmar_satc_unit *dmar_find_matched_satc_unit(struct pci_dev *dev)
> return satcu;
> }
>
> -static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
> +static bool dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
> {
> - int i, ret = 1;
> + int i;
> struct pci_bus *bus;
> + bool supported = true;
> struct pci_dev *bridge = NULL;
> struct device *tmp;
> struct acpi_dmar_atsr *atsr;
This list should have been in reverse Christmas tree order per the length. :)
> @@ -2786,11 +2787,11 @@ static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
> bridge = bus->self;
> /* If it's an integrated device, allow ATS */
> if (!bridge)
> - return 1;
> + return true;
> /* Connected via non-PCIe: no ATS */
> if (!pci_is_pcie(bridge) ||
> pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE)
> - return 0;
> + return false;
> /* If we found the root port, look it up in the ATSR */
> if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
> break;
> @@ -2809,11 +2810,11 @@ static int dmar_ats_supported(struct pci_dev *dev, struct intel_iommu *iommu)
> if (atsru->include_all)
> goto out;
> }
> - ret = 0;
> + supported = false;
> out:
> rcu_read_unlock();
>
> - return ret;
> + return supported;
> }
>
> int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)
--
Regards,
Yi Liu
On Friday, May 9, 2025 5:27 PM, Liu, Yi L wrote:
/5/9 22:00, Wei Wang wrote:
> > According to "Function return values and names" in coding-style.rst,
> > the
> > dmar_ats_supported() function should return a boolean instead of an
> > integer. Also, rename "ret" to "supported" to be more straightforward.
> >
>
> seems just a recommendation since this is just internal helper. The function
> was indeed not well written anyhow. :) not sure if Baolu wants take it or not.
> Taking it may make history tracking harder. Patch itself looks good to me.
>
> Reviewed-by: Yi Liu <yi.l.liu@intel.com>
It seems mandatory to me from coding-style.rst:
"
Mixing up these two sorts of representations is a fertile source of
difficult-to-find bugs. If the C language included a strong distinction
between integers and booleans then the compiler would find these mistakes
for us... but it doesn't. To help prevent such bugs, always follow this
convention::
If the name of a function is an action or an imperative command,
the function should return an error-code integer. If the name
is a predicate, the function should return a "succeeded" boolean.
"
Another reason for making this change is that when we try to add more checks
inside this function (e.g., integrated_device_ats_supported() in patch 3), the added
new function needs to continue following the incorrect style. So, I thought, why
not change it from the foundation 😊
© 2016 - 2025 Red Hat, Inc.