Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH] dma-buf: system_heap: Use LIST_HEAD() to initialize on stack list head
@ 2026-05-19  6:05 Jisheng Zhang
  2026-05-19  6:51 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Jisheng Zhang @ 2026-05-19  6:05 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
	T . J . Mercier, Christian König
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel

Use LIST_HEAD to initialize on stack list head. No intentional
functional impact.

Change generated with below coccinelle script:

@@
identifier name;
@@
- struct list_head name;
+ LIST_HEAD(name);
... when != name
- INIT_LIST_HEAD(&name);

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 drivers/dma-buf/heaps/system_heap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 03c2b87cb111..6f8b7138ff56 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -409,7 +409,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
 	struct dma_buf *dmabuf;
 	struct sg_table *table;
 	struct scatterlist *sg;
-	struct list_head pages;
+	LIST_HEAD(pages);
 	struct page *page, *tmp_page;
 	int i, ret = -ENOMEM;
 
@@ -423,7 +423,6 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
 	buffer->len = len;
 	buffer->cc_shared = cc_shared;
 
-	INIT_LIST_HEAD(&pages);
 	i = 0;
 	while (size_remaining > 0) {
 		/*
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] dma-buf: system_heap: Use LIST_HEAD() to initialize on stack list head
  2026-05-19  6:05 [PATCH] dma-buf: system_heap: Use LIST_HEAD() to initialize on stack list head Jisheng Zhang
@ 2026-05-19  6:51 ` Christian König
  2026-05-19 23:19   ` Jisheng Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2026-05-19  6:51 UTC (permalink / raw)
  To: Jisheng Zhang, Sumit Semwal, Benjamin Gaignard, Brian Starkey,
	John Stultz, T . J . Mercier
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel

On 5/19/26 08:05, Jisheng Zhang wrote:
> Use LIST_HEAD to initialize on stack list head. No intentional
> functional impact.
> 
> Change generated with below coccinelle script:
> 
> @@
> identifier name;
> @@
> - struct list_head name;
> + LIST_HEAD(name);
> ... when != name
> - INIT_LIST_HEAD(&name);

The patch itself looks correct, but my question is why would we want to do that?

Initializing the list head (or any other result variable) directly before it is filled in is usually good practice.

Regards,
Christian.

> 
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  drivers/dma-buf/heaps/system_heap.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> index 03c2b87cb111..6f8b7138ff56 100644
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -409,7 +409,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
>         struct dma_buf *dmabuf;
>         struct sg_table *table;
>         struct scatterlist *sg;
> -       struct list_head pages;
> +       LIST_HEAD(pages);
>         struct page *page, *tmp_page;
>         int i, ret = -ENOMEM;
> 
> @@ -423,7 +423,6 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
>         buffer->len = len;
>         buffer->cc_shared = cc_shared;
> 
> -       INIT_LIST_HEAD(&pages);
>         i = 0;
>         while (size_remaining > 0) {
>                 /*
> --
> 2.53.0
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dma-buf: system_heap: Use LIST_HEAD() to initialize on stack list head
  2026-05-19  6:51 ` Christian König
@ 2026-05-19 23:19   ` Jisheng Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Jisheng Zhang @ 2026-05-19 23:19 UTC (permalink / raw)
  To: Christian König
  Cc: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
	T . J . Mercier, linux-media, dri-devel, linaro-mm-sig,
	linux-kernel

On Tue, May 19, 2026 at 08:51:00AM +0200, Christian König wrote:
> On 5/19/26 08:05, Jisheng Zhang wrote:
> > Use LIST_HEAD to initialize on stack list head. No intentional
> > functional impact.
> > 
> > Change generated with below coccinelle script:
> > 
> > @@
> > identifier name;
> > @@
> > - struct list_head name;
> > + LIST_HEAD(name);
> > ... when != name
> > - INIT_LIST_HEAD(&name);
> 
> The patch itself looks correct, but my question is why would we want to do that?

The benefit is: simpler code, combine the linked list defintion and
initialization in one step, thus 1 LoC vs 2 LoCs; And potential bug
prevention, e.g use the list before intialized.
But I agree, no strong benefit here.
> 
> Initializing the list head (or any other result variable) directly before it is filled in is usually good practice.
> 
> Regards,
> Christian.
> 
> > 
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >  drivers/dma-buf/heaps/system_heap.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> > index 03c2b87cb111..6f8b7138ff56 100644
> > --- a/drivers/dma-buf/heaps/system_heap.c
> > +++ b/drivers/dma-buf/heaps/system_heap.c
> > @@ -409,7 +409,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
> >         struct dma_buf *dmabuf;
> >         struct sg_table *table;
> >         struct scatterlist *sg;
> > -       struct list_head pages;
> > +       LIST_HEAD(pages);
> >         struct page *page, *tmp_page;
> >         int i, ret = -ENOMEM;
> > 
> > @@ -423,7 +423,6 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
> >         buffer->len = len;
> >         buffer->cc_shared = cc_shared;
> > 
> > -       INIT_LIST_HEAD(&pages);
> >         i = 0;
> >         while (size_remaining > 0) {
> >                 /*
> > --
> > 2.53.0
> > 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-19 23:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19  6:05 [PATCH] dma-buf: system_heap: Use LIST_HEAD() to initialize on stack list head Jisheng Zhang
2026-05-19  6:51 ` Christian König
2026-05-19 23:19   ` Jisheng Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox