Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1847033pxb; Thu, 7 Oct 2021 16:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeb48ggFX4ZSncEoDkjr4w39FsH4gUTeqpFptznTun+BiPSoQIdCnjuStexauSM5YGYHm1 X-Received: by 2002:a17:906:1901:: with SMTP id a1mr9639015eje.129.1633650794809; Thu, 07 Oct 2021 16:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650794; cv=none; d=google.com; s=arc-20160816; b=N7H2DVhdHBjYd47xNs2zptkgpbM1lgh2x/u5eMOZ0FRbgY/hJ24lpes4qzmQ8Q6ICK dnk1udUYhWngMKfmhtvo4ANsq+nJ+5AjGs59OCIGlUXFaUk8KPF55s2W6qRy88DK19Q9 8+gl5GVmkydlFQuEfezQb66C4CU5mTDQg1Cz7XuyH6Boh7M3kCfjghkrmr/yq+cpUQeC ukSsprkqZ6VhumIcYhCeMQUUqx6M9TZcVAWSnWc/2Rg0Mf6qCZTD3Lvq/9Hvgxi2ZMQx PCiCaY4sO5bXH8AzVu+u2CsxhQ7KKQiVWaOHjtSx4PKq2cXyL5cQxiE4jPv/d7S+gHeE rNaA== 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 :dkim-signature; bh=6e39aL4HLnRACkqXPdSOU02ep3H9ltSIfuFtoAOZeqE=; b=lEWtAeEHPEECvJrA6uqYqS0Tqqoo2x3uZG0IVGHLdsDlrhP2saDl0/U/J40CHvHCzj VN3SkEIZdhvnH/YU3/GdbMCjt4ZDCLnnn9lUXPnOfwVK1ss3y/agXHTNd//stb+VWlIB HOnsQ/htihlBLYynVB2KfPgnJ9NR4Z1xiiBGlWmvl6JzTUQKtLJWnrGiDHLXzcKQ4YaS sagl38pvwLMn6dJaKl2YdJiNCCEZGbDXsmryno0P1rUI6BSPIu50E72vvPq25IYdfYq0 dShW2tFciflC2E9aY6b9DPZUlB94ptoUD1EgKhepmzk97SLoX4h51WVsXXZbelL96Zxt XQtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OOAyfAz1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si1262804ejc.230.2021.10.07.16.52.50; Thu, 07 Oct 2021 16:53:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OOAyfAz1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234163AbhJGXvF (ORCPT + 99 others); Thu, 7 Oct 2021 19:51:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbhJGXvF (ORCPT ); Thu, 7 Oct 2021 19:51:05 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB3EC061570 for ; Thu, 7 Oct 2021 16:49:10 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id z20so29022926edc.13 for ; Thu, 07 Oct 2021 16:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=6e39aL4HLnRACkqXPdSOU02ep3H9ltSIfuFtoAOZeqE=; b=OOAyfAz1BBcaxtO0aWdjutrTQ/sat7LfWu4imx/Yrr+QnoTt6nR/vi48nebxdF4B7G yFa0m5bIIPVeNnpFPyoiUnkoS0BLzXOrF1MNZ2tpp6TOxe1RL+XCxEp8CF7fA1kKzUjO rRPNlOrGNKuiFlIRnZO3NHGd0iL0AsLNDznctjUWcL/INqy9gw4trwdx/EjPsRyX9aOm iWVSMrieMz0B9ibHYdXf1fRDL9Gr3Pd+O7NlXQGEmwsYmmBz3/8bH0Za6Qj7JfLj2yuW 19QuWfMPuEpFdQCkEFOpjuaQMu6tS2Ryi4jAYJ44Qnd60J0F+CbQ2Ko3DLF8z/uzWMRX 3V+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6e39aL4HLnRACkqXPdSOU02ep3H9ltSIfuFtoAOZeqE=; b=PwJgz29SdpWzgFDioDQJ1KplL+QAiYxu6ZRWD7+zcY2eGSGAnLHWI//kKE9V34NS6W 4MCL/I3WahOVWiSj8k37kiRNVBRFTD38By0qgZwYw0AsN5PYRMQVdCzjNImqKnBwnCU9 OCPA3qmpyUoRTDIhnd8odq+F17HuD1bhlFYKHox1ZoUCNJpz0NZXRQBNd8hb+aKDHUtr FkQ0nOjbUU63+KTm9NACOqQcy5myZPP+OFQ/YwRv5O4CzoXV3lrhvA6l+7EKhCNo5TJR HtOjBpCqLGRtHgk7nTaflNBPC0gv63/LI+jXh0v4IgRh7XbmTB3SSt3Fr6VJcTkhSzNa 6qZg== X-Gm-Message-State: AOAM531pSxfFKh8PdcwWmBkI89kZ8YikRSmBfz9dJRkEGCnQAPUPhRRV cHYkrgtbquhPEUXHYJOY1DE= X-Received: by 2002:a05:6402:2712:: with SMTP id y18mr8428679edd.116.1633650549129; Thu, 07 Oct 2021 16:49:09 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id s24sm333820edy.38.2021.10.07.16.49.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:49:08 -0700 (PDT) From: Wei Yang To: kuba@kernel.org, gregkh@linuxfoundation.org, neilb@suse.com, mojha@codeaurora.org, jkosina@suse.cz Cc: linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] hashtable: add documentation for hash_for_each[_xxx] Date: Thu, 7 Oct 2021 23:48:07 +0000 Message-Id: <20211007234807.4292-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hash_for_each[_xxx] introduce a new loop command constructed from 2 nested loops. To make it work like normal loop, 'obj == NULL' is explicitly put in loop check to break out not only inner loop but also the outer loop. This patch adds a documentation to clarify this behavior. Signed-off-by: Wei Yang Reviewed-by: NeilBrown --- include/linux/hashtable.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h index f6c666730b8c..355681c632ff 100644 --- a/include/linux/hashtable.h +++ b/include/linux/hashtable.h @@ -122,6 +122,10 @@ static inline void hash_del_rcu(struct hlist_node *node) * @bkt: integer to use as bucket loop cursor * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * Note: It is safe to 'break' out of this loop even though it is a two nested + * loops. The 'obj == NULL' test ensures that when the inner loop is broken, + * the outer loop will break too. */ #define hash_for_each(name, bkt, obj, member) \ for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\ @@ -134,6 +138,8 @@ static inline void hash_del_rcu(struct hlist_node *node) * @bkt: integer to use as bucket loop cursor * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * Note: It is safe to 'break' out of this loop. */ #define hash_for_each_rcu(name, bkt, obj, member) \ for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\ @@ -148,6 +154,8 @@ static inline void hash_del_rcu(struct hlist_node *node) * @tmp: a &struct hlist_node used for temporary storage * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * Note: It is safe to 'break' out of this loop. */ #define hash_for_each_safe(name, bkt, tmp, obj, member) \ for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\ -- 2.23.0