mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fix termination state for idr_for_each_entry_ul()
@ 2023-10-23 22:53 NeilBrown
  2023-10-26  7:22 ` Paolo Abeni
  2023-11-03  9:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: NeilBrown @ 2023-10-23 22:53 UTC (permalink / raw)
  To: netdev, David S. Miller; +Cc: LKML, Matthew Wilcox, Chris Mi, Cong Wang


The comment for idr_for_each_entry_ul() states

  after normal termination @entry is left with the value NULL

This is not correct in the case where UINT_MAX has an entry in the idr.
In that case @entry will be non-NULL after termination.
No current code depends on the documentation being correct, but to
save future code we should fix it.

Also fix idr_for_each_entry_continue_ul().  While this is not documented
as leaving @entry as NULL, the mellanox driver appears to depend on
it doing so.  So make that explicit in the documentation as well as in
the code.

Fixes: e33d2b74d805 ("idr: fix overflow case for idr_for_each_entry_ul()")
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Chris Mi <chrism@mellanox.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
---
 include/linux/idr.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index a0dce14090a9..da5f5fa4a3a6 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -200,7 +200,7 @@ static inline void idr_preload_end(void)
  */
 #define idr_for_each_entry_ul(idr, entry, tmp, id)			\
 	for (tmp = 0, id = 0;						\
-	     tmp <= id && ((entry) = idr_get_next_ul(idr, &(id))) != NULL; \
+	     ((entry) = tmp <= id ? idr_get_next_ul(idr, &(id)) : NULL) != NULL; \
 	     tmp = id, ++id)
 
 /**
@@ -224,10 +224,12 @@ static inline void idr_preload_end(void)
  * @id: Entry ID.
  *
  * Continue to iterate over entries, continuing after the current position.
+ * After normal termination @entry is left with the value NULL.  This
+ * is convenient for a "not found" value.
  */
 #define idr_for_each_entry_continue_ul(idr, entry, tmp, id)		\
 	for (tmp = id;							\
-	     tmp <= id && ((entry) = idr_get_next_ul(idr, &(id))) != NULL; \
+	     ((entry) = tmp <= id ? idr_get_next_ul(idr, &(id)) : NULL) != NULL; \
 	     tmp = id, ++id)
 
 /*
-- 
2.42.0


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

* Re: [PATCH] Fix termination state for idr_for_each_entry_ul()
  2023-10-23 22:53 [PATCH] Fix termination state for idr_for_each_entry_ul() NeilBrown
@ 2023-10-26  7:22 ` Paolo Abeni
  2023-11-03  9:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2023-10-26  7:22 UTC (permalink / raw)
  To: NeilBrown, netdev, David S. Miller
  Cc: LKML, Matthew Wilcox, Chris Mi, Cong Wang

On Tue, 2023-10-24 at 09:53 +1100, NeilBrown wrote:
> The comment for idr_for_each_entry_ul() states
> 
>   after normal termination @entry is left with the value NULL
> 
> This is not correct in the case where UINT_MAX has an entry in the idr.
> In that case @entry will be non-NULL after termination.
> No current code depends on the documentation being correct, but to
> save future code we should fix it.
> 
> Also fix idr_for_each_entry_continue_ul().  While this is not documented
> as leaving @entry as NULL, the mellanox driver appears to depend on
> it doing so.  So make that explicit in the documentation as well as in
> the code.
> 
> Fixes: e33d2b74d805 ("idr: fix overflow case for idr_for_each_entry_ul()")
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Chris Mi <chrism@mellanox.com>
> Cc: Cong Wang <xiyou.wangcong@gmail.com>
> Signed-off-by: NeilBrown <neilb@suse.de>

Since the affected user is in the netdev tree, I think we can take this
patch. But this is also a sort of gray area of the tree... @Matthew are
you ok with that?

Thanks,

Paolo


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

* Re: [PATCH] Fix termination state for idr_for_each_entry_ul()
  2023-10-23 22:53 [PATCH] Fix termination state for idr_for_each_entry_ul() NeilBrown
  2023-10-26  7:22 ` Paolo Abeni
@ 2023-11-03  9:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-03  9:20 UTC (permalink / raw)
  To: NeilBrown; +Cc: netdev, davem, linux-kernel, willy, chrism, xiyou.wangcong

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue, 24 Oct 2023 09:53:33 +1100 you wrote:
> The comment for idr_for_each_entry_ul() states
> 
>   after normal termination @entry is left with the value NULL
> 
> This is not correct in the case where UINT_MAX has an entry in the idr.
> In that case @entry will be non-NULL after termination.
> No current code depends on the documentation being correct, but to
> save future code we should fix it.
> 
> [...]

Here is the summary with links:
  - Fix termination state for idr_for_each_entry_ul()
    https://git.kernel.org/netdev/net/c/e8ae8ad479e2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-11-03  9:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 22:53 [PATCH] Fix termination state for idr_for_each_entry_ul() NeilBrown
2023-10-26  7:22 ` Paolo Abeni
2023-11-03  9:20 ` patchwork-bot+netdevbpf

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®