2021-09-14 01:52:31

by Nicolin Chen

[permalink] [raw]
Subject: [PATCH v6 2/6] iommu/tegra-smmu: Rename struct tegra_smmu_group_soc *soc to *group_soc

There are both tegra_smmu_soc and tegra_smmu_group_soc using "soc"
for their pointer instances. This patch renames the one of struct
tegra_smmu_group_soc from "soc" to "group_soc" to distinguish it.

Signed-off-by: Nicolin Chen <[email protected]>
---
drivers/iommu/tegra-smmu.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 6ebae635d3aa..a32ed347e25d 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -22,7 +22,7 @@
struct tegra_smmu_group {
struct list_head list;
struct tegra_smmu *smmu;
- const struct tegra_smmu_group_soc *soc;
+ const struct tegra_smmu_group_soc *group_soc;
struct iommu_group *grp;
unsigned int swgroup;
};
@@ -870,7 +870,7 @@ static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
static void tegra_smmu_release_device(struct device *dev) {}

static const struct tegra_smmu_group_soc *
-tegra_smmu_find_group(struct tegra_smmu *smmu, unsigned int swgroup)
+tegra_smmu_find_group_soc(struct tegra_smmu *smmu, unsigned int swgroup)
{
unsigned int i, j;

@@ -896,19 +896,20 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct tegra_smmu *smmu = dev_iommu_priv_get(dev);
- const struct tegra_smmu_group_soc *soc;
+ const struct tegra_smmu_group_soc *group_soc;
unsigned int swgroup = fwspec->ids[0];
struct tegra_smmu_group *group;
struct iommu_group *grp;

/* Find group_soc associating with swgroup */
- soc = tegra_smmu_find_group(smmu, swgroup);
+ group_soc = tegra_smmu_find_group_soc(smmu, swgroup);

mutex_lock(&smmu->lock);

/* Find existing iommu_group associating with swgroup or group_soc */
list_for_each_entry(group, &smmu->groups, list)
- if ((group->swgroup == swgroup) || (soc && group->soc == soc)) {
+ if ((group->swgroup == swgroup) ||
+ (group_soc && group->group_soc == group_soc)) {
grp = iommu_group_ref_get(group->grp);
mutex_unlock(&smmu->lock);
return grp;
@@ -921,9 +922,9 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
}

INIT_LIST_HEAD(&group->list);
+ group->group_soc = group_soc;
group->swgroup = swgroup;
group->smmu = smmu;
- group->soc = soc;

if (dev_is_pci(dev))
group->grp = pci_device_group(dev);
@@ -937,8 +938,8 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
}

iommu_group_set_iommudata(group->grp, group, tegra_smmu_group_release);
- if (soc)
- iommu_group_set_name(group->grp, soc->name);
+ if (group_soc)
+ iommu_group_set_name(group->grp, group_soc->name);
list_add_tail(&group->list, &smmu->groups);
mutex_unlock(&smmu->lock);

--
2.17.1


2021-10-07 19:42:04

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH v6 2/6] iommu/tegra-smmu: Rename struct tegra_smmu_group_soc *soc to *group_soc

On Mon, Sep 13, 2021 at 06:38:54PM -0700, Nicolin Chen wrote:
> There are both tegra_smmu_soc and tegra_smmu_group_soc using "soc"
> for their pointer instances. This patch renames the one of struct
> tegra_smmu_group_soc from "soc" to "group_soc" to distinguish it.
>
> Signed-off-by: Nicolin Chen <[email protected]>
> ---
> drivers/iommu/tegra-smmu.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)

I think the context makes it clear which one this is. The "soc" field in
struct tegra_smmu_group clearly refers to the group SoC data, whereas
the "soc" field in struct tegra_smmu refers to the SMMU SoC data.

>
> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
> index 6ebae635d3aa..a32ed347e25d 100644
> --- a/drivers/iommu/tegra-smmu.c
> +++ b/drivers/iommu/tegra-smmu.c
> @@ -22,7 +22,7 @@
> struct tegra_smmu_group {
> struct list_head list;
> struct tegra_smmu *smmu;
> - const struct tegra_smmu_group_soc *soc;
> + const struct tegra_smmu_group_soc *group_soc;
> struct iommu_group *grp;
> unsigned int swgroup;
> };
> @@ -870,7 +870,7 @@ static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
> static void tegra_smmu_release_device(struct device *dev) {}
>
> static const struct tegra_smmu_group_soc *
> -tegra_smmu_find_group(struct tegra_smmu *smmu, unsigned int swgroup)
> +tegra_smmu_find_group_soc(struct tegra_smmu *smmu, unsigned int swgroup)

This one might be okay to disambiguate, but even here I think this isn't
really necessary. It's already clear from the return value what's being
returned.

> {
> unsigned int i, j;
>
> @@ -896,19 +896,20 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
> {
> struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> struct tegra_smmu *smmu = dev_iommu_priv_get(dev);
> - const struct tegra_smmu_group_soc *soc;
> + const struct tegra_smmu_group_soc *group_soc;
> unsigned int swgroup = fwspec->ids[0];
> struct tegra_smmu_group *group;
> struct iommu_group *grp;
>
> /* Find group_soc associating with swgroup */
> - soc = tegra_smmu_find_group(smmu, swgroup);
> + group_soc = tegra_smmu_find_group_soc(smmu, swgroup);
>
> mutex_lock(&smmu->lock);
>
> /* Find existing iommu_group associating with swgroup or group_soc */
> list_for_each_entry(group, &smmu->groups, list)
> - if ((group->swgroup == swgroup) || (soc && group->soc == soc)) {
> + if ((group->swgroup == swgroup) ||
> + (group_soc && group->group_soc == group_soc)) {
> grp = iommu_group_ref_get(group->grp);
> mutex_unlock(&smmu->lock);
> return grp;
> @@ -921,9 +922,9 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
> }
>
> INIT_LIST_HEAD(&group->list);
> + group->group_soc = group_soc;
> group->swgroup = swgroup;
> group->smmu = smmu;
> - group->soc = soc;

As another example, it's pretty evident that group->soc refers to the
group SoC data rather than the SMMU SoC data. The latter can be obtained
from group->smmu->soc, which again is enough context to make it clear
what this is.

So I don't think this makes things any clearer. It only makes the names
more redundant and awkward to write.

Thierry


Attachments:
(No filename) (3.24 kB)
signature.asc (849.00 B)
Download all attachments

2021-10-07 20:53:38

by Nicolin Chen

[permalink] [raw]
Subject: Re: [PATCH v6 2/6] iommu/tegra-smmu: Rename struct tegra_smmu_group_soc *soc to *group_soc

On Thu, Oct 07, 2021 at 06:50:52PM +0200, Thierry Reding wrote:

> > static const struct tegra_smmu_group_soc *
> > -tegra_smmu_find_group(struct tegra_smmu *smmu, unsigned int swgroup)
> > +tegra_smmu_find_group_soc(struct tegra_smmu *smmu, unsigned int swgroup)
>
> This one might be okay to disambiguate, but even here I think this isn't
> really necessary. It's already clear from the return value what's being
> returned.

The point here is to disambiguate "group", as there are quite a few
places using the same naming for different structures. You may argue
that it's clear by looking at the return value/type. But it is still
hard to tell when reading the code of its caller, right?

> > @@ -921,9 +922,9 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev)
> > }
> >
> > INIT_LIST_HEAD(&group->list);
> > + group->group_soc = group_soc;
> > group->swgroup = swgroup;
> > group->smmu = smmu;
> > - group->soc = soc;
>
> As another example, it's pretty evident that group->soc refers to the
> group SoC data rather than the SMMU SoC data. The latter can be obtained
> from group->smmu->soc, which again is enough context to make it clear
> what this is.
>
> So I don't think this makes things any clearer. It only makes the names
> more redundant and awkward to write.

Okay. I will drop the part of s/soc/group_soc.