From nobody Tue Feb 10 07:41:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29F79C7EE26 for ; Tue, 23 May 2023 12:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236921AbjEWMXM (ORCPT ); Tue, 23 May 2023 08:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236845AbjEWMWw (ORCPT ); Tue, 23 May 2023 08:22:52 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB33139 for ; Tue, 23 May 2023 05:22:40 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230523122239euoutp018e3c8dff3d017662d1d2ae22e789a22d~hxTNLMiLv1696116961euoutp01n for ; Tue, 23 May 2023 12:22:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230523122239euoutp018e3c8dff3d017662d1d2ae22e789a22d~hxTNLMiLv1696116961euoutp01n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684844559; bh=aJ50gZPCUiYPfATuPiuF3FP7jhiW9EGQQWudnikqczE=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=T6CjuxuOMbY7Jn1B+Hb6y1SeOkP3MP17eYWEVKaYAmV8+noDdpm7a5i5ArPDYbHIW 4Eh3w+0Pxc1y/d5D/zYdHry2bTJIqfg5kqOuLxN2acBT/umQg/gffYukdRPBwRAVoc 3AoLMFYfwG+1F3ymmcckDhGslVDruTOPcuGgJeyY= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230523122239eucas1p190560f3aae58440d1d9c7c647b95a0af~hxTM5Jkkn2688426884eucas1p1P; Tue, 23 May 2023 12:22:39 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id A9.C8.42423.F00BC646; Tue, 23 May 2023 13:22:39 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230523122239eucas1p19c23501df7732d16422ab0489503c764~hxTMkyRy62670226702eucas1p1F; Tue, 23 May 2023 12:22:39 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230523122239eusmtrp24d64abac24d303b57ab36d8049c54933~hxTMkMy7R0682106821eusmtrp2h; Tue, 23 May 2023 12:22:39 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-10-646cb00f5040 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 60.CF.10549.E00BC646; Tue, 23 May 2023 13:22:38 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230523122238eusmtip284f979b57f69c7f863ed642bd93cefbf~hxTMYohQE1858618586eusmtip24; Tue, 23 May 2023 12:22:38 +0000 (GMT) Received: from localhost (106.210.248.82) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 23 May 2023 13:22:38 +0100 From: Joel Granados To: CC: Christian Brauner , Kees Cook , Joel Granados , , , Iurii Zaikin , Alexander Viro , Sudip Mukherjee Subject: [PATCH v4 8/8] sysctl: Remove register_sysctl_table Date: Tue, 23 May 2023 14:22:20 +0200 Message-ID: <20230523122220.1610825-9-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230523122220.1610825-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [106.210.248.82] X-ClientProxiedBy: CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) To CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHKsWRmVeSWpSXmKPExsWy7djP87r8G3JSDNY9ErZ4ffgTo8WZ7lyL PXtPslhc3jWHzeLGhKeMFgdOT2G2OP/3OKvFsp1+DhwesxsusnjsnHWX3WPBplKPTas62Tw+ b5Lz2PTkLVMAWxSXTUpqTmZZapG+XQJXxsa2ZqaCpeYVRw49Ym9gfKnVxcjJISFgIvHy7RW2 LkYuDiGBFYwS+z4eZIFwvjBKTJ3+Ecr5zChx+tpmdpiWs+d/s0MkljNK7Pn/nAmu6tDrxawQ zhZGiek7usBa2AR0JM6/ucMMYosIiEucOL2ZEaSIWWAnk0R/5y02kISwgI3EhEu/mEBsFgFV iXcNf8AaeAVsJXZNm8YGsVteou36dEYQm1PATuLQs32sEDWCEidnPmEBsZmBapq3zmaGsCUk Dr54wQzRqySxuusP1JxaiVNbboGdLSHwg0Pi/vIGFoiEi8T5jr9MELawxKvjW6CelpH4v3M+ VMNkRon9/z6wQzirGSWWNX6F6rCWaLnyBKrDUWL/26lAcQ4gm0/ixltBiIv4JCZtm84MEeaV 6GgTmsCoMgvJD7OQ/DALyQ8LGJlXMYqnlhbnpqcWG+allusVJ+YWl+al6yXn525iBCah0/+O f9rBOPfVR71DjEwcjIcYJTiYlUR4T5RnpwjxpiRWVqUW5ccXleakFh9ilOZgURLn1bY9mSwk kJ5YkpqdmlqQWgSTZeLglGpgyhXs2tH39rRv/7/YN46HAjyOhu5Uvbh282addRcyvnkkTONx eni4uyM7geW5fn7ArDg5z7LNbQlPt+b07/nY93txccQp8y61rVsFBN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z76eHVLsclhCIXXiicfZWnb/b 9z8/ZLF9xZStnX//6i3tfmFV0scg0bN8i2tQV0CWwrm7f/MPFgVvFvTu+bfaIDxf4tKn4lfH 7nLenq11/uBko7k7jK6ZPduzfWXF5YqYzIQfV/US9Y0eOdSX6Jvr6BZN02RXaKqc6/Nn0sv7 PJtfPO2eqPZ+lbX3nz7rfO9PQd9KBObEvZjssOXxJLP68GCx3VM0QubU33nz1eHnzhrp0vqp DLxqx6J2LywU0n/IOfO3z1ODc7cWnJpVp956XGvzluDF05RYijMSDbWYi4oTAXck6/RYAwAA X-CMS-MailID: 20230523122239eucas1p19c23501df7732d16422ab0489503c764 X-Msg-Generator: CA X-RootMTR: 20230523122239eucas1p19c23501df7732d16422ab0489503c764 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230523122239eucas1p19c23501df7732d16422ab0489503c764 References: <20230523122220.1610825-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is part of the general push to deprecate register_sysctl_paths and register_sysctl_table. After removing all the calling functions, we remove both the register_sysctl_table function and the documentation check that appeared in check-sysctl-docs awk script. We save 595 bytes with this change: ./scripts/bloat-o-meter vmlinux.1.refactor-base-paths vmlinux.2.remove-sysc= tl-table add/remove: 2/8 grow/shrink: 1/0 up/down: 1154/-1749 (-595) Function old new delta count_subheaders - 983 +983 unregister_sysctl_table 29 184 +155 __pfx_count_subheaders - 16 +16 __pfx_unregister_sysctl_table.part 16 - -16 __pfx_register_leaf_sysctl_tables.constprop 16 - -16 __pfx_count_subheaders.part 16 - -16 __pfx___register_sysctl_base 16 - -16 unregister_sysctl_table.part 136 - -136 __register_sysctl_base 478 - -478 register_leaf_sysctl_tables.constprop 524 - -524 count_subheaders.part 547 - -547 Total: Before=3D21257652, After=3D21257057, chg -0.00% Signed-off-by: Joel Granados [mcgrof: remove register_leaf_sysctl_tables and append_path too and add bloat-o-meter stats] Signed-off-by: Luis Chamberlain --- fs/proc/proc_sysctl.c | 159 -------------------------------------- scripts/check-sysctl-docs | 10 --- 2 files changed, 169 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index f8f19e000d76..8873812d22f3 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1466,19 +1466,6 @@ void __init __register_sysctl_init(const char *path,= struct ctl_table *table, kmemleak_not_leak(hdr); } =20 -static char *append_path(const char *path, char *pos, const char *name) -{ - int namelen; - namelen =3D strlen(name); - if (((pos - path) + namelen + 2) >=3D PATH_MAX) - return NULL; - memcpy(pos, name, namelen); - pos[namelen] =3D '/'; - pos[namelen + 1] =3D '\0'; - pos +=3D namelen + 1; - return pos; -} - static int count_subheaders(struct ctl_table *table) { int has_files =3D 0; @@ -1498,152 +1485,6 @@ static int count_subheaders(struct ctl_table *table) return nr_subheaders + has_files; } =20 -static int register_leaf_sysctl_tables(const char *path, char *pos, - struct ctl_table_header ***subheader, struct ctl_table_set *set, - struct ctl_table *table) -{ - struct ctl_table *ctl_table_arg =3D NULL; - struct ctl_table *entry, *files; - int nr_files =3D 0; - int nr_dirs =3D 0; - int err =3D -ENOMEM; - - list_for_each_table_entry(entry, table) { - if (entry->child) - nr_dirs++; - else - nr_files++; - } - - files =3D table; - /* If there are mixed files and directories we need a new table */ - if (nr_dirs && nr_files) { - struct ctl_table *new; - files =3D kcalloc(nr_files + 1, sizeof(struct ctl_table), - GFP_KERNEL); - if (!files) - goto out; - - ctl_table_arg =3D files; - new =3D files; - - list_for_each_table_entry(entry, table) { - if (entry->child) - continue; - *new =3D *entry; - new++; - } - } - - /* Register everything except a directory full of subdirectories */ - if (nr_files || !nr_dirs) { - struct ctl_table_header *header; - header =3D __register_sysctl_table(set, path, files); - if (!header) { - kfree(ctl_table_arg); - goto out; - } - - /* Remember if we need to free the file table */ - header->ctl_table_arg =3D ctl_table_arg; - **subheader =3D header; - (*subheader)++; - } - - /* Recurse into the subdirectories. */ - list_for_each_table_entry(entry, table) { - char *child_pos; - - if (!entry->child) - continue; - - err =3D -ENAMETOOLONG; - child_pos =3D append_path(path, pos, entry->procname); - if (!child_pos) - goto out; - - err =3D register_leaf_sysctl_tables(path, child_pos, subheader, - set, entry->child); - pos[0] =3D '\0'; - if (err) - goto out; - } - err =3D 0; -out: - /* On failure our caller will unregister all registered subheaders */ - return err; -} - -/** - * register_sysctl_table - register a sysctl table hierarchy - * @table: the top-level table structure - * - * Register a sysctl table hierarchy. @table should be a filled in ctl_tab= le - * array. A completely 0 filled entry terminates the table. - * We are slowly deprecating this call so avoid its use. - */ -static struct ctl_table_header *register_sysctl_table(struct ctl_table *ta= ble) -{ - struct ctl_table *ctl_table_arg =3D table; - int nr_subheaders =3D count_subheaders(table); - struct ctl_table_header *header =3D NULL, **subheaders, **subheader; - char *new_path, *pos; - - pos =3D new_path =3D kmalloc(PATH_MAX, GFP_KERNEL); - if (!new_path) - return NULL; - - pos[0] =3D '\0'; - while (table->procname && table->child && !table[1].procname) { - pos =3D append_path(new_path, pos, table->procname); - if (!pos) - goto out; - table =3D table->child; - } - if (nr_subheaders =3D=3D 1) { - header =3D __register_sysctl_table(&sysctl_table_root.default_set, new_p= ath, table); - if (header) - header->ctl_table_arg =3D ctl_table_arg; - } else { - header =3D kzalloc(sizeof(*header) + - sizeof(*subheaders)*nr_subheaders, GFP_KERNEL); - if (!header) - goto out; - - subheaders =3D (struct ctl_table_header **) (header + 1); - subheader =3D subheaders; - header->ctl_table_arg =3D ctl_table_arg; - - if (register_leaf_sysctl_tables(new_path, pos, &subheader, - &sysctl_table_root.default_set, table)) - goto err_register_leaves; - } - -out: - kfree(new_path); - return header; - -err_register_leaves: - while (subheader > subheaders) { - struct ctl_table_header *subh =3D *(--subheader); - struct ctl_table *table =3D subh->ctl_table_arg; - unregister_sysctl_table(subh); - kfree(table); - } - kfree(header); - header =3D NULL; - goto out; -} - -int __register_sysctl_base(struct ctl_table *base_table) -{ - struct ctl_table_header *hdr; - - hdr =3D register_sysctl_table(base_table); - kmemleak_not_leak(hdr); - return 0; -} - static void put_links(struct ctl_table_header *header) { struct ctl_table_set *root_set =3D &sysctl_table_root.default_set; diff --git a/scripts/check-sysctl-docs b/scripts/check-sysctl-docs index edc9a629d79e..4f163e0bf6a4 100755 --- a/scripts/check-sysctl-docs +++ b/scripts/check-sysctl-docs @@ -146,16 +146,6 @@ curtable && /\.procname[\t ]*=3D[\t ]*".+"/ { children[curtable][curentry] =3D child } =20 -/register_sysctl_table\(.*\)/ { - match($0, /register_sysctl_table\(([^)]+)\)/, tables) - if (debug) print "Registering table " tables[1] - if (children[tables[1]][table]) { - for (entry in entries[children[tables[1]][table]]) { - printentry(entry) - } - } -} - END { for (entry in documented) { if (!seen[entry]) { --=20 2.30.2