diff mbox series

[net] net: page_pool: add missing free_percpu when page_pool_init fail

Message ID 20231030091256.2915394-1-shaojijie@huawei.com (mailing list archive)
State Accepted
Commit 8ffbd1669ed1d58939d6e878dffaa2f60bf961a4
Delegated to: Netdev Maintainers
Headers show
Series [net] net: page_pool: add missing free_percpu when page_pool_init fail | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1346 this patch: 1346
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1370 this patch: 1370
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1371 this patch: 1371
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 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

Jijie Shao Oct. 30, 2023, 9:12 a.m. UTC
From: Jian Shen <shenjian15@huawei.com>

When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
is not called to free pool->recycle_stats, which may cause memory
leak.

Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 net/core/page_pool.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Yunsheng Lin Oct. 30, 2023, 9:31 a.m. UTC | #1
On 2023/10/30 17:12, Jijie Shao wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.

LGTM.
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>

> 
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  net/core/page_pool.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 77cb75e63aca..31f923e7b5c4 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -221,8 +221,12 @@ static int page_pool_init(struct page_pool *pool,
>  		return -ENOMEM;
>  #endif
>  
> -	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
> +	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
> +#ifdef CONFIG_PAGE_POOL_STATS
> +		free_percpu(pool->recycle_stats);
> +#endif
>  		return -ENOMEM;
> +	}
>  
>  	atomic_set(&pool->pages_state_release_cnt, 0);
>  
>
Jiri Pirko Oct. 30, 2023, 12:07 p.m. UTC | #2
Mon, Oct 30, 2023 at 10:12:56AM CET, shaojijie@huawei.com wrote:
>From: Jian Shen <shenjian15@huawei.com>
>
>When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
>is not called to free pool->recycle_stats, which may cause memory
>leak.

Would be nice to see the use of imperative mood in the patch description
too, not only patch subject. Nevertheless, fix looks fine:

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Somnath Kotur Oct. 30, 2023, 1:44 p.m. UTC | #3
On Mon, 30 Oct, 2023, 18:02 Jiri Pirko, <jiri@resnulli.us> wrote:

> Mon, Oct 30, 2023 at 10:12:56AM CET, shaojijie@huawei.com wrote:
> >From: Jian Shen <shenjian15@huawei.com>
> >
> >When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> >is not called to free pool->recycle_stats, which may cause memory
> >leak.
>
> Would be nice to see the use of imperative mood in the patch description
> too, not only patch subject. Nevertheless, fix looks fine:
>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
>
>
Reviewed-by: Somnath Kotur
>
<somnath.kotur@broadcom.com >
Ilias Apalodimas Nov. 1, 2023, 11:11 a.m. UTC | #4
On Mon, 30 Oct 2023 at 11:17, Jijie Shao <shaojijie@huawei.com> wrote:
>
> From: Jian Shen <shenjian15@huawei.com>
>
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.
>
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  net/core/page_pool.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 77cb75e63aca..31f923e7b5c4 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -221,8 +221,12 @@ static int page_pool_init(struct page_pool *pool,
>                 return -ENOMEM;
>  #endif
>
> -       if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
> +       if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
> +#ifdef CONFIG_PAGE_POOL_STATS
> +               free_percpu(pool->recycle_stats);
> +#endif
>                 return -ENOMEM;
> +       }
>
>         atomic_set(&pool->pages_state_release_cnt, 0);
>
> --
> 2.30.0
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
patchwork-bot+netdevbpf@kernel.org Nov. 2, 2023, 11:50 a.m. UTC | #5
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 30 Oct 2023 17:12:56 +0800 you wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.
> 
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> 
> [...]

Here is the summary with links:
  - [net] net: page_pool: add missing free_percpu when page_pool_init fail
    https://git.kernel.org/netdev/net/c/8ffbd1669ed1

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 77cb75e63aca..31f923e7b5c4 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -221,8 +221,12 @@  static int page_pool_init(struct page_pool *pool,
 		return -ENOMEM;
 #endif
 
-	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
+	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
+#ifdef CONFIG_PAGE_POOL_STATS
+		free_percpu(pool->recycle_stats);
+#endif
 		return -ENOMEM;
+	}
 
 	atomic_set(&pool->pages_state_release_cnt, 0);