From nobody Fri Dec 19 17:55:51 2025 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 9A574C7EE24 for ; Fri, 2 Jun 2023 11:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235960AbjFBLHu (ORCPT ); Fri, 2 Jun 2023 07:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235857AbjFBLH1 (ORCPT ); Fri, 2 Jun 2023 07:07:27 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF519196 for ; Fri, 2 Jun 2023 04:07:05 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230602110658euoutp01892398afd87e6ae068e43d5aa39bd2db~k0t_siAjl0189801898euoutp01Y for ; Fri, 2 Jun 2023 11:06:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230602110658euoutp01892398afd87e6ae068e43d5aa39bd2db~k0t_siAjl0189801898euoutp01Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1685704018; bh=BhjlbE3l65EDbxXPKpYH+/IItCuSaglkyGpoc2fZJys=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=X0LTpbuqcSvbiXMG8CGVd2hMCiFANmN0MeNr9nHqf5XoJm0XPowTlO9Q39fGZsCww VYNpi/yndgc1369Xeb/TxQjIua+Zz5/gD72Hwb0UpzYmcH3UCVX7WF/P+iAQwScyo5 4hY8AAhHhkMuo17hdYwUhg74s6lqbCIm7csNdLy0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230602110658eucas1p27ccf28cedfee77b724984314dfce3c77~k0t_jdLpI2052120521eucas1p2d; Fri, 2 Jun 2023 11:06:58 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 97.77.11320.25DC9746; Fri, 2 Jun 2023 12:06:58 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230602110658eucas1p27d31eeac2417f9e19f8d4b6de012209b~k0t_KGxtF2052220522eucas1p2z; Fri, 2 Jun 2023 11:06:58 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230602110658eusmtrp19add2e18ca5bb2a26ee0cbd401c5a237~k0t_JjZpq2194821948eusmtrp12; Fri, 2 Jun 2023 11:06:58 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-9a-6479cd527b71 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 51.B9.10549.15DC9746; Fri, 2 Jun 2023 12:06:57 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230602110657eusmtip2922d74715e738263fbe99c2d1cb968c1~k0t9_p76L0244502445eusmtip27; Fri, 2 Jun 2023 11:06:57 +0000 (GMT) Received: from localhost (106.210.248.205) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 2 Jun 2023 12:06:57 +0100 From: Joel Granados To: CC: , , , Joel Granados Subject: [PATCH 8/8] sysctl: replace child with a flags var Date: Fri, 2 Jun 2023 13:06:38 +0200 Message-ID: <20230602110638.789426-9-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230602110638.789426-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [106.210.248.205] X-ClientProxiedBy: CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) To CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBIsWRmVeSWpSXmKPExsWy7djPc7pBZytTDCbdELfYs/cki8XlXXPY LKbfec9mcWPCU0YHFo9NqzrZPD5vkgtgiuKySUnNySxLLdK3S+DKeP5oEnPBUrOKJzevMzcw PtXpYuTkkBAwkbi2+AdzFyMXh5DACkaJ/QvWMEE4XxglDk7pZ4dwPjNKdE6ZwgzTcrxpHQtE YjmjxInFG5ngqn6v64FytjBKvGrbyQLSwiagI3H+zR2wdhEBcYkTpzczghQxC0xglOhb9wus SFjAWqL77xJGEJtFQEXi8rz5bCA2r4CNxI2Dx6F2y0u0XZ8OVsMpYCtx6PQZqBpBiZMzn4DN YQaqad46mxnClpA4+OIFVK+yxIR1v1kh7FqJU1tuMUHYBzgktk8Ph7BdJNb92QxVIyzx6vgW dghbRuL05B6wnyUEJgOD6d8HdghnNaPEssavUJOsJVquPIHqcJTo790FtJkDyOaTuPFWEOIg PolJ26ZDhXklOtqEJjCqzELywiwkL8xC8sICRuZVjOKppcW56anFRnmp5XrFibnFpXnpesn5 uZsYgYnj9L/jX3YwLn/1Ue8QIxMH4yFGCQ5mJRFeobDyFCHelMTKqtSi/Pii0pzU4kOM0hws SuK82rYnk4UE0hNLUrNTUwtSi2CyTBycUg1MOy7cush8WI87YYdC45XLBsV85Z77eOuZlCNF uLJml7nqmdfr/fk8e02/e/LZVKMrV2w4NsXeFl+w3mzb+49S+zlDogUZ68rcFxyZJ5TxxCn7 6ow9VrLFZjK71pz7KKXbuuZ54cWPeRtOa1757bj1b5n/ltlSvvUBxl2u4e9rT0bNa05T6VvB pn0xfKqPimlr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/Drzdqe98sHb5vOxLcLHmfbLr8tcaH/YzSRo+rNondu5p0ZbYLunrd57/pOq9+6qNk fl2VTon8Dc84WWapB86qKZB8uNGwvFzebY7TLY/g4/MqE4qmHPup91QltD4gQomlOCPRUIu5 qDgRABcI0OAzAwAA X-CMS-MailID: 20230602110658eucas1p27d31eeac2417f9e19f8d4b6de012209b X-Msg-Generator: CA X-RootMTR: 20230602110658eucas1p27d31eeac2417f9e19f8d4b6de012209b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230602110658eucas1p27d31eeac2417f9e19f8d4b6de012209b References: <20230602110638.789426-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 effort to remove the empty element at the end of ctl_table structs. "child" was a deprecated elem in this struct and was being used to differentiate between two types of ctl_tables: "normal" and "permanently emtpy". What changed?: * Replace "child" with a u8 "flag" variable and use it to differentiate between types by refactoring the permanently empty helper functions. * Remove the "empty child" check from sysctl_check_table * Remove count_subheaders function as there is no longer a need to calculate how many headers there are for every child * Remove the recursive call to unregister_sysctl_table as there is no need to traverse down the child tree any longer * Add a new SYSCTL_PERM_EMPTY_DIR binary flag * Remove the last remanence of child from partport/procfs.c Signed-off-by: Joel Granados --- drivers/parport/procfs.c | 1 - fs/proc/proc_sysctl.c | 81 +++++++++------------------------------- include/linux/sysctl.h | 4 +- 3 files changed, 20 insertions(+), 66 deletions(-) diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index 0f2d2e1ee28e..4e5b972c3e26 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -387,7 +387,6 @@ parport_device_sysctl_template =3D { .data =3D NULL, .maxlen =3D 0, .mode =3D 0555, - .child =3D NULL }, {} } diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 07804097f997..a180bc952397 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -29,9 +29,8 @@ static const struct file_operations proc_sys_dir_file_ope= rations; static const struct inode_operations proc_sys_dir_operations; =20 /* Support for permanently empty directories */ - struct ctl_table sysctl_mount_point[] =3D { - { } + {.flags =3D SYSCTL_PERM_EMPTY_DIR } }; =20 /** @@ -48,21 +47,14 @@ struct ctl_table_header *register_sysctl_mount_point(co= nst char *path) } EXPORT_SYMBOL(register_sysctl_mount_point); =20 -static bool is_empty_dir(struct ctl_table_header *head) -{ - return head->ctl_table[0].child =3D=3D sysctl_mount_point; -} - -static void set_empty_dir(struct ctl_dir *dir) -{ - dir->header.ctl_table[0].child =3D sysctl_mount_point; -} - -static void clear_empty_dir(struct ctl_dir *dir) - -{ - dir->header.ctl_table[0].child =3D NULL; -} +#define sysctl_is_perm_empty_ctl_table(tptr) \ + (tptr[0].flags & SYSCTL_PERM_EMPTY_DIR) +#define sysctl_is_perm_empty_ctl_header(hptr) \ + (sysctl_is_perm_empty_ctl_table(hptr->ctl_table)) +#define sysctl_set_perm_empty_ctl_header(hptr) \ + (hptr->ctl_table[0].flags |=3D SYSCTL_PERM_EMPTY_DIR) +#define sysctl_clear_perm_empty_ctl_header(hptr) \ + (hptr->ctl_table[0].flags &=3D ~SYSCTL_PERM_EMPTY_DIR) =20 void proc_sys_poll_notify(struct ctl_table_poll *poll) { @@ -230,20 +222,22 @@ static void erase_header(struct ctl_table_header *hea= d) static int insert_header(struct ctl_dir *dir, struct ctl_table_header *hea= der) { struct ctl_table *entry; + struct ctl_table_header *dir_h =3D &dir->header; int err; =20 + /* Is this a permanently empty directory? */ - if (is_empty_dir(&dir->header)) + if (sysctl_is_perm_empty_ctl_header(dir_h)) return -EROFS; =20 /* Am I creating a permanently empty directory? */ - if (header->ctl_table =3D=3D sysctl_mount_point) { + if (sysctl_is_perm_empty_ctl_table(header->ctl_table)) { if (!RB_EMPTY_ROOT(&dir->root)) return -EINVAL; - set_empty_dir(dir); + sysctl_set_perm_empty_ctl_header(dir_h); } =20 - dir->header.nreg++; + dir_h->nreg++; header->parent =3D dir; err =3D insert_links(header); if (err) @@ -259,9 +253,9 @@ static int insert_header(struct ctl_dir *dir, struct ct= l_table_header *header) put_links(header); fail_links: if (header->ctl_table =3D=3D sysctl_mount_point) - clear_empty_dir(dir); + sysctl_clear_perm_empty_ctl_header(dir_h); header->parent =3D NULL; - drop_sysctl_table(&dir->header); + drop_sysctl_table(dir_h); return err; } =20 @@ -479,7 +473,7 @@ static struct inode *proc_sys_make_inode(struct super_b= lock *sb, inode->i_mode |=3D S_IFDIR; inode->i_op =3D &proc_sys_dir_operations; inode->i_fop =3D &proc_sys_dir_file_operations; - if (is_empty_dir(head)) + if (sysctl_is_perm_empty_ctl_header(head)) make_empty_dir_inode(inode); } =20 @@ -1136,9 +1130,6 @@ static int sysctl_check_table(const char *path, struc= t ctl_table *table) struct ctl_table *entry; int err =3D 0; list_for_each_table_entry(entry, table) { - if (entry->child) - err |=3D sysctl_err(path, entry, "Not a file"); - if ((entry->proc_handler =3D=3D proc_dostring) || (entry->proc_handler =3D=3D proc_dobool) || (entry->proc_handler =3D=3D proc_dointvec) || @@ -1465,25 +1456,6 @@ void __init __register_sysctl_init(const char *path,= struct ctl_table *table, kmemleak_not_leak(hdr); } =20 -static int count_subheaders(struct ctl_table *table) -{ - int has_files =3D 0; - int nr_subheaders =3D 0; - struct ctl_table *entry; - - /* special case: no directory and empty directory */ - if (!table || !table->procname) - return 1; - - list_for_each_table_entry(entry, table) { - if (entry->child) - nr_subheaders +=3D count_subheaders(entry->child); - else - has_files =3D 1; - } - return nr_subheaders + has_files; -} - static void put_links(struct ctl_table_header *header) { struct ctl_table_set *root_set =3D &sysctl_table_root.default_set; @@ -1546,28 +1518,11 @@ static void drop_sysctl_table(struct ctl_table_head= er *header) */ void unregister_sysctl_table(struct ctl_table_header * header) { - int nr_subheaders; might_sleep(); =20 if (header =3D=3D NULL) return; =20 - nr_subheaders =3D count_subheaders(header->ctl_table_arg); - if (unlikely(nr_subheaders > 1)) { - struct ctl_table_header **subheaders; - int i; - - subheaders =3D (struct ctl_table_header **)(header + 1); - for (i =3D nr_subheaders -1; i >=3D 0; i--) { - struct ctl_table_header *subh =3D subheaders[i]; - struct ctl_table *table =3D subh->ctl_table_arg; - unregister_sysctl_table(subh); - kfree(table); - } - kfree(header); - return; - } - spin_lock(&sysctl_lock); drop_sysctl_table(header); spin_unlock(&sysctl_lock); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 653b66c762b1..0cd79a7f1d3e 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -137,7 +137,7 @@ struct ctl_table { void *data; int maxlen; umode_t mode; - struct ctl_table *child; /* Deprecated */ + u8 flags; proc_handler *proc_handler; /* Callback for text formatting */ struct ctl_table_poll *poll; void *extra1; @@ -229,7 +229,7 @@ extern int unaligned_enabled; extern int unaligned_dump_stack; extern int no_unaligned_warning; =20 -extern struct ctl_table sysctl_mount_point[]; +#define SYSCTL_PERM_EMPTY_DIR (1 << 0) =20 #else /* CONFIG_SYSCTL */ =20 --=20 2.30.2