From patchwork Wed Aug 9 10:49:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 133226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2787488vqr; Wed, 9 Aug 2023 06:08:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbRlWJ3+DIjHVU3nMqGVlEHURqYw1e6V2X7rEHQxJtkaIzBbfcMtgT3/HLpPCa4xwxBl8H X-Received: by 2002:a05:6a20:320d:b0:13f:aa86:804d with SMTP id hl13-20020a056a20320d00b0013faa86804dmr2598643pzc.35.1691586484797; Wed, 09 Aug 2023 06:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691586484; cv=none; d=google.com; s=arc-20160816; b=ENKUtM6fEJ+4mbd6dxzY7zesSmYAqb4S8dV5okWWFmlIAjCzi1tWS72ZSqKJlFLjFE OqZhnW1mJ1w6xdmDNz44rrsYl5HnDoypPK8mDJB3mQXgfVRu0AMsQ4KBiZRfjgAfrsyf DiXWBNxVEgbxUWzX0Xn57yLb53ecmn9G5KrLUifkCK3+8uLLtHyTdxa3h0Kt6mCzQxOU 2JuZX4uJk4aQGeDLO35kmU2jy3BJLzzgQzlF5YA6J/SH6rpnUJs5vBxqC8p3zk/pgD1b UOJR/V2QtisBMCz5P8YyZytjbLD430bcXri2qDduRFNu9uF3H3pg5d2eCRHOZ5UCpEXT yT1A== 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=GPr2gCh0WwKGZ3vD5F3mcw/cD05Ywt0Q6uWcdKx3iw8=; fh=yJYy1gNyqt+ZQdQgHW0QnMhG/WDC5gaPesekaVcjNqQ=; b=DL49tMLyEG3Lh0/1v2HROXItb+Tdl3GdQSM4o/Y9lEchCuq90B4PhyQks/TT488/KQ 8SqsNwuXyd6z40EST7+BKfzT3lHuUA4Dt6kQQqKpIRu0v+Fg8EHmUJJ3iw0+W1zqflzo 5v4DaINEAWzt/KbIVWpONejye92tt0c78FWj2nwJAePzMGZVc3YGuhQG3cKYWnN4Ve2J Z2KZj3gavMScfG2fNM0mTjX/cMwu9neOiCZR26uyCRk9NfBAT0vAOUcgHalsdl4FsNDd 4K9HXZNi9UeLRiXXtxX4uFiP+tSE2N6haTxDvU24lSDndN9Ac7dHLm1bTaM7EIohv53p sEsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Ft/M2URZ"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a056a0010c800b006683174a49csi9293418pfu.198.2023.08.09.06.07.50; Wed, 09 Aug 2023 06:08:04 -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="Ft/M2URZ"; 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 S232450AbjHIKui (ORCPT + 99 others); Wed, 9 Aug 2023 06:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232366AbjHIKua (ORCPT ); Wed, 9 Aug 2023 06:50:30 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62D8F2112; Wed, 9 Aug 2023 03:50:24 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fe501e0b4cso32566865e9.1; Wed, 09 Aug 2023 03:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691578223; x=1692183023; 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=GPr2gCh0WwKGZ3vD5F3mcw/cD05Ywt0Q6uWcdKx3iw8=; b=Ft/M2URZH4F9TYPvggTbYZI70JB09nVLQPW/chdRXAcUsPbgMM66BJGWbrvIr6sO0X /S1TV4QPNbJFtFWfbKqENSXb1SethxNaapV5Pr8Ze1daK4ea3ZcsvWqsx6Vnz7IBJnzE FdNnYJXXgiy2FH6o6wTg9TMCwioyKds6hC/uwclYhE2GOfuqjgoWkCOi5J6sN9bV+/gy G6tD94G1bDRfAU+yXLWVNCuxp01jDE/qrztCqh1bCblexqARHilBR3HAnOhA4fi95YzO +pADPslmnto3C6CoQWlLSrLP2ArR3ZG5Xi4wyj1x7sMmkwf8IvwppLpZc2/6sbJImYmW kj3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691578223; x=1692183023; 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=GPr2gCh0WwKGZ3vD5F3mcw/cD05Ywt0Q6uWcdKx3iw8=; b=AJIaOQM8giw6Voj1+cJgJxejYB/ZsBhi0pRXKQHpZ2UCU0D0whTfmmuwE4G0wlFWy5 e1E2Km6A4sDQmO1EZEGWnd7Hokp1+S0FXV+yUKV5mspmq+QmRQTHI5Ka81ihtSffN/+C xDmWHyC12jlsrhWR5tuyteY9S74gp5r85URtyMgI6DQjMQczidY9nfog4uadCp1hOAbd gHK1ImJF4/QZi4pa8fm6T7D0BcFji2zm35HpwS1rpnk3iSYAue+95WtYZRQq7g/mK7M8 8LbjiUBbH8FWhxG5pViSotKYbjwbvepjVsPRLmvxil64YuCqKejKrGo9PrfsJ1864qOD pWCg== X-Gm-Message-State: AOJu0YxMf3P3yQ7W6hBd2IpMe0fwRlBF9L++4ZZYeINWouZtbIXxLsJq pYAmdBYAhLIVvkh3FUGGhMHa3kahd1lseQwA X-Received: by 2002:a05:600c:3641:b0:3fe:26bf:6605 with SMTP id y1-20020a05600c364100b003fe26bf6605mr1630731wmq.26.1691578222558; Wed, 09 Aug 2023 03:50:22 -0700 (PDT) Received: from localhost ([165.225.194.193]) by smtp.gmail.com with ESMTPSA id m8-20020a7bca48000000b003fa96fe2bd9sm1645531wml.22.2023.08.09.03.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 03:50:22 -0700 (PDT) From: Joel Granados X-Google-Original-From: Joel Granados To: mcgrof@kernel.org Cc: rds-devel@oss.oracle.com, "David S. Miller" , Florian Westphal , willy@infradead.org, Jan Karcher , Wen Gu , Simon Horman , Tony Lu , linux-wpan@vger.kernel.org, Matthieu Baerts , Christian Borntraeger , mptcp@lists.linux.dev, Heiko Carstens , Stefan Schmidt , Will Deacon , Julian Anastasov , netfilter-devel@vger.kernel.org, Joerg Reuter , linux-kernel@vger.kernel.org, Alexander Gordeev , linux-sctp@vger.kernel.org, Xin Long , Herbert Xu , linux-hams@vger.kernel.org, Vasily Gorbik , coreteam@netfilter.org, Ralf Baechle , Steffen Klassert , Pablo Neira Ayuso , keescook@chromium.org, Roopa Prabhu , David Ahern , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Jozsef Kadlecsik , Wenjia Zhang , josh@joshtriplett.org, linux-fsdevel@vger.kernel.org, Alexander Aring , Nikolay Aleksandrov , netdev@vger.kernel.org, Santosh Shilimkar , linux-s390@vger.kernel.org, Sven Schnelle , "D. Wythe" , Eric Dumazet , lvs-devel@vger.kernel.org, linux-rdma@vger.kernel.org, Paolo Abeni , Iurii Zaikin , Marcelo Ricardo Leitner , bridge@lists.linux-foundation.org, Karsten Graul , Mat Martineau , Miquel Raynal , Jakub Kicinski , Joel Granados , Greg Kroah-Hartman Subject: [PATCH v3 07/14] sysctl: Add size arg to __register_sysctl_init Date: Wed, 9 Aug 2023 12:49:59 +0200 Message-Id: <20230809105006.1198165-8-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230809105006.1198165-1-j.granados@samsung.com> References: <20230809105006.1198165-1-j.granados@samsung.com> MIME-Version: 1.0 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_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773756989834841978 X-GMAIL-MSGID: 1773756989834841978 This commit adds table_size to __register_sysctl_init in preparation for the removal of the sentinel elements in the ctl_table arrays (last empty markers). And though we do *not* remove any sentinels in this commit, we set things up by calculating the ctl_table array size with ARRAY_SIZE. We add a table_size argument to __register_sysctl_init and modify the register_sysctl_init macro to calculate the array size with ARRAY_SIZE. The original callers do not need to be updated as they will go through the new macro. Signed-off-by: Joel Granados Suggested-by: Greg Kroah-Hartman --- fs/proc/proc_sysctl.c | 12 +++--------- include/linux/sysctl.h | 5 +++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 80d3e2f61947..817bc51c58d8 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1433,6 +1433,7 @@ EXPORT_SYMBOL(register_sysctl_sz); * lifetime use of the sysctl. * @table_name: The name of sysctl table, only used for log printing when * registration fails + * @table_size: The number of elements in table * * The sysctl interface is used by userspace to query or modify at runtime * a predefined value set on a variable. These variables however have default @@ -1445,16 +1446,9 @@ EXPORT_SYMBOL(register_sysctl_sz); * Context: if your base directory does not exist it will be created for you. */ void __init __register_sysctl_init(const char *path, struct ctl_table *table, - const char *table_name) + const char *table_name, size_t table_size) { - int count = 0; - struct ctl_table *entry; - struct ctl_table_header t_hdr, *hdr; - - t_hdr.ctl_table = table; - list_for_each_table_entry(entry, (&t_hdr)) - count++; - hdr = register_sysctl_sz(path, table, count); + struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size); if (unlikely(!hdr)) { pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index b1168ae281c9..09d7429d67c0 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -236,8 +236,9 @@ void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init_bases(void); extern void __register_sysctl_init(const char *path, struct ctl_table *table, - const char *table_name); -#define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table) + const char *table_name, size_t table_size); +#define register_sysctl_init(path, table) \ + __register_sysctl_init(path, table, #table, ARRAY_SIZE(table)) extern struct ctl_table_header *register_sysctl_mount_point(const char *path); void do_sysctl_args(void);