[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260112032116.49781-1-pengcan@kylinos.cn>
Date: Mon, 12 Jan 2026 11:21:16 +0800
From: Can Peng <pengcan@...inos.cn>
To: joro@...tes.org,
will@...nel.org,
robin.murphy@....com,
Markus.Elfring@....de
Cc: iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Can Peng <pengcan@...inos.cn>
Subject: [PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
Use LIST_HEAD() to declare and initialize list heads in both
iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
instead of separate declaration and INIT_LIST_HEAD(). This simplifies the
code by combining declaration and initialization into a single idiomatic
form, improving readability without changing functionality.
Signed-off-by: Can Peng <pengcan@...inos.cn>
---
>> Use LIST_HEAD() to declare and initialize the 'mappings' list head in
>> iommu_create_device_direct_mappings() instead of separate declaration and
>> INIT_LIST_HEAD(). This simplifies the code by combining declaration and
>> initialization into a single idiomatic form, improving readability without
>> changing functionality.
>…
>
>How do you think about to repeat the mentioned transformation approach for the implementation
>of the function “iommu_group_show_resv_regions”?
>https://elixir.bootlin.com/linux/v6.19-rc4/source/drivers/iommu/iommu.c#L949-L969
Changes since v1:
- Extend the cleanup to iommu_group_show_resv_regions() as suggested by
reviewer, applying the same LIST_HEAD() pattern consistently across
the file.
Best regards,
Can Peng
drivers/iommu/iommu.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 2ca990dfbb88..b9ffd001b4b3 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -950,10 +950,9 @@ static ssize_t iommu_group_show_resv_regions(struct iommu_group *group,
char *buf)
{
struct iommu_resv_region *region, *next;
- struct list_head group_resv_regions;
+ LIST_HEAD(group_resv_regions);
int offset = 0;
- INIT_LIST_HEAD(&group_resv_regions);
iommu_get_group_resv_regions(group, &group_resv_regions);
list_for_each_entry_safe(region, next, &group_resv_regions, list) {
@@ -1173,12 +1172,11 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
struct device *dev)
{
struct iommu_resv_region *entry;
- struct list_head mappings;
+ LIST_HEAD(mappings);
unsigned long pg_size;
int ret = 0;
pg_size = domain->pgsize_bitmap ? 1UL << __ffs(domain->pgsize_bitmap) : 0;
- INIT_LIST_HEAD(&mappings);
if (WARN_ON_ONCE(iommu_is_dma_domain(domain) && !pg_size))
return -EINVAL;
--
2.25.1
Powered by blists - more mailing lists