Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4091273rwb; Mon, 31 Jul 2023 00:43:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlFqUvOFpnnyiMh9PiQD6IQt2OGdiZy9ighcM68rdqi5ZgP6uJ1XiAHGKcGYMKwi2Z/gR5C5 X-Received: by 2002:a17:902:c20d:b0:1b5:edd:e3c7 with SMTP id 13-20020a170902c20d00b001b50edde3c7mr8668715pll.16.1690789421287; Mon, 31 Jul 2023 00:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690789421; cv=none; d=google.com; s=arc-20160816; b=dQvt9dsBZVDf7vuMYJVa2pQPkQV3Kn9BUl0+7MaDHnPplm/p66qPp8pwUXRp3oOZj2 2/FYeVGFIU8I2dz4ttcyTLmK5//QB7sAUsloCpiX0gtuFD67xx4JdKXDT3PUCll9dvzL Nq8iEVpBWrz/NPKTrSw4F8htjASosGAcVPSUxUf34IbcpiPLUw0xQ9LSoOJu35obaTPW L2O/kQDkeKi0KJCATxESYy3X+6vqGQqPtPjfx4rpb3O8XAclmueyudg56yAuPKf7/9MF iCFsm1BtiHtvv/xOwpRq8FR2ja/++JtqcWGuQeA1CDab2aw8PmnVvR67j/EcyMyizOX0 dULQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q2sRNbI2azaNM3epQYqeDbNNvVsnx+uOoBBxcjhRKfE=; fh=aHwFfzDw3PoKbpABTZNa0bc0ZPEBsjzm+AcFcKu2OWY=; b=k6k+IuZgoi0K3LyQj2iVxSPDR+at5Z0O3OyWmS76jeVZYq/OqSR7KyF5T+2+XZe9Ys R67Wm2xKMeVg4N+dblAHuoQDBaOGaJ9wjchYP8g3jiIa1iUoIpSet/v7Wmi5oUcMjwmJ YujLTAq0MhQ9RbxtWv0+uR9we9oSi6USYD1Z5l86zg/m3DlBFH5J9nZOxZZzTzpWdOdJ b0B52FQtaxeX535X0Ty2o7AZzyxZt1UEAgOC/TzCWUpiTMaPVx3YSn4rpvwzuOUesue5 osQ9WBLOsDGVwoTLQ7elQssT6nXa1WYvm5RJ0gu7vgmjm9wnOM7h0quDQDGS5crwra+c fsrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=FX60aiiY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ke14-20020a170903340e00b001b89654fa42si6717659plb.476.2023.07.31.00.43.28; Mon, 31 Jul 2023 00:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=FX60aiiY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229469AbjGaHVE (ORCPT + 99 others); Mon, 31 Jul 2023 03:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbjGaHT3 (ORCPT ); Mon, 31 Jul 2023 03:19:29 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2455B2D67; Mon, 31 Jul 2023 00:17:59 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbab0d0b88so35766965e9.0; Mon, 31 Jul 2023 00:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690787878; x=1691392678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q2sRNbI2azaNM3epQYqeDbNNvVsnx+uOoBBxcjhRKfE=; b=FX60aiiY2KctEUh+j9yuK0cGnmKW2WpFZ3k1hVMZjIYTseBraxngepIWNvfcXGsPq1 7xSVdY+8zc9yIZ57nKdT+hlUE0Ql178jQsRiH723XYn4HhHTr/pv49QmaTcNQ2XsUNAi PWzt+UqFr/sg0NpYqkGyiJNK7oFd9qBYvtgDfg+keM7SyoPlJi+mcwnnV0qqy8UUXXH+ yEQM7BNRR98OhKiErQTxzAomz+aqzdV0nWU9PRrMuhWCCwSQ75cIObdPL85tLs8lZ4Tp 84iwFiXBPFqH6x90lqRFXFaxycKbeNqBugndgd7V/GFzGnSbrjoxW1nQKlMiaVkRQI3W 1DjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690787878; x=1691392678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q2sRNbI2azaNM3epQYqeDbNNvVsnx+uOoBBxcjhRKfE=; b=HDJUJ5lI3B1ru52ZusBW9FM5UVqAa9eE897G41o42Kj+842Ju+/VQsPjvDRaaBnJGg /QyGOcdSqOx5ToD0N5XIPsMA/RPaKy3DAeVpMHuUCnZcnZau+6QkVicej0ibzOwUHAWu ccOUR8EwLFd31gX9z3FhJ3jpiEVonnaCt/R+TnEL9b7wK0jWvbBLze3I2RUuWwYXPfXl T6YlMDQTBo89L5tKZNkTQ3rVnhGCSy7nwLnP01mXyoTF+QRiGCDQA2Fapih3WAE61p56 zjyFwMmgMr7+mppwL/b7vLQcKxXZ+m88Bt5GQWo51Ilpg3VoUffASjtGalUD0wk0EIxZ H49A== X-Gm-Message-State: ABy/qLZ0ZGwTE3qVopxwcKG79bf4z4ejDBFk6F+jj/rr6EWIdHBUnwzF GdDYN3kC0MnYld2z/7ID8N8= X-Received: by 2002:a5d:60c1:0:b0:313:e88d:e6d3 with SMTP id x1-20020a5d60c1000000b00313e88de6d3mr10154506wrt.14.1690787877583; Mon, 31 Jul 2023 00:17:57 -0700 (PDT) Received: from localhost ([165.225.194.214]) by smtp.gmail.com with ESMTPSA id k1-20020adff5c1000000b00313de682eb3sm12164837wrp.65.2023.07.31.00.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 00:17:57 -0700 (PDT) From: Joel Granados X-Google-Original-From: Joel Granados To: mcgrof@kernel.org Cc: Catalin Marinas , Iurii Zaikin , Jozsef Kadlecsik , Sven Schnelle , Marcelo Ricardo Leitner , Steffen Klassert , Kees Cook , "D. Wythe" , mptcp@lists.linux.dev, Jakub Kicinski , Vasily Gorbik , Paolo Abeni , coreteam@netfilter.org, Jan Karcher , Alexander Aring , Will Deacon , Stefan Schmidt , Matthieu Baerts , bridge@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Joerg Reuter , Julian Anastasov , David Ahern , netfilter-devel@vger.kernel.org, Wen Gu , linux-kernel@vger.kernel.org, Santosh Shilimkar , linux-wpan@vger.kernel.org, lvs-devel@vger.kernel.org, Karsten Graul , Miquel Raynal , Herbert Xu , linux-sctp@vger.kernel.org, Tony Lu , Pablo Neira Ayuso , Ralf Baechle , Florian Westphal , willy@infradead.org, Heiko Carstens , "David S. Miller" , linux-rdma@vger.kernel.org, Roopa Prabhu , Alexander Gordeev , Simon Horman , Mat Martineau , josh@joshtriplett.org, Christian Borntraeger , Eric Dumazet , linux-hams@vger.kernel.org, Wenjia Zhang , linux-fsdevel@vger.kernel.org, linux-s390@vger.kernel.org, Xin Long , Nikolay Aleksandrov , netdev@vger.kernel.org, rds-devel@oss.oracle.com, Joel Granados , Jani Nikula Subject: [PATCH v2 14/14] sysctl: Use ctl_table_size as stopping criteria for list macro Date: Mon, 31 Jul 2023 09:17:28 +0200 Message-Id: <20230731071728.3493794-15-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230731071728.3493794-1-j.granados@samsung.com> References: <20230731071728.3493794-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparation commit to make it easy to remove the sentinel elements (empty end markers) from the ctl_table arrays. It both allows the systematic removal of the sentinels and adds the ctl_table_size variable to the stopping criteria of the list_for_each_table_entry macro that traverses all ctl_table arrays. Once all the sentinels are removed by subsequent commits, ctl_table_size will become the only stopping criteria in the macro. We don't actually remove any elements in this commit, but it sets things up to for the removal process to take place. By adding header->ctl_table_size as an additional stopping criteria for the list_for_each_table_entry macro, it will execute until it finds an "empty" ->procname or until the size runs out. Therefore if a ctl_table array with a sentinel is passed its size will be too big (by one element) but it will stop on the sentinel. On the other hand, if the ctl_table array without a sentinel is passed its size will be just write and there will be no need for a sentinel. Signed-off-by: Joel Granados Suggested-by: Jani Nikula --- fs/proc/proc_sysctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 817bc51c58d8..504e847c2a3a 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -19,8 +19,9 @@ #include #include "internal.h" -#define list_for_each_table_entry(entry, header) \ - for ((entry) = (header->ctl_table); (entry)->procname; (entry)++) +#define list_for_each_table_entry(entry, header) \ + entry = header->ctl_table; \ + for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++) static const struct dentry_operations proc_sys_dentry_operations; static const struct file_operations proc_sys_file_operations; -- 2.30.2