diff mbox series

inet: inet_defrag: Removing the usage of refcount_inc_not_zero

Message ID 20240415160619.8249-1-jain.abhinav177@gmail.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series inet: inet_defrag: Removing the usage of refcount_inc_not_zero | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
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: 928 this patch: 928
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 938 this patch: 938
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: 939 this patch: 939
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 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

Abhinav Jain April 15, 2024, 4:06 p.m. UTC
Remove refcount_inc_not_zero as per the listed TODO in the file.
Used spin_(un)lock and refcount_* functions for synchronization.

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 net/ipv4/inet_fragment.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Eric Dumazet April 15, 2024, 5:33 p.m. UTC | #1
On Mon, Apr 15, 2024 at 6:06 PM Abhinav Jain <jain.abhinav177@gmail.com> wrote:
>
> Remove refcount_inc_not_zero as per the listed TODO in the file.
> Used spin_(un)lock and refcount_* functions for synchronization.
>
> Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
> ---
>  net/ipv4/inet_fragment.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
> index c88c9034d630..e4838bbe0abb 100644
> --- a/net/ipv4/inet_fragment.c
> +++ b/net/ipv4/inet_fragment.c
> @@ -358,7 +358,6 @@ static struct inet_frag_queue *inet_frag_create(struct fqdir *fqdir,
>         return q;
>  }
>
> -/* TODO : call from rcu_read_lock() and no longer use refcount_inc_not_zero() */
>  struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
>  {
>         /* This pairs with WRITE_ONCE() in fqdir_pre_exit(). */
> @@ -375,8 +374,14 @@ struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
>                 fq = inet_frag_create(fqdir, key, &prev);
>         if (!IS_ERR_OR_NULL(prev)) {
>                 fq = prev;
> -               if (!refcount_inc_not_zero(&fq->refcnt))
> +               spin_lock(&fq->lock);
> +               if (refcount_read(&fq->refcnt) > 0) {
> +                       refcount_inc(&fq->refcnt);
> +                       spin_unlock(&fq->lock);
> +               } else {
> +                       spin_unlock(&fq->lock);
>                         fq = NULL;
> +               }
>

This is bogus. I do not think you understood the comment.
diff mbox series

Patch

diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index c88c9034d630..e4838bbe0abb 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -358,7 +358,6 @@  static struct inet_frag_queue *inet_frag_create(struct fqdir *fqdir,
 	return q;
 }
 
-/* TODO : call from rcu_read_lock() and no longer use refcount_inc_not_zero() */
 struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
 {
 	/* This pairs with WRITE_ONCE() in fqdir_pre_exit(). */
@@ -375,8 +374,14 @@  struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
 		fq = inet_frag_create(fqdir, key, &prev);
 	if (!IS_ERR_OR_NULL(prev)) {
 		fq = prev;
-		if (!refcount_inc_not_zero(&fq->refcnt))
+		spin_lock(&fq->lock);
+		if (refcount_read(&fq->refcnt) > 0) {
+			refcount_inc(&fq->refcnt);
+			spin_unlock(&fq->lock);
+		} else {
+			spin_unlock(&fq->lock);
 			fq = NULL;
+		}
 	}
 	rcu_read_unlock();
 	return fq;