Message ID | 169810161336.20306.1410058490199370047@noble.neil.brown.name |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1597247vqx; Mon, 23 Oct 2023 15:54:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDIJStuq6jfSN3kWuC+VAqcmKCkCT9FvAMIkuaJ35QiGqCUzlFCBCYSqVspfwRXcPN4aWA X-Received: by 2002:a05:6359:2e88:b0:168:dc05:b3fe with SMTP id rp8-20020a0563592e8800b00168dc05b3femr4480359rwb.14.1698101641237; Mon, 23 Oct 2023 15:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698101641; cv=none; d=google.com; s=arc-20160816; b=dl8TZ2RpYDB8jO+9yNeNuPxYcL7pfkBTxrxxfhPBzB3MEXZnOkNjKmduTw+cC92O6x Z36QIoFN60pwzzRI4lJnZNhspJvWyGBR6d+olhb4CGYEASshM5DRhLl0Ecg7A9tp6Td0 QGV3LTuwlOHIwUu74jPtM8qZxVBRUzJq/jE1L6dBoXwKl4l1Lk6E/NIwrRPbi9+q8YNW Hsh/27qdpzKGsyoVx1gvU8xr8w+chHfcQ3h/EdKaKoolymDyawA9pOkO1e0ki/94AnYo IAsPhoa3Z6yXh5K7yHLhPJc04bZD4q6+8gKuIdTxWD5uYzYZYtNU9PvLIsE1tFAfkQmA sigQ== 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 header.b=Uq6MNDIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s128-20020a637786000000b005660335e26fsi7090595pgc.485.2023.10.23.15.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 15:54:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; 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 header.b=Uq6MNDIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 2FA1E803113F; Mon, 23 Oct 2023 15:53:59 -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 S230260AbjJWWxp (ORCPT <rfc822;aposhian.dev@gmail.com> + 27 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <neilb@suse.de>); 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" <neilb@suse.de> To: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net> Cc: LKML <linux-kernel@vger.kernel.org>, Matthew Wilcox <willy@infradead.org>, Chris Mi <chrism@mellanox.com>, Cong Wang <xiyou.wangcong@gmail.com> 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: <linux-kernel.vger.kernel.org> 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:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780588626298461734 X-GMAIL-MSGID: 1780588626298461734 |
Series |
Fix termination state for idr_for_each_entry_ul()
|
|
Commit Message
NeilBrown
Oct. 23, 2023, 10:53 p.m. UTC
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(-)
Comments
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
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!
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) /*