Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1406122lqj; Mon, 3 Jun 2024 23:41:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXF31sn42lz9yr0vyIuliRysZfzYNoP0KhJ8iycxT8ahvJQ3ZoIQ19atVGl7vQOm6CD9bTrIo6K620cXPZfbQZafu2/Fk18WOtblI6kJQ== X-Google-Smtp-Source: AGHT+IEoXReifO9YBdev20yju8+ZJ+Bd+Bz0jqgAyRAp9qsczNy9I8YB/xte7mo7AdoPmAs0/GNG X-Received: by 2002:a05:6a21:3403:b0:1b2:a899:e577 with SMTP id adf61e73a8af0-1b2a899e612mr959122637.57.1717483316143; Mon, 03 Jun 2024 23:41:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717483316; cv=pass; d=google.com; s=arc-20160816; b=0soTUCAJiwvGX0SbgZfoDuUpjFhbGCDEwpLOYnG36FWhjj2wW2P3ECaomVGT6c6c0e FwKJ9FOw13fw6375bRIPuZtT6z0VMHwLCtCPsIhATz/1iCJ4M4/aJQ0BmCRN+vyvcOwm LpYuPhg1wHSQEfkzGcH3uqgaDb9aiPOr6PXaqct1mc2WU1HZmBP5/N0AAW91ChaXulnS x+ag73O/c6pBCwcKYiLRV3BRtvBw3DmIqh/H/ke+djKfuOLA4/PaRwZUqFWizb7pvHtz EbiS8QMCOg1Hrk9Sk7yprxgiHy579RGezpryycKmVhUX/8KtdxN7+GKTnj7tTaAIlnVc 1DCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=IJzMVukPtS876YYkYzr1cLufRLNFzlqZjVB2lI5Csko=; fh=JVRUZZLuRsJ3MmHwpM7KMtlA/nDFrs/x0P5sZr3L/X0=; b=keoeBIIjAEJt9ExxnpxzCAeDSNk22bhbCy/XQaEL0fhJSHXm34zNgCjJc6uMq9WDFX mIm9vQQUudlr8sNgLv02VmXzhatI2Gyczt24iJ69k4kUvw/bHr8E2Ai4+8SzmTR3DcTy PslugV/NRdHgRZ5CAHEsf3geLn3CBYE5cDw/5Y45xv/rhEDg/5aKNUkr8H961691Ix0Z F0YbmWVmGxXn8+lgLbV02lqHsRwaGP4t6+pZdhpheAp3BiBMBhRPcllMery8usBvAj5g lC4xVkZ1Di5AbuWnsdJZ8jnxE8sLvFYkoPOEHXoeN+r7LWNLAEDWNjnHIEeoy41iOXIi aU9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pA4dmeog; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200107-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200107-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-7026a8e6ba6si3439883b3a.313.2024.06.03.23.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 23:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200107-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pA4dmeog; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200107-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200107-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E703028D524 for ; Tue, 4 Jun 2024 06:32:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ADD7143743; Tue, 4 Jun 2024 06:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pA4dmeog" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EBB513F00B; Tue, 4 Jun 2024 06:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717482600; cv=none; b=CranHYsDU7Sku8pVk/5hUb91u6a38bu6UymyQLIeMDtBoJmG4kmxmHxtvQGROzV6Vd0S7H4nrDbozMJKGfQC1J7Suj9ZZYse0UkLgCO/qA527ytsiFjp/8q2V+oNeyM1OrSygK1XmdkupKeDLVR2MBajr7jlOFIDdxEHrRdpq2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717482600; c=relaxed/simple; bh=SiVUhtxONKQWX+BBZwI127KwpXG2Q3vZOfxEJQppcWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aTPjr08EU30OsYxEJaA8/kBvA7qYA24drM+cYqyagj+qklaIHwd7ASDWYTFwcK+xQUSnzuRMx1rSjg8JeksyIh7ev3hEmBjTdhpbZHIewkcxHFjd4r1HfEIrquA0BR99bDmZRfnqbejGoaJwR/t3aZ1+9i4LZL9u2dHB5D9V8iY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pA4dmeog; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id AEBC7C4AF09; Tue, 4 Jun 2024 06:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717482599; bh=SiVUhtxONKQWX+BBZwI127KwpXG2Q3vZOfxEJQppcWk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pA4dmeogTARSZfUZ/Gh9KHrzmf7wDP8GqwUGhu5YY1UfYSpIYx7Ne3usxtGqOwF2J mA5x5+xvD0pZwhihYG1Ufi1aaFA8o2vmdw121w6VUTnpX7cM1CcG8/w9hdles60tLI 5sNqVzC6xqZol58Rt0b4wJcCTQLTqh5WaMaM1gJt8R8rFyUCTLy2e78mU5MjXxt9xv 3+j9/MOmODLqmTStj6lUdjNt3QeZfewviDek6mipvnJGN1KTs8WIU/WH4EyjcrQx5i x+Sbm2GdzftBbBsodZq+OgHOAWOsgB5lDdMspCkESqr7WUTz24atJeZbtBMslDcz/A Xah1DKevIQW2w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0F52C27C55; Tue, 4 Jun 2024 06:29:59 +0000 (UTC) From: Joel Granados via B4 Relay Date: Tue, 04 Jun 2024 08:29:21 +0200 Subject: [PATCH 3/8] sysctl: Remove check for sentinel element in ctl_table arrays Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240604-jag-sysctl_remset-v1-3-2df7ecdba0bd@samsung.com> References: <20240604-jag-sysctl_remset-v1-0-2df7ecdba0bd@samsung.com> In-Reply-To: <20240604-jag-sysctl_remset-v1-0-2df7ecdba0bd@samsung.com> To: Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Suren Baghdasaryan , Kent Overstreet , Andrew Morton , Luis Chamberlain , Kees Cook , Joel Granados , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2348; i=j.granados@samsung.com; h=from:subject:message-id; bh=mD4Ze/7MDPElpYuv5XGK8tVRov3P49zLBw+A3YRwezE=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZetGMc5UA19wZYyokNq00ONpu/iFrRM3b3d ji21KMQyCufh4kBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmXrRjAAoJELqXzVK3 lkFPjSkL/jbkTtKEHy2F4Zoay4bUyht8qYvmVrqYV35vhM08LmptpbTf9aDW49d1wvwom8i7zTo +bkTEJ+q5fEM8JibuQ4wBCwuyN55TQaiyynC6+P1sISJFiR+wNNKUkzoJZJuds9xIN3VHDBujmF hNT6GLin8xncVd6bXgjH1ukPvQamXDCmxcTzZ2ES5fPV4d063gEAAo0nfHkZRnPYcBfiPAf6E0W 6G/lTK5uCzNa1ienyagjyYa/UhAA/5IR33bkyguc9SGsBIZ5T33xBdFUHEfNS3GwclPA2Yt2jZ1 LYUI6YkfSftzj365NjA/UIsfGOdho/i4+CyV68VYXCQ0uQqSokz3ckRi9m/9JJOmT+qgzaSJbad kdWkSUcfn0vkojZPlpE8X3ed9U671GRAu0H/6f3Mv1yLfMoZEfspW68GFf+XV2mwWYYfmJl8rny mq0grO/Kf0H96o3+fcySffKJnyun8yE/Sil4YyRoh2AS4mwi23lOtffZxZJuyJcUTavw5iP4Pw6 PI= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados Use ARRAY_SIZE exclusively by removing the check to ->procname in the stopping criteria of the loops traversing ctl_table arrays. This commit finalizes the removal of the sentinel elements at the end of ctl_table arrays which reduces the build time size and run time memory bloat by ~64 bytes per sentinel (further information Link : https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/) Remove the entry->procname evaluation from the for loop stopping criteria in sysctl and sysctl_net. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 2 +- net/sysctl_net.c | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index b1c2c0b82116..d4ba7ad9dbe0 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -21,7 +21,7 @@ #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++) + for (size_t i = 0 ; i < header->ctl_table_size; ++i, entry++) static const struct dentry_operations proc_sys_dentry_operations; static const struct file_operations proc_sys_file_operations; diff --git a/net/sysctl_net.c b/net/sysctl_net.c index f5017012a049..19e8048241ba 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -127,7 +127,7 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path, pr_debug("Registering net sysctl (net %p): %s\n", net, path); ent = table; - for (size_t i = 0; i < table_size && ent->procname; ent++, i++) { + for (size_t i = 0; i < table_size; ent++, i++) { unsigned long addr; const char *where; @@ -165,17 +165,10 @@ struct ctl_table_header *register_net_sysctl_sz(struct net *net, struct ctl_table *table, size_t table_size) { - int count; - struct ctl_table *entry; - if (!net_eq(net, &init_net)) ensure_safe_net_sysctl(net, path, table, table_size); - entry = table; - for (count = 0 ; count < table_size && entry->procname; entry++, count++) - ; - - return __register_sysctl_table(&net->sysctls, path, table, count); + return __register_sysctl_table(&net->sysctls, path, table, table_size); } EXPORT_SYMBOL_GPL(register_net_sysctl_sz); -- 2.43.0