From patchwork Wed Aug 9 10:49:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 133164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2741198vqr; Wed, 9 Aug 2023 04:51:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGA7WH1mbfsS2+03Rn7Hq7pqDcDyGTgaG0/0/9SLAX1ovj/5YMltXOkPp65rBV/8POufVzp X-Received: by 2002:a17:907:86a8:b0:98d:f2c9:a1eb with SMTP id qa40-20020a17090786a800b0098df2c9a1ebmr1549099ejc.24.1691581883644; Wed, 09 Aug 2023 04:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691581883; cv=none; d=google.com; s=arc-20160816; b=fSvykRXQoke4K7RoKwV80dymeWOqFeZDFZCRSk8Iz5PTFRsNdwZpFUvCsLLGWR/2Fe pMtKRnTmeiZf7KTzcOLymKWHSlinVMJ/G7nCl3IGbdjqR3zazvuqdDbBjkrMzEkHNpXi /Frm4dipy4cNinmJUAqSdfXBxP2M/nyr8IZgZv5FtRJfcp6GvXVFCnw+uUqbzx0IaUV/ BUY03xeW1qdaRASC0j7WpwwZrwEs8HhSivII9tSQBpxc33YFZwJKgjxrirnNkaDGTDWF yVe/hwyIncex8qH8y8dYxBDbwIvqfS8m8npcohz0O1E8d/3qhyZJddv0NBz5XTDpndQ8 8mZg== 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=9/+5UTOZSoINBQX5Idlq9s7Q/YjlqMmFruSJ92+I5og=; fh=vrJVathPeHoK961IEaGeDqkbez4IR8NxkZspkqdeRJ4=; b=0/ETdDMxIb7UW28Mbh1JSXdYG1zDmDOS1J+a7xvhSipQ6g5Oi5+c1sDns0HfpemCaB 9Wky2kUKrSSnsvIMb8PX/GaXhe0LN26nl9Mv7377gmoqvzZdBqYwA/8q5NE4QpIdMnUk ByKSnKZ/A8Xi7iZQs01sVvvo/33pVx660iVaGtKpEX4EB8J1ttzTt70HlvADMZ42v0Ku 9CHRcFJiE6P96LartFSG9nsNq/ULV3cj3Fcyahu0fHsJXVRLyo931eB9MQ5O+lGIZcEi yG+7AbtYgtH/KbhcxNLx7M10Ql0l5iv4nHnjSkr+L4KBNQi4zG/aPrSzGxXqBHVXOGf2 tgPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=atb4R9D3; 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 s2-20020aa7cb02000000b0051dd30da018si8444626edt.611.2023.08.09.04.50.59; Wed, 09 Aug 2023 04:51:23 -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=atb4R9D3; 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 S232355AbjHIKua (ORCPT + 99 others); Wed, 9 Aug 2023 06:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232314AbjHIKuN (ORCPT ); Wed, 9 Aug 2023 06:50:13 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3DE01702; Wed, 9 Aug 2023 03:50:11 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-313e742a787so447411f8f.1; Wed, 09 Aug 2023 03:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691578210; x=1692183010; 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=9/+5UTOZSoINBQX5Idlq9s7Q/YjlqMmFruSJ92+I5og=; b=atb4R9D3UP8rF8J4DGImLYCkkIjCylHcvHBJaEULX5niQjnDlzqKMSD5b4XFz4ZLJm sSVslKOliNw8ZHFha9Q562wOwmSVoMuXD4Jzi45CYhNUVyBhkrybtxsTzBbaNvkF6YdB 3Ip1yQFeNZNWV136v1J6u6djXhWlqXLYc4pygA1zQYzZSG7N5rFZfAdvnT5RaC4IdpX8 Hhp/XGgonRRh1UB5bBOZOcE3bm9Hw+tW0izfNszwTTx12H0BeD1gHzEhTaTGaK1+Je54 ZTIaLIKV/p9CynDWkY98/7O5UGX5w209N20Q+KQeJkXFPaMRlFgR87Pko35IDChhUfFg iO/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691578210; x=1692183010; 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=9/+5UTOZSoINBQX5Idlq9s7Q/YjlqMmFruSJ92+I5og=; b=h7l/ha86PFGgbj4Hn6j0HklHmXyVGIbJ2PolhzUwmNSabt8K1oyorRJsyddO3HwAUB bBune5pVHoikwLB/VTwQhV6wJaweU5hR8cIAwEyQH75bHJPAhhieUtppssehwTel0uqN VYmq6syElrwiTJvSgYxptaMUzI12UnsAYnK6teWpxPZimES27sTBYGPG4kto1GHR8e87 Tm2iWHH7/n4DhlVamlf365s1XYyEfoG1oLU/7j1nIDJk588kRNxFthoNnxcHNnBmNFvh 2IGzNoSOqm3viy/kl7a+9Raub3LHlzk72nl1Jd+FMk7ePioAuye/DTjGe6JNa0brIgVY TN9A== X-Gm-Message-State: AOJu0Yw60irY1DGYepSvPAUGtAVghyBHoqI4U3fOF5QsHu4njq+kL3lw I6yIt35BcCvDEiZo/IXBGQyeaUgwarsvygwX X-Received: by 2002:adf:f1cc:0:b0:314:475:bc6b with SMTP id z12-20020adff1cc000000b003140475bc6bmr2059281wro.18.1691578210251; Wed, 09 Aug 2023 03:50:10 -0700 (PDT) Received: from localhost ([165.225.194.193]) by smtp.gmail.com with ESMTPSA id z14-20020adfe54e000000b00317e9f8f194sm9272438wrm.34.2023.08.09.03.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 03:50:09 -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 Subject: [PATCH v3 01/14] sysctl: Prefer ctl_table_header in proc_sysctl Date: Wed, 9 Aug 2023 12:49:53 +0200 Message-Id: <20230809105006.1198165-2-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_NONE,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: 1773752165113511168 X-GMAIL-MSGID: 1773752165113511168 This is a preparation commit that replaces ctl_table with ctl_table_header as the pointer that is passed around in proc_sysctl.c. This will become necessary in subsequent commits when the size of the ctl_table array can no longer be calculated by searching for an empty sentinel (last empty ctl_table element) but will be carried along inside the ctl_table_header struct. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5ea42653126e..94d71446da39 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table) return err; } -static int sysctl_check_table(const char *path, struct ctl_table *table) +static int sysctl_check_table(const char *path, struct ctl_table_header *header) { struct ctl_table *entry; int err = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { if ((entry->proc_handler == proc_dostring) || (entry->proc_handler == proc_dobool) || (entry->proc_handler == proc_dointvec) || @@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table) return err; } -static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table, - struct ctl_table_root *link_root) +static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head) { struct ctl_table *link_table, *entry, *link; struct ctl_table_header *links; @@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table name_bytes = 0; nr_entries = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { nr_entries++; name_bytes += strlen(entry->procname) + 1; } @@ -1189,12 +1188,12 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table link_name = (char *)&link_table[nr_entries + 1]; link = link_table; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { int len = strlen(entry->procname) + 1; memcpy(link_name, entry->procname, len); link->procname = link_name; link->mode = S_IFLNK|S_IRWXUGO; - link->data = link_root; + link->data = head->root; link_name += len; link++; } @@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table } static bool get_links(struct ctl_dir *dir, - struct ctl_table *table, struct ctl_table_root *link_root) + struct ctl_table_header *header, + struct ctl_table_root *link_root) { - struct ctl_table_header *head; + struct ctl_table_header *tmp_head; struct ctl_table *entry, *link; /* Are there links available for every entry in table? */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); + link = find_entry(&tmp_head, dir, procname, strlen(procname)); if (!link) return false; if (S_ISDIR(link->mode) && S_ISDIR(entry->mode)) @@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir, } /* The checks passed. Increase the registration count on the links */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); - head->nreg++; + link = find_entry(&tmp_head, dir, procname, strlen(procname)); + tmp_head->nreg++; } return true; } @@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head) if (IS_ERR(core_parent)) return 0; - if (get_links(core_parent, head->ctl_table, head->root)) + if (get_links(core_parent, head, head->root)) return 0; core_parent->header.nreg++; spin_unlock(&sysctl_lock); - links = new_links(core_parent, head->ctl_table, head->root); + links = new_links(core_parent, head); spin_lock(&sysctl_lock); err = -ENOMEM; @@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head) goto out; err = 0; - if (get_links(core_parent, head->ctl_table, head->root)) { + if (get_links(core_parent, head, head->root)) { kfree(links); goto out; } @@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table( node = (struct ctl_node *)(header + 1); init_header(header, root, set, node, table); - if (sysctl_check_table(path, table)) + if (sysctl_check_table(path, header)) goto fail; spin_lock(&sysctl_lock);