mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] inet: inet_defrag: Removing the usage of refcount_inc_not_zero
@ 2024-04-15 16:06 Abhinav Jain
  2024-04-15 17:33 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Abhinav Jain @ 2024-04-15 16:06 UTC (permalink / raw)
  To: davem, dsahern, edumazet, kuba, pabeni, netdev, linux-kernel
  Cc: skhan, javier.carrasco.cruz, Abhinav Jain

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;
+		}
 	}
 	rcu_read_unlock();
 	return fq;
-- 
2.34.1


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

end of thread, other threads:[~2024-04-15 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 16:06 [PATCH] inet: inet_defrag: Removing the usage of refcount_inc_not_zero Abhinav Jain
2024-04-15 17:33 ` Eric Dumazet

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

all inboxes | Powered by JetHome®