[PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()

Can Peng posted 1 patch 3 weeks, 6 days ago
drivers/iommu/iommu.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
Posted by Can Peng 3 weeks, 6 days ago
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@kylinos.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

Re: [PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
Posted by Markus Elfring 3 weeks, 5 days ago
> 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.

Thanks for your interest in further code adjustments.

* I wonder how they fit to the feedback “Applied, thanks.” by Jörg Rödel
  from 2026-01-10.
  https://lore.kernel.org/lkml/stpavkxy3sbevk7zmt4kxyecqy5gc6phubvcfutbtnuk7vphlh@a7aimtvk423i/
  https://lkml.org/lkml/2026/1/10/235

* A shorter summary phrase might become more desirable for this patch variant.
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc4#n687

* Will development interests grow also for another transformation approach
  like the following by the means of the semantic patch language (Coccinelle software)?


@replacement@
expression e;
identifier i;
@@
-struct list_head i;
 ... when exists
     when != i = e
-INIT_LIST_HEAD
+LIST_HEAD
               (
-               &
                i
               );


  I determined that 175 source files of the software “Linux next-20260109” contain
  corresponding update candidates.

Regards,
Markus
Re: [PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
Posted by Vasant Hegde 3 weeks, 4 days ago
On 1/12/2026 6:00 PM, Markus Elfring wrote:
>> 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.
> 
> Thanks for your interest in further code adjustments.
> 
> * I wonder how they fit to the feedback “Applied, thanks.” by Jörg Rödel
>   from 2026-01-10.
>   https://lore.kernel.org/lkml/stpavkxy3sbevk7zmt4kxyecqy5gc6phubvcfutbtnuk7vphlh@a7aimtvk423i/
>   https://lkml.org/lkml/2026/1/10/235

Right. Patch is already applied. @Can, Please rebase patch on top of iommu/next
branch.


> 
> * A shorter summary phrase might become more desirable for this patch variant.
>   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc4#n687
> 
> * Will development interests grow also for another transformation approach
>   like the following by the means of the semantic patch language (Coccinelle software)?
> 
> 
> @replacement@
> expression e;
> identifier i;
> @@
> -struct list_head i;
>  ... when exists
>      when != i = e
> -INIT_LIST_HEAD
> +LIST_HEAD
>                (
> -               &
>                 i
>                );
> 
> 
>   I determined that 175 source files of the software “Linux next-20260109” contain
>   corresponding update candidates.

Interesting!  Thanks for the stat.

-Vasant

Re: [PATCH v2] iommu: simplify list initialization in iommu_create_device_direct_mappings() and iommu_group_show_resv_regions()
Posted by Vasant Hegde 3 weeks, 5 days ago
On 1/12/2026 8:51 AM, Can Peng wrote:
> 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@kylinos.cn>

Patch looks good.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>

-Vasant