Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2422894ybk; Sun, 17 May 2020 21:25:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvH/V+cUb19nbPAFMOUzzvXIvSXvl/VvLZHKouGze54DBuM59eU3Pr4+4+oY7BiVOT83Dm X-Received: by 2002:aa7:d612:: with SMTP id c18mr6411389edr.282.1589775902909; Sun, 17 May 2020 21:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589775902; cv=none; d=google.com; s=arc-20160816; b=vtFaPB6W4hwfy0Jgnk7QRoGFvZh9H96tRk48fioVwiJ4Xsr24zRV9y3Iz+z+TRhOMN TQDrytpAXVp0aJxzabLTH8pFHtkhEMeqvh7cnhXpJ6Za69Fu7WDVuQjbIRqUo2e/0oAa +PasiRUt7nVPHHFeyqN6EQYu8w2gPM3MKKvnVYpxk1s6n0JzB18iz+QsclatoH3bluA1 AX5LSY63uRc2MkECi9wUxOnAb6812k2s6+rRsfocmJ5xWnLctwYw+XPGyDjaRGAbXhye 37mbtEIckBz4XCsT6a3iElHusX+WqlX7bdM3fl9si6svf2TJe7XB31OXjbawbd7ejCWB 1hvg== 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=XEkx3WAd2Nkif3MlzPvZDmbGrgxZn96g4HhXkPTYVP0=; b=axcO19T5tV5qjn7ovD7JGitFkx6vJHTx4hFL5vCLCKEsWIxxmvVbqR/OIOQjG2fyYh P+kAPN7GD4RvTCG7qvoLNqsyeFp4VjZF+GDdNiGmNzje845xXgnpanW/vzGSNN+PFJKV ea3z9stLVLKHPXv8JHMGbpb7v5sulkEE2VSIkomO8mFjXigg/U+WiEyK2N7TbZv0mR4V OSf/hFqK4rf2fM7n9O0+wmeAQ6YDp/2/ct8Dm9WLXdMqv96utVISG+uJclZ7AHWfpfQd Gv03oZy+iZ2EhKelb8fn7YkDZogEo+LqmbWmPmAHv5FBZPMEtQS3pQIAAsPV96JGncbv qlhA== 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 z5si5736500edi.111.2020.05.17.21.24.40; Sun, 17 May 2020 21:25:02 -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 S1726443AbgEREAP (ORCPT + 99 others); Mon, 18 May 2020 00:00:15 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:58024 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726127AbgEREAM (ORCPT ); Mon, 18 May 2020 00:00:12 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6E54E5E5E0121A94F1E0; Mon, 18 May 2020 12:00:09 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Mon, 18 May 2020 11:59:59 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , , , CC: , , Subject: [PATCH v3 1/4] sysctl: Add register_sysctl_init() interface Date: Mon, 18 May 2020 11:59:54 +0800 Message-ID: <1589774397-42485-2-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1589774397-42485-1-git-send-email-nixiaoming@huawei.com> References: <1589774397-42485-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 02fa844..43f8ef9 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -206,6 +206,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); extern struct ctl_table sysctl_mount_point[]; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8a176d8..c96122f 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1968,6 +1968,25 @@ int __init sysctl_init(void) 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 */ /* -- 1.8.5.6