Thread (7 messages) flat view 7 messages, 3 authors, 2021-11-17

Re: [RFC net-next 1/2] net: add netdev_refs debug

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-11-17 18:35:54

On Wed, 17 Nov 2021 20:24:17 +0200 Leon Romanovsky wrote:
quoted
+/* Store a raw, unprotected pointer */
+static inline void __netdev_ref_store(struct netdev_ref *ref,
+				      struct net_device *dev)
+{
+	ref->dev = dev;
+
+#ifdef CONFIG_DEBUG_OBJECTS_NETDEV_REFS
+	refcount_set(&ref->cnt, 0);  
This is very uncommon pattern. I would expect that first pointer access
will start from 1, like all refcount_t users. If you still prefer to
start from 0, i suggest you to use atomic_t. 
It's not really "starting from 0", it's more of a "setting the count
to invalid". It can't escape from this state with a simple inc.
IMHO, much better will be to use kref for this type of reference counting.
I'm not really sure if the netdev_ref_{get,put}() part is necessary.

Main pattern I'm trying to replace is a pointer which is optionally 
holding a reference (0, 1 references). Rather than a pointer which 
is ref counted (1..n references).

IOW __netdev_ref_store() is much more likely to be used than
netdev_ref_get(), that's also why netdev_put() does not invalidate
the pointer itself.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help