From patchwork Tue Mar 1 07:58:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764274 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD7BDC433F5 for ; Tue, 1 Mar 2022 07:58:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48D0F8D0003; Tue, 1 Mar 2022 02:58:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 415598D0001; Tue, 1 Mar 2022 02:58:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B5A08D0003; Tue, 1 Mar 2022 02:58:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 1D8FA8D0001 for ; Tue, 1 Mar 2022 02:58:58 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D83C323DB5 for ; Tue, 1 Mar 2022 07:58:57 +0000 (UTC) X-FDA: 79195066314.02.90ABF18 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf19.hostedemail.com (Postfix) with ESMTP id 696791A0009 for ; Tue, 1 Mar 2022 07:58:57 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id d187so13460737pfa.10 for ; Mon, 28 Feb 2022 23:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A25GcqUFVN2qz3QO76ICHSNj41DHlj4ABgVqzMafhNg=; b=hVlBBk7cs3/dXDPXoxjOjlK9Y2BjNWryWa8KLFqkxMZ5ftNCcm0uTY3qgZ7j31jVdE NhAaG15pa6YHcqJrKGZ4lLVFaxxfcvKBBdFIiwMikx65WVALF2ZyVQ+KTVRaghMfTH0I p5g2esJOzzR3Yr587LNne8gGAKIjHfiX75OEHWXutMQKgC2pkNRDzvcLsmu7YRDSwyNt J5eed6MBS7KSGP0xLrSgVRfq8sjHu8/Z0Zr+42wZRfwZZLWen1ndY0pLNyxau4KukI7u OUORMosGY7bR8f0Hq3ApDq+5m6lWzaZIUan654q+W/RtAwKEhkenqXGM81YkqYfiFq30 jOvA== 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:in-reply-to :references; bh=A25GcqUFVN2qz3QO76ICHSNj41DHlj4ABgVqzMafhNg=; b=wRurKqPEf5Zb8Gs+KVh0NaVjFbozIoO4C5D9cFZzd9H97agmntkCgUAKSnhseAhtYW IBdRkchWL3FdyJgpJCZyKYamOcS8IuMfN846ZhaZnlNnzcl3YE3VysCqrwkosrEfMpCp KbVdB3MUs6DmKBzkIw7BVnFxDTh5WNl7fxaw6tF/oz6QNmHdGFcRk56RSwhO9ZDqX/RM RNelJUMTY9fyBJ0N++EGo3kK5BM51gnbiqfq7nhU75q8yLt+ZjqVHK1R8sW/csCqgqQA cDz65quiSS8KaDdc/RgQ+HEP0fewW3XDlD0BEvTNKu6mGN4tkQn0hmJcda2FdLqlf0Dq soTg== X-Gm-Message-State: AOAM531oy+vwPJ/+W9j618hRHvVmqs1uzYhSCkomoaQS4rIw+Vh5nfal G35tgjgXByHWjTtNq/84ji8= X-Google-Smtp-Source: ABdhPJwz/5TAUp9XKAqJDu66ccB4TZTOrvlYbd+foqA41ACOpsKAIWqQCfWfUYS1KUrpFS2b84vyqA== X-Received: by 2002:a05:6a00:2286:b0:4e1:285:5715 with SMTP id f6-20020a056a00228600b004e102855715mr26166424pfe.37.1646121536489; Mon, 28 Feb 2022 23:58:56 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:58:56 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 1/6] Kbuild: compile kernel with gnu11 std Date: Tue, 1 Mar 2022 15:58:34 +0800 Message-Id: <20220301075839.4156-2-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 696791A0009 X-Stat-Signature: 3j8m8whiiuwm8wzam57apbbfzww9xt6j Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hVlBBk7c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com X-HE-Tag: 1646121537-572614 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This patch is suggested by linus[1], there may be some corner cases which should be considered before merge, and is just for prove PATCH 2. [1]: https://lore.kernel.org/all/CAHk-=wh97QY9fEQUK6zMVQwaQ_JWDvR=R+TxQ_0OYrMHQ+egvQ@mail.gmail.com/ Signed-off-by: Xiaomeng Tong Reported-by: kernel test robot --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 289ce2be8..84a96ae3c 100644 --- a/Makefile +++ b/Makefile @@ -515,7 +515,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror=implicit-function-declaration -Werror=implicit-int \ -Werror=return-type -Wno-format-security \ - -std=gnu89 + -std=gnu11 -Wno-shift-negative-value KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := From patchwork Tue Mar 1 07:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764275 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BF90C433F5 for ; Tue, 1 Mar 2022 07:59:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDAAA8D0005; Tue, 1 Mar 2022 02:59:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D63A88D0001; Tue, 1 Mar 2022 02:59:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C04CD8D0005; Tue, 1 Mar 2022 02:59:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id ADC5F8D0001 for ; Tue, 1 Mar 2022 02:59:04 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 589048249980 for ; Tue, 1 Mar 2022 07:59:04 +0000 (UTC) X-FDA: 79195066608.26.72654EE Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf24.hostedemail.com (Postfix) with ESMTP id D9CFE180006 for ; Tue, 1 Mar 2022 07:59:03 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id z11so4426057pla.7 for ; Mon, 28 Feb 2022 23:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YmXLEDuShcOW3JnBcgY++d4c0kg2D36rSz3AenVtmRY=; b=P+Lo9i6QowRAx0EEntsNvNUxCt1I6HaXTfmY+33mqDxWWil2KSfipziM4Nn/14h0Oq z3ypRqxwexLrfYlQJoFd5+rVz7UslgYwUmHKWvJwvuKairaWtKd3veo5qsliUZ77MFPs 4HnpB+JqFuavKk7cpK2Xv26KsS2ayZZif2Pr2d/FgeJA2JDTyHKjs7+K7Ws+K0zgWKRI ruFI6zDEScMjqU+vBM3+W3qJPu1gsLFAzxWdPEOww2yB+9dZENlLnBl8qdXU/rKNsiTR Eg+MOzpR1yqVnUoWa8XtPdBWxpwcFODjLHq/RzIc9anKNpZ0JutOuz4IzAjjjND7Pu74 wYFQ== 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:in-reply-to :references; bh=YmXLEDuShcOW3JnBcgY++d4c0kg2D36rSz3AenVtmRY=; b=GbVC3nS05kO1SioQtUUMZyOiVQo+QFTWspSHCsMjyRKje7tBoAQzl6nl5uz4Z6mNYq H5GGt2ENbLVhbbvJhBHASi8ZTeNAjt6OTr4N0Ky19W0L/Qcy0Z7H/lH6eAd3mZjuDaJe ZAONIMX8Z3E09+WsUFyXiYDKg/IKuG2fqP8Kkp2gQqs3WG2PsGn5TR2K4huIrbIGUzXB GiPu2MhGVSq8JF+VoRgkzhKPgtgU1nUI+lBxHMfUSTLjGdEegCQBvPL3rPLDW1XxP55Q RhvIj7hBbEj6VOhXg3ZExdAyhdBq1nECW0u0J0PlXBrh3PU64LOk0JxbfU0rnxQ8PTzj 2C9w== X-Gm-Message-State: AOAM532kNNK4GPzTkyi37pgkT/6ffxI4ewOZjZ1xw/CVF0oeSJaYPk0L kkbe5Ioy9o6fALMG15KMlWY= X-Google-Smtp-Source: ABdhPJzyKErM8pnzRaH8ojeB27k6eMiFHyMnxjPUJP6pxbk0TO4CP5X8i6d+VfvO4iKjFenzpV33QA== X-Received: by 2002:a17:902:7d83:b0:14e:f2f4:743 with SMTP id a3-20020a1709027d8300b0014ef2f40743mr24258960plm.107.1646121542543; Mon, 28 Feb 2022 23:59:02 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:59:02 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Date: Tue, 1 Mar 2022 15:58:35 +0800 Message-Id: <20220301075839.4156-3-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D9CFE180006 X-Stat-Signature: zx95jhfxhmq4ekuzyndc81ir755jc541 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P+Lo9i6Q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com X-HE-Tag: 1646121543-12078 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For each list_for_each_entry* macros(10 variants), implements a respective new *_inside one. Such as the new macro list_for_each_entry_inside for list_for_each_entry. The idea is to be as compatible with the original interface as possible and to minimize code changes. Here are 2 examples: list_for_each_entry_inside: - declare the iterator-variable pos inside the loop. Thus, the origin declare of the inputed *pos* outside the loop should be removed. In other words, the inputed *pos* now is just a string name. - add a new "type" argument as the type of the container struct this is embedded in, and should be inputed when calling the macro. list_for_each_entry_safe_continue_inside: - declare the iterator-variable pos and n inside the loop. Thus, the origin declares of the inputed *pos* and *n* outside the loop should be removed. In other words, the inputed *pos* and *n* now are just string name. - add a new "start" argument as the given iterator to start with and can be used to get the container struct *type*. This should be inputed when calling the macro. Signed-off-by: Xiaomeng Tong Reported-by: kernel test robot --- include/linux/list.h | 156 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index dd6c2041d..1595ce865 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -639,6 +639,19 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = list_next_entry(pos, member)) +/** + * list_for_each_entry_inside + * - iterate over list of given type and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @type: the type of the container struct this is embedded in. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_inside(pos, type, head, member) \ + for (type * pos = list_first_entry(head, type, member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + /** * list_for_each_entry_reverse - iterate backwards over list of given type. * @pos: the type * to use as a loop cursor. @@ -650,6 +663,19 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = list_prev_entry(pos, member)) +/** + * list_for_each_entry_reverse_inside + * - iterate backwards over list of given type and keep iterator inside the loop. + * @pos: the type * to use as a loop cursor. + * @type: the type of the container struct this is embedded in. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_reverse_inside(pos, type, head, member) \ + for (type * pos = list_last_entry(head, type, member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_prev_entry(pos, member)) + /** * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() * @pos: the type * to use as a start point @@ -675,6 +701,22 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = list_next_entry(pos, member)) +/** + * list_for_each_entry_continue_inside + * - continue iteration over list of given type and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue_inside(pos, start, head, member) \ + for (typeof(*start) *pos = list_next_entry(start, member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + /** * list_for_each_entry_continue_reverse - iterate backwards from the given point * @pos: the type * to use as a loop cursor. @@ -689,6 +731,22 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = list_prev_entry(pos, member)) +/** + * list_for_each_entry_continue_reverse_inside + * - iterate backwards from the given point and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse_inside(pos, start, head, member) \ + for (typeof(*start) *pos = list_prev_entry(start, member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_prev_entry(pos, member)) + /** * list_for_each_entry_from - iterate over list of given type from the current point * @pos: the type * to use as a loop cursor. @@ -701,6 +759,20 @@ static inline void list_splice_tail_init(struct list_head *list, for (; !list_entry_is_head(pos, head, member); \ pos = list_next_entry(pos, member)) +/** + * list_for_each_entry_from_inside + * - iterate over list of given type from the current point and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from_inside(pos, start, head, member) \ + for (typeof(*start) *pos = start; !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + /** * list_for_each_entry_from_reverse - iterate backwards over list of given type * from the current point @@ -714,6 +786,21 @@ static inline void list_splice_tail_init(struct list_head *list, for (; !list_entry_is_head(pos, head, member); \ pos = list_prev_entry(pos, member)) +/** + * list_for_each_entry_from_reverse_inside + * - iterate backwards over list of given type from the current point + * and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, continuing from current position. + */ +#define list_for_each_entry_from_reverse_inside(pos, start, head, member) \ + for (typeof(*start) *pos = start; !list_entry_is_head(pos, head, member); \ + pos = list_prev_entry(pos, member)) + /** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry * @pos: the type * to use as a loop cursor. @@ -727,6 +814,22 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/** + * list_for_each_entry_safe_inside + * - iterate over list of given type safe against removal of list entry + * and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @type: the type of the container struct this is embedded in. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_safe_inside(pos, n, type, head, member) \ + for (type * pos = list_first_entry(head, type, member), \ + *n = list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + /** * list_for_each_entry_safe_continue - continue list iteration safe against removal * @pos: the type * to use as a loop cursor. @@ -743,6 +846,24 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/** + * list_for_each_entry_safe_continue_inside + * - continue list iteration safe against removal and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue_inside(pos, n, start, head, member) \ + for (typeof(*start) *pos = list_next_entry(start, member), \ + *n = list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + /** * list_for_each_entry_safe_from - iterate over list from current point safe against removal * @pos: the type * to use as a loop cursor. @@ -758,6 +879,23 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/** + * list_for_each_entry_safe_from_inside + * - iterate over list from current point safe against removal and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @start: the given iterator to start with. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from_inside(pos, n, start, head, member) \ + for (typeof(*start) *pos = start, *n = list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + /** * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal * @pos: the type * to use as a loop cursor. @@ -774,6 +912,24 @@ static inline void list_splice_tail_init(struct list_head *list, !list_entry_is_head(pos, head, member); \ pos = n, n = list_prev_entry(n, member)) +/** + * list_for_each_entry_safe_reverse_insde + * - iterate backwards over list safe against removal and keep iterator inside the loop + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @type: the type of the struct this is enmbeded in. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse_inside(pos, n, type, head, member) \ + for (type * pos = list_last_entry(head, type, member), \ + *n = list_prev_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_prev_entry(n, member)) + /** * list_safe_reset_next - reset a stale list_for_each_entry_safe loop * @pos: the loop cursor used in the list_for_each_entry_safe loop From patchwork Tue Mar 1 07:58:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764276 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6015C433EF for ; Tue, 1 Mar 2022 07:59:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0467E8D0006; Tue, 1 Mar 2022 02:59:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F115E8D0001; Tue, 1 Mar 2022 02:59:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB21C8D0006; Tue, 1 Mar 2022 02:59:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id CB8C28D0001 for ; Tue, 1 Mar 2022 02:59:09 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 82AE98249980 for ; Tue, 1 Mar 2022 07:59:09 +0000 (UTC) X-FDA: 79195066818.22.4D418E2 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf12.hostedemail.com (Postfix) with ESMTP id 16E9D40004 for ; Tue, 1 Mar 2022 07:59:08 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id 139so13794985pge.1 for ; Mon, 28 Feb 2022 23:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QzqMQ7hY2MYfklNGeKF7LFcaPkZedhmqr5FhyMheFwo=; b=gVxF1LdSpG+k8ok8OMNRdDVtLVE/NqVwo2cuhWNRniKttJozJwf5d6VZzH1i92tcfk LjvV2n6up3BQHyac+coxsykXnz5tWVcVghrIO/tq32iI8qFez1io7PrDuupWuIK5szwX qEjlBQh+0f4d0L0OTTiYJtjiL5fRe2VA3Yct7uyzXCmqDfkhSWwiAarqiCN4a3N/VHCX zWewXOlqmVeI74ZEOxGPYEkH6z5Gys0pTYAPlWV7VdU0/ZCr3lP8qsP0igB+sK6iL7i0 GV3sXSENLbKqbl8ye1/LTCIdneSxT7Wqtw/pCXiNbKTPso4aWiY4bMLS4DiiToakIcIN HbIg== 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:in-reply-to :references; bh=QzqMQ7hY2MYfklNGeKF7LFcaPkZedhmqr5FhyMheFwo=; b=F2Fq5pFEKfR+xsE+Ip5zGIEBf3vJ7XXY9S/SLjVlKq/xcKUU/cQuKYsj4WaKJiuxUN 6uiMZIYTWnTOeusivi3RjWmNXhxE1eWui3Pe4cWLAS8w+ZdnZAD0YEZS0rPv0JTIswIr uTUKgja9YnTC/FPVFyNMsieztp+/M4s+3zCKuWFiQmEhmUloFG7Wxfv6U6ltCj7PTtDl cWLUYtYkcAkxQlnnuKav0UxK6Qqk6Sxe7p+rIouqtgQFsMpD9XENYtYkVt+oiM6TIj94 X5hlwxOL2Bk3OhG9inx/TTrUF8Ma3Mk3BlmlGffRdYidfEF9hsTT3pMflU7s1w6FiAfx yr8A== X-Gm-Message-State: AOAM530PJy22Cvw2snlZOce00wsLPIIHwwAreAcnS9SOd7ISS7oAzRUk 62xqnstZoIL821Nge3jVeSs= X-Google-Smtp-Source: ABdhPJyuoS68KxM7xG7Clm6TRMSCvt/W4vvf7HErAeAb32bAA7KFsQ5E8Cn37Dg0u8Z/+37AV7q49Q== X-Received: by 2002:a05:6a00:1312:b0:4e1:58c4:ddfd with SMTP id j18-20020a056a00131200b004e158c4ddfdmr26133089pfu.65.1646121548180; Mon, 28 Feb 2022 23:59:08 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:59:07 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 3/6] kernel: remove iterator use outside the loop Date: Tue, 1 Mar 2022 15:58:36 +0800 Message-Id: <20220301075839.4156-4-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 16E9D40004 X-Stat-Signature: rodz6jt8crny5inq53no911fh7ifhc8g Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gVxF1LdS; spf=pass (imf12.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1646121548-834121 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Demonstrations for: - list_for_each_entry_inside - list_for_each_entry_continue_inside - list_for_each_entry_safe_continue_inside Signed-off-by: Xiaomeng Tong --- kernel/power/snapshot.c | 28 ++++++++++++++++------------ kernel/signal.c | 6 +++--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 330d49937..75958b5fa 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -625,16 +625,18 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask) for_each_populated_zone(zone) { unsigned long zone_start, zone_end; - struct mem_extent *ext, *cur, *aux; + struct mem_extent *me = NULL; zone_start = zone->zone_start_pfn; zone_end = zone_end_pfn(zone); - list_for_each_entry(ext, list, hook) - if (zone_start <= ext->end) + list_for_each_entry_inside(ext, struct mem_extent, list, hook) + if (zone_start <= ext->end) { + me = ext; break; + } - if (&ext->hook == list || zone_end < ext->start) { + if (!me || zone_end < me->start) { /* New extent is necessary */ struct mem_extent *new_ext; @@ -645,23 +647,25 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask) } new_ext->start = zone_start; new_ext->end = zone_end; - list_add_tail(&new_ext->hook, &ext->hook); + if (!me) + list_add_tail(&new_ext->hook, list); + else + list_add_tail(&new_ext->hook, &me->hook); continue; } /* Merge this zone's range of PFNs with the existing one */ - if (zone_start < ext->start) - ext->start = zone_start; - if (zone_end > ext->end) - ext->end = zone_end; + if (zone_start < me->start) + me->start = zone_start; + if (zone_end > me->end) + me->end = zone_end; /* More merging may be possible */ - cur = ext; - list_for_each_entry_safe_continue(cur, aux, list, hook) { + list_for_each_entry_safe_continue_inside(cur, aux, me, list, hook) { if (zone_end < cur->start) break; if (zone_end < cur->end) - ext->end = cur->end; + me->end = cur->end; list_del(&cur->hook); kfree(cur); } diff --git a/kernel/signal.c b/kernel/signal.c index 9b04631ac..da2c20de1 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -711,7 +711,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info) { struct task_struct *tsk = current; struct sigpending *pending = &tsk->pending; - struct sigqueue *q, *sync = NULL; + struct sigqueue *sync = NULL; /* * Might a synchronous signal be in the queue? @@ -722,7 +722,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info) /* * Return the first synchronous signal in the queue. */ - list_for_each_entry(q, &pending->list, list) { + list_for_each_entry_inside(q, struct sigqueue, &pending->list, list) { /* Synchronous signals have a positive si_code */ if ((q->info.si_code > SI_USER) && (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) { @@ -735,7 +735,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info) /* * Check if there is another siginfo for the same signal. */ - list_for_each_entry_continue(q, &pending->list, list) { + list_for_each_entry_continue_inside(q, sync, &pending->list, list) { if (q->info.si_signo == sync->info.si_signo) goto still_pending; } From patchwork Tue Mar 1 07:58:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764277 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F996C433EF for ; Tue, 1 Mar 2022 07:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B42718D0007; Tue, 1 Mar 2022 02:59:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACB5F8D0001; Tue, 1 Mar 2022 02:59:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 946C98D0007; Tue, 1 Mar 2022 02:59:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 85E588D0001 for ; Tue, 1 Mar 2022 02:59:15 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 449FD181CAC52 for ; Tue, 1 Mar 2022 07:59:15 +0000 (UTC) X-FDA: 79195067070.22.5B43AE8 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf12.hostedemail.com (Postfix) with ESMTP id D510540004 for ; Tue, 1 Mar 2022 07:59:14 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id p17so12811177plo.9 for ; Mon, 28 Feb 2022 23:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DH7q20NUg2fMsVec64lFAIumDGct4fZ105Sw3WAxbUA=; b=HLRBF069/um4dwnSHVDbI8dMFG7O4YOwO13iD6T3NtC46gVCf+cqdA32nJr444gw/e ZGXMD/+Sq19GBj7ri2stQfg2YRHBVyL1h3wjdYyUNAQFRvV/NO/yhTObYAjYR6yB4O1P R2gnrnnWh7bFxCGgXzrazITF3jtmnFfFzcl8cTwldg9M0evnPLez8C4LIY0MzmQU5Gr6 WWooK8bKBefjGTEctbNTWyvit1VOWagfNoh+RIOqOTt7wVNiBBvqpSh0+CtHAwc2RXTL eiYUzqx5xKpj02Dnqcwx6p2YICPj+SXQrmhNW655CZVzyEClYIKvi+T8zCIx067+f19l ALgw== 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:in-reply-to :references; bh=DH7q20NUg2fMsVec64lFAIumDGct4fZ105Sw3WAxbUA=; b=z+VGhuTP9eE+HArsb6D8lKTitGrj4bze5v6y1jIlWfCr49PJWPyyRFxXf9AUKKYElo pCJO6oTSfU782HK+Gq7zhisVB+ffxzSpS+OHERCemY3oWOipw6a8qJrXaBjQB0CeMG9n l4Dv30Re81+AiOegVPhbGq3Owwt4hMn8XTBqu5vsI2b/nc1kn/6N7n+6A9U8vbyp4ghh jHwCqkwTNlSjhyUlpTWDf+UuvKdqMZCSmwiM98cRpXnVrWD66OD8dJHnGj/3hctQMSTN EPYZeuygnOj4JVTjK/G/CMkLCaLNgiAgW1UVjSHAL5Q9kHaJ6jrCApRgSSAvVSTCQ3TB wIKw== X-Gm-Message-State: AOAM530OfV97+ZyQp139mM5zf0sycWZFsvqIUxEbHe6aGji3sGZfTYE4 uu1g/y+0GmP4ihNkOoF6EMk= X-Google-Smtp-Source: ABdhPJzfIGUgp26nNkeuQ+F6tXH5OU7cPOWBmYg0OuNdWuCuc04wHa/W/eDEP40nsuuNMSdEw+IExA== X-Received: by 2002:a17:90a:788f:b0:1bd:59c5:748e with SMTP id x15-20020a17090a788f00b001bd59c5748emr7588034pjk.158.1646121554019; Mon, 28 Feb 2022 23:59:14 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:59:13 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 4/6] mm: remove iterator use outside the loop Date: Tue, 1 Mar 2022 15:58:37 +0800 Message-Id: <20220301075839.4156-5-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspamd-Queue-Id: D510540004 X-Stat-Signature: j51pgtajns7x9x94xm49884pm7w591no X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HLRBF069; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646121554-74755 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Demonstrations for: - list_for_each_entry_inside - list_for_each_entry_reverse_inside - list_for_each_entry_safe_inside - list_for_each_entry_from_inside - list_for_each_entry_continue_reverse_inside Signed-off-by: Xiaomeng Tong --- mm/list_lru.c | 10 ++++++---- mm/slab_common.c | 7 ++----- mm/vmalloc.c | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index 0cd5e89ca..d8aab53a7 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -493,20 +493,22 @@ static void memcg_cancel_update_list_lru(struct list_lru *lru, int memcg_update_all_list_lrus(int new_size) { int ret = 0; - struct list_lru *lru; + struct list_lru *ll = NULL; int old_size = memcg_nr_cache_ids; mutex_lock(&list_lrus_mutex); - list_for_each_entry(lru, &memcg_list_lrus, list) { + list_for_each_entry_inside(lru, struct list_lru, &memcg_list_lrus, list) { ret = memcg_update_list_lru(lru, old_size, new_size); - if (ret) + if (ret) { + ll = lru; goto fail; + } } out: mutex_unlock(&list_lrus_mutex); return ret; fail: - list_for_each_entry_continue_reverse(lru, &memcg_list_lrus, list) + list_for_each_entry_continue_reverse_inside(lru, ll, &memcg_list_lrus, list) memcg_cancel_update_list_lru(lru, old_size, new_size); goto out; } diff --git a/mm/slab_common.c b/mm/slab_common.c index 23f2ab071..68a25d385 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -186,8 +186,6 @@ int slab_unmergeable(struct kmem_cache *s) struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, slab_flags_t flags, const char *name, void (*ctor)(void *)) { - struct kmem_cache *s; - if (slab_nomerge) return NULL; @@ -202,7 +200,7 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, if (flags & SLAB_NEVER_MERGE) return NULL; - list_for_each_entry_reverse(s, &slab_caches, list) { + list_for_each_entry_reverse_inside(s, struct kmem_cache, &slab_caches, list) { if (slab_unmergeable(s)) continue; @@ -419,7 +417,6 @@ EXPORT_SYMBOL(kmem_cache_create); static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) { LIST_HEAD(to_destroy); - struct kmem_cache *s, *s2; /* * On destruction, SLAB_TYPESAFE_BY_RCU kmem_caches are put on the @@ -439,7 +436,7 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) rcu_barrier(); - list_for_each_entry_safe(s, s2, &to_destroy, list) { + list_for_each_entry_safe_inside(s, s2, struct kmem_cache, &to_destroy, list) { debugfs_slab_release(s); kfence_shutdown_cache(s); #ifdef SLAB_SUPPORTS_SYSFS diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 4165304d3..65a9f1db7 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3417,14 +3417,14 @@ long vread(char *buf, char *addr, unsigned long count) if ((unsigned long)addr + count <= va->va_start) goto finished; - list_for_each_entry_from(va, &vmap_area_list, list) { + list_for_each_entry_from_inside(iter, va, &vmap_area_list, list) { if (!count) break; - if (!va->vm) + if (!iter->vm) continue; - vm = va->vm; + vm = iter->vm; vaddr = (char *) vm->addr; if (addr >= vaddr + get_vm_area_size(vm)) continue; From patchwork Tue Mar 1 07:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764278 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 063CBC433FE for ; Tue, 1 Mar 2022 07:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BC318D0008; Tue, 1 Mar 2022 02:59:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 944B48D0001; Tue, 1 Mar 2022 02:59:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E7828D0008; Tue, 1 Mar 2022 02:59:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 6FA018D0001 for ; Tue, 1 Mar 2022 02:59:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4535E23D5B for ; Tue, 1 Mar 2022 07:59:21 +0000 (UTC) X-FDA: 79195067322.06.F1019D5 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf24.hostedemail.com (Postfix) with ESMTP id BB7AD180006 for ; Tue, 1 Mar 2022 07:59:20 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id bc27so4880144pgb.4 for ; Mon, 28 Feb 2022 23:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3aKejJw1nR/er0PaT33ysU9JAPbiP/BO+fmavRczddA=; b=MkwrLGU+BDmEg5akmiJV5iuAGXoVQex9eAJamjRI5yPEwQz5ZBphS8rWxnJoh6r2qk GITpdBUCOCJKhpDPKvimmGQSnQYAGyWqE3P/+tlqY8/Lu4X9F1UCmP0Z1BSnNx23hj2H UtRYDHpyz0wyS3HBEihDOvYCmXO68ii5OY2AqwLcziJx5hhINrQq37iUPti6770WqH72 1+XtxGGGSMNbhBmEy4L8XvJ2nezmqom4+TByy//BriSjcIkpn9hXnEZncRbOhKFatyZi G1bY7lVc2k/YjXTfPPTknwvPMtj6AurwobswVDg4xT3ibtE/DX12Ms7BPAu681KRpKyf EYkw== 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:in-reply-to :references; bh=3aKejJw1nR/er0PaT33ysU9JAPbiP/BO+fmavRczddA=; b=puwM8qixXgISY27JleThOyulgkHVC3zSIanWNuLV44WK6ew8yAIz4AlepOYCZS/lN3 gqXaSxJ2oHXh/+R4u4PG/Qo1mLNbiAH53lLaNjCk7Njv/KUKbv33LzUdYgfeY7TUIDtq U6WknY7fHJSMv4yPtqAwMyyHDFA++fK4C798lK6snmL4I8xwLGnwaH6xPKi2ictVaKL1 LK3HkQSHjadG1VLXiye7sQNqEq37OAO3vULtMl+MKi3XVwLET92mPvmH/5f+uIJ0cAvE TvubRXJRTPaeWoc4BXLcYoLDfLYxGxGHAfs6lnChfgEpkqEEKGeo6/JnMex2n88yx7dL vbYQ== X-Gm-Message-State: AOAM530EWefx7vCqd7jak/44B/JUgJL0/gxVzeBokYKDddxu/V90mGel PUtZ9MXkt5fOWP1Wll+rHOs= X-Google-Smtp-Source: ABdhPJzsmChq0SMT6w+a5llB+evOvw/vtlrBOBuie32yTHIMn9w2PHQgwGyq50KU4/df9sG257/q1g== X-Received: by 2002:a05:6a00:124f:b0:4c0:6242:c14e with SMTP id u15-20020a056a00124f00b004c06242c14emr25860679pfi.83.1646121559737; Mon, 28 Feb 2022 23:59:19 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:59:19 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 5/6] net/core: remove iterator use outside the loop Date: Tue, 1 Mar 2022 15:58:38 +0800 Message-Id: <20220301075839.4156-6-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: ynt7tx94rkg39uudiwri4jwqfq89n8xh Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MkwrLGU+; spf=pass (imf24.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: BB7AD180006 X-HE-Tag: 1646121560-968433 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Demonstrations for: - list_for_each_entry_safe_reverse_inside Signed-off-by: Xiaomeng Tong --- net/core/gro.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/gro.c b/net/core/gro.c index a11b286d1..4d4f1f2fb 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -286,9 +286,8 @@ static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index, bool flush_old) { struct list_head *head = &napi->gro_hash[index].list; - struct sk_buff *skb, *p; - list_for_each_entry_safe_reverse(skb, p, head, list) { + list_for_each_entry_safe_reverse_inside(skb, p, struct sk_buff, head, list) { if (flush_old && NAPI_GRO_CB(skb)->age == jiffies) return; skb_list_del_init(skb); From patchwork Tue Mar 1 07:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaomeng Tong X-Patchwork-Id: 12764279 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD23C433FE for ; Tue, 1 Mar 2022 07:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B7138D0009; Tue, 1 Mar 2022 02:59:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23FB48D0001; Tue, 1 Mar 2022 02:59:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E0628D0009; Tue, 1 Mar 2022 02:59:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 005F38D0001 for ; Tue, 1 Mar 2022 02:59:26 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C6BD51496 for ; Tue, 1 Mar 2022 07:59:26 +0000 (UTC) X-FDA: 79195067532.01.C7459AA Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf01.hostedemail.com (Postfix) with ESMTP id 4FB8940004 for ; Tue, 1 Mar 2022 07:59:26 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id 139so13795493pge.1 for ; Mon, 28 Feb 2022 23:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ekN4siAZvBFYd9yFklz7czO7Ig0JL/XxTSkd0vY2Yt8=; b=Kz+4lJxpn6ZgNlG3qZPKUsrxvOx+u6q7ExG1ZalqIm2eoUgzkmKQ18EPS8Y2gJ91ws ok2nLgOjheo5Q+JkSgWrbzHDQpQa5YOuFW3unn1k1/7oZ0HgwPOrZIe2pesso6MHMbRP bZzU3Cz9/18EGeHCFtChKtNwLPgdwcTb5joSEyWFCDalPn4pWeVOSJaVpa2UJWelNXo7 nW275yP5KtdIIFFzENZdI2cq35OKDfDJ47rPXJa5QgRa8MoylJN0zGyv7syuj6ACJMJU wP71gwseBBGoxOdHN/stX4Rz3Pzt08bTEZ5h4DDmVo+SpG06gBNUEOGFabRPha8U2EyC LGvQ== 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:in-reply-to :references; bh=ekN4siAZvBFYd9yFklz7czO7Ig0JL/XxTSkd0vY2Yt8=; b=QYW5/PSQd67xn3foTxls3v/WC8bnY97UyBWTpjfv+D1bM9+1sVbNICpgkLGcLDAteB 9VJksBx/mscZoNd0o8UJC5BLY0fMaxSd34SoSF5ZgCF+yWkJ1f8gPwolxVD2azi3P6WX 8uYs6rnxpQtRaJsNczUsV48/LSjqweUPojwk9+dfFj/EptBj2ekXv8FyRvcP1miinv5S 2HaLWph1TFmM3tmFPviy2Qj0sIKWOHByrrbyFlEvT+lWJZl88TXyiSZ7mhJszxyu00dp v8msaiNt5vDU1r7NGiyBMiOvmp2mitTORW1p7J8haBXbKWqwtp0iqpYw0dwcledHSoLT R1wQ== X-Gm-Message-State: AOAM5322ty8nMvxjeK/d5Z3dBamRGoi36f0xWXtDnu+yxmNca1sRv2Nr 9jjMlu/Ei7J5pamWc6VU+DA= X-Google-Smtp-Source: ABdhPJwXvPb7Q40+8gxqteNpuZwp+PE+h/n6nJyCxWSbGjj0S4pZaxg41DZenCjeRXk3a7weBaal7A== X-Received: by 2002:a65:680a:0:b0:34d:efd6:7a5f with SMTP id l10-20020a65680a000000b0034defd67a5fmr20435429pgt.213.1646121565470; Mon, 28 Feb 2022 23:59:25 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:59:25 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 6/6] drivers/dma: remove iterator use outside the loop Date: Tue, 1 Mar 2022 15:58:39 +0800 Message-Id: <20220301075839.4156-7-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com> References: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4FB8940004 X-Stat-Signature: wg1ci7epfqubcjbcntnd8sqtfoykbdiw Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Kz+4lJxp; spf=pass (imf01.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1646121566-393823 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Demonstrations for: - list_for_each_entry_from_inside - list_for_each_entry_safe_from_inside Signed-off-by: Xiaomeng Tong --- drivers/dma/iop-adma.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/dma/iop-adma.c b/drivers/dma/iop-adma.c index 310b899d5..2f326fb37 100644 --- a/drivers/dma/iop-adma.c +++ b/drivers/dma/iop-adma.c @@ -159,7 +159,6 @@ static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan) /* all the members of a group are complete */ if (slots_per_op != 0 && slot_cnt == 0) { - struct iop_adma_desc_slot *grp_iter, *_grp_iter; int end_of_chain = 0; pr_debug("\tgroup end\n"); @@ -167,9 +166,8 @@ static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan) if (grp_start->xor_check_result) { u32 zero_sum_result = 0; slot_cnt = grp_start->slot_cnt; - grp_iter = grp_start; - list_for_each_entry_from(grp_iter, + list_for_each_entry_from_inside(grp_iter, grp_start, &iop_chan->chain, chain_node) { zero_sum_result |= iop_desc_get_zero_result(grp_iter); @@ -186,9 +184,8 @@ static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan) /* clean up the group */ slot_cnt = grp_start->slot_cnt; - grp_iter = grp_start; - list_for_each_entry_safe_from(grp_iter, _grp_iter, - &iop_chan->chain, chain_node) { + list_for_each_entry_safe_from_inside(grp_iter, _grp_iter, + grp_start, &iop_chan->chain, chain_node) { cookie = iop_adma_run_tx_complete_actions( grp_iter, iop_chan, cookie);