Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3176425ybk; Mon, 18 May 2020 20:34:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjFHyPQSyPsn3X1bMv+yYfkUzlQRnQUGvGDXNOet1qgUbyvKx4EosLcqfZMm1wc6umOqq7 X-Received: by 2002:a05:6402:17a3:: with SMTP id j3mr17164026edy.137.1589859287071; Mon, 18 May 2020 20:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589859287; cv=none; d=google.com; s=arc-20160816; b=FG4MYhe0jAzS47nfKIwebPFSK5TZ64rJOO/1P5pDr1YHjf2xBkyHnkGkXOJ6IV4oUt lENBC8pyYai7Hq8X9ZYJYFCt8s1dc3Cet8JnH65CkzgosR0MWnw9SDcdSe9ltDao2U+A jleT81R59+R0Xk2VjzNI3PDK358iyt+qk8Vo6xsw0ewk7yzJBJsuDomeR+41vzdxlqtg OHLZMuQD87kE4bNVLGLc+FgyqZ6MIPEEg9+N5ukqvnfZfsaeoqPLjrRkfd6+kj+J8K88 rwJ8xsEo08ra8Df05tyQfkK61kUh55m6gIm5aCHWqeOmv5AbehiipP/TKvHIbPJHNeBC 0koA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=LvbD3EpaGNefO6QEion8/qLlDmjlmcZOjAmZ/NVErN4=; b=f39FmaqskJ30csmFTUJ74GbQgZnJBIhLKSe8djKdsKuzE8rlFdfIwzFptulgKfbLPy 3V6HUCIP6VYBSsEU7yff9/aMaC9/R3nNyftYYeRMJRD6jgX8lVlslk/L7yCx9cHtK+2Y 7ClHe5puP0z9e6hkDnVjXmK0zJB4YT8LWObo21KmGsAtUOhVywDe4hEdy2oiMu6hzfEz F/nk9+lHi3yLNYY017OH9u9b66sbZ1/2f/kvy4NnlbiONux8O2SHN8qZfx6MumLJ5wSv lwa64mAH5LiZ0ZjbemoR81Xb08IxnQUujaLLDWbmXj6HWvhzfcLP3AQXyOWqxT8I8Y+O 0cag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds8si5216267ejc.350.2020.05.18.20.34.24; Mon, 18 May 2020 20:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728198AbgESDbV (ORCPT + 99 others); Mon, 18 May 2020 23:31:21 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4859 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726302AbgESDbV (ORCPT ); Mon, 18 May 2020 23:31:21 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CA27B95C87A6593A342B; Tue, 19 May 2020 11:31:19 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 19 May 2020 11:31:13 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , , , , , , , , , , CC: , Subject: [PATCH v4 1/4] sysctl: Add register_sysctl_init() interface Date: Tue, 19 May 2020 11:31:08 +0800 Message-ID: <1589859071-25898-2-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1589859071-25898-1-git-send-email-nixiaoming@huawei.com> References: <1589859071-25898-1-git-send-email-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to eliminate the duplicate code for registering the sysctl interface during the initialization of each feature, add the register_sysctl_init() interface Signed-off-by: Xiaoming Ni Reviewed-by: Kees Cook --- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 50bb7f3..857ba93 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -197,6 +197,8 @@ struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init(void); +extern void register_sysctl_init(const char *path, struct ctl_table *table, + const char *table_name); void do_sysctl_args(void); extern int pwrsw_enabled; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index cc1fcba..8afd713 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -3358,6 +3358,25 @@ int __init sysctl_init(void) kmemleak_not_leak(hdr); return 0; } + +/* + * The sysctl interface is used to modify the interface value, + * but the feature interface has default values. Even if register_sysctl fails, + * the feature body function can also run. At the same time, malloc small + * fragment of memory during the system initialization phase, almost does + * not fail. Therefore, the function return is designed as void + */ +void __init register_sysctl_init(const char *path, struct ctl_table *table, + const char *table_name) +{ + struct ctl_table_header *hdr = register_sysctl(path, table); + + if (unlikely(!hdr)) { + pr_err("failed when register_sysctl %s to %s\n", table_name, path); + return; + } + kmemleak_not_leak(hdr); +} #endif /* CONFIG_SYSCTL */ /* * No sense putting this after each symbol definition, twice, -- 1.8.5.6