diff mbox series

[net-next,03/24] net: Use __napi_alloc_frag_align() instead of open coding it.

Message ID 20231215171020.687342-4-bigeasy@linutronix.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series locking: Introduce nested-BH locking. | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1117 this patch: 1117
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 1143 this patch: 1143
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1144 this patch: 1144
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sebastian Andrzej Siewior Dec. 15, 2023, 5:07 p.m. UTC
The else condition within __netdev_alloc_frag_align() is an open coded
__napi_alloc_frag_align().

Use __napi_alloc_frag_align() instead of open coding it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 net/core/skbuff.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Paolo Abeni Dec. 18, 2023, 7:48 a.m. UTC | #1
On Fri, 2023-12-15 at 18:07 +0100, Sebastian Andrzej Siewior wrote:
> The else condition within __netdev_alloc_frag_align() is an open coded
> __napi_alloc_frag_align().
> 
> Use __napi_alloc_frag_align() instead of open coding it.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  net/core/skbuff.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index b157efea5dea8..de9397e45718a 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -311,11 +311,8 @@ void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask)
>  
>  		data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask);
>  	} else {
> -		struct napi_alloc_cache *nc;
> -
>  		local_bh_disable();
> -		nc = this_cpu_ptr(&napi_alloc_cache);
> -		data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask);

There is a:

	fragsz = SKB_DATA_ALIGN(fragsz);

statement just before the enclosing 'if'. I would consider moving such
assignment inside the 'then' branch - since __napi_alloc_frag_align()
already include that.

/P
Sebastian Andrzej Siewior Jan. 12, 2024, 9:01 a.m. UTC | #2
On 2023-12-18 08:48:56 [+0100], Paolo Abeni wrote:
> > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > index b157efea5dea8..de9397e45718a 100644
> > --- a/net/core/skbuff.c
> > +++ b/net/core/skbuff.c
> > @@ -311,11 +311,8 @@ void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask)
> >  
> >  		data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask);
> >  	} else {
> > -		struct napi_alloc_cache *nc;
> > -
> >  		local_bh_disable();
> > -		nc = this_cpu_ptr(&napi_alloc_cache);
> > -		data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask);
> 
> There is a:
> 
> 	fragsz = SKB_DATA_ALIGN(fragsz);
> 
> statement just before the enclosing 'if'. I would consider moving such
> assignment inside the 'then' branch - since __napi_alloc_frag_align()
> already include that.

Okay, moved.

> /P
Sebastian
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b157efea5dea8..de9397e45718a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -311,11 +311,8 @@  void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask)
 
 		data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask);
 	} else {
-		struct napi_alloc_cache *nc;
-
 		local_bh_disable();
-		nc = this_cpu_ptr(&napi_alloc_cache);
-		data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask);
+		data = __napi_alloc_frag_align(fragsz, align_mask);
 		local_bh_enable();
 	}
 	return data;