diff mbox series

[v1] mm/dmapool.c: Replace open-coded list_first_entry()

Message ID 20200812153059.51089-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1] mm/dmapool.c: Replace open-coded list_first_entry() | expand

Commit Message

Andy Shevchenko Aug. 12, 2020, 3:30 p.m. UTC
There is a place in the code where open-coded version of list_first_entry()
is used. Replace that with the standard macro.

While here, separate definitions from the code to avoid a churn by janitors.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 mm/dmapool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox Aug. 12, 2020, 6:41 p.m. UTC | #1
On Wed, Aug 12, 2020 at 06:30:59PM +0300, Andy Shevchenko wrote:
>  	while (!list_empty(&pool->page_list)) {
>  		struct dma_page *page;
> -		page = list_entry(pool->page_list.next,
> -				  struct dma_page, page_list);
> +
> +		page = list_first_entry(&pool->page_list, struct dma_page, page_list);

Eh, I'd rather see this as:

		struct dma_page *page = list_first_entry(&pool->page_list,
				struct dma_page, page_list);
Andy Shevchenko Aug. 13, 2020, 11:09 a.m. UTC | #2
On Wed, Aug 12, 2020 at 07:41:41PM +0100, Matthew Wilcox wrote:
> On Wed, Aug 12, 2020 at 06:30:59PM +0300, Andy Shevchenko wrote:
> >  	while (!list_empty(&pool->page_list)) {
> >  		struct dma_page *page;
> > -		page = list_entry(pool->page_list.next,
> > -				  struct dma_page, page_list);
> > +
> > +		page = list_first_entry(&pool->page_list, struct dma_page, page_list);
> 
> Eh, I'd rather see this as:
> 
> 		struct dma_page *page = list_first_entry(&pool->page_list,
> 				struct dma_page, page_list);

On the second thought we may convert the entire loop to use
list_for_each_entry_safe() since there is no locking in between, we
should be fine.
diff mbox series

Patch

diff --git a/mm/dmapool.c b/mm/dmapool.c
index f9fb9bbd733e..049ac1459714 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -283,8 +283,8 @@  void dma_pool_destroy(struct dma_pool *pool)
 
 	while (!list_empty(&pool->page_list)) {
 		struct dma_page *page;
-		page = list_entry(pool->page_list.next,
-				  struct dma_page, page_list);
+
+		page = list_first_entry(&pool->page_list, struct dma_page, page_list);
 		if (is_page_busy(page)) {
 			if (pool->dev)
 				dev_err(pool->dev,