Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1527508rda; Mon, 23 Oct 2023 15:53:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFU2fIVo9eVNkGP3M3wGoAuEyXMouUdeanVGP3YoO19UsJRhW6E0nJJ0uKqtkeIQ6l02QGi X-Received: by 2002:a05:6a20:e128:b0:14c:c511:387d with SMTP id kr40-20020a056a20e12800b0014cc511387dmr1234275pzb.9.1698101632808; Mon, 23 Oct 2023 15:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698101632; cv=none; d=google.com; s=arc-20160816; b=gdIxPBJjm0tCCM2uhoD9dvU9ZZ8sL1URUnIHNpLzTLPdQ+ahi3/fV7Y73x+qDBIvn8 C9pHHPYaay/7gYq0HzlVWQMJX6zu64QhfzVUf+nazxfGICBBnVKWNaul+mBNee+VPJNI uKCCFgoprlKreDSAueuHCiZd/H7tfJsI4LDZYNA/ltDPNoc/fWTu95XkYxAUMG+sKJ6u HTBtAEuPPfx7LNYeyiXg5gI7LzPV7N5NAFoOiDxyh5UF6PzT9WB1wT2SZ4LhHGNvZnye I93J4tmX3DNl3aUIwX7/Hu/iY7o9gEoB4fVb8oN8XrQAswk4IodQkQE2DZKomNRM7jJT W1LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:mime-version :content-transfer-encoding:dkim-signature:dkim-signature; bh=DLQ46MyUf9JQqxfaCEEB2Yq4zSHDMTH/ehP/eQi7vqY=; fh=JygKlxT4GmcsHgPorkkZ4MMpnbuqy9kY/7IbJsHVmqA=; b=ikBIyzvDqWg58aBAe5F0IeIi301KiHVaXyQFbf0AwjGVaMGfCxTLA31FjQZL+zwwPH C+lysK+XEq9fRSxUfCO8AaSW6nJuzDsOWPAJ0ZXD3RZvYh8buFu8T/vBxXG53aNfxMKd 7YZp4yv4Lg6D6TZjqKzsaEarwNinjutsw4f+rc9acHJy5Eo3RGhS5rpPjF5SQUAZnJ0q zhvnaCzvmluMUoxkEfJHsSqsKJPo+8uxt5uXXgJ6w39ETsTT9iJgkOzLWK7B0gThHOp4 oqbQmX0oZ5rX//2TJuCcvqt3zJxrhwGdqLOOOoBVXJ7+anGX/nXfNZ9bjCq+wGP179yn CM2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=diftkx2W; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q15-20020a17090311cf00b001c62e42ad8bsi7386531plh.72.2023.10.23.15.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 15:53:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=diftkx2W; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6D24B8031138; Mon, 23 Oct 2023 15:53:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbjJWWxp (ORCPT + 99 others); Mon, 23 Oct 2023 18:53:45 -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: 7bit 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-Spam-Level: X-Spam-Score: -3.91 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] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 15:53:50 -0700 (PDT) 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 = 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