From nobody Sat Feb 7 04:00:59 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA186C25B42 for ; Mon, 23 Oct 2023 22:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbjJWWxq (ORCPT ); Mon, 23 Oct 2023 18:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbjJWWxn (ORCPT ); Mon, 23 Oct 2023 18:53:43 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635BA10C; Mon, 23 Oct 2023 15:53:41 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9247E21B37; Mon, 23 Oct 2023 22:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698101619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DLQ46MyUf9JQqxfaCEEB2Yq4zSHDMTH/ehP/eQi7vqY=; b=diftkx2W6M2xZKxLZo4rrz8XG7xpbVEVd+F5kpDYkg8rZZ5oN33DrH5jBWhxYleOjCQyLx 6qw7nKCf45OwAcMZfxLLIiQ/fMJ3ORQzG68B9sPRgS6fH9zEDHmSrwKEoo6p6Lv/Ewpggm R2zQDOmheVs5bJ9ccXJ2H3x1bS8Ibsc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698101619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DLQ46MyUf9JQqxfaCEEB2Yq4zSHDMTH/ehP/eQi7vqY=; b=Uq6MNDIaTIR1Q2CQBCpFe7Jm2aTmZItFsqT+nImKV9XTcGxlvVHQtFEQvpd1+YqeSHAWAR iHtC57vYZ+JJIlDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 84182132FD; Mon, 23 Oct 2023 22:53:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +Ci/DnH5NmXXXgAAMHmgww (envelope-from ); Mon, 23 Oct 2023 22:53:37 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: netdev@vger.kernel.org, "David S. Miller" Cc: LKML , Matthew Wilcox , Chris Mi , Cong Wang Subject: [PATCH] Fix termination state for idr_for_each_entry_ul() Date: Tue, 24 Oct 2023 09:53:33 +1100 Message-id: <169810161336.20306.1410058490199370047@noble.neil.brown.name> Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-3.91 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-1.31)[90.19%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-3.00)[-1.000]; RCPT_COUNT_FIVE(0.00)[6]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[]; FREEMAIL_CC(0.00)[vger.kernel.org,infradead.org,mellanox.com,gmail.com] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Chris Mi Cc: Cong Wang Signed-off-by: NeilBrown --- 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 =3D 0, id =3D 0; \ - tmp <=3D id && ((entry) =3D idr_get_next_ul(idr, &(id))) !=3D NULL; \ + ((entry) =3D tmp <=3D id ? idr_get_next_ul(idr, &(id)) : NULL) !=3D = NULL; \ tmp =3D id, ++id) =20 /** @@ -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 =3D id; \ - tmp <=3D id && ((entry) =3D idr_get_next_ul(idr, &(id))) !=3D NULL; \ + ((entry) =3D tmp <=3D id ? idr_get_next_ul(idr, &(id)) : NULL) !=3D = NULL; \ tmp =3D id, ++id) =20 /* --=20 2.42.0