Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp213069ybk; Thu, 14 May 2020 21:39:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6WbP3/Jo4gX72Kqq1iQFlCCKkMAEjI6e+r3BSaLZtBRDMp2y0BOWfsdThRu8C6F4WUs9I X-Received: by 2002:a50:9e47:: with SMTP id z65mr1179487ede.261.1589517589181; Thu, 14 May 2020 21:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589517589; cv=none; d=google.com; s=arc-20160816; b=OUWPyOz/fQuOEZwNX0Li8/uPTKWFT6zjViEVrsl/NKsBDrdhj11AO2sC8DK5Ncdnyk XvuKx8S/OqvbtkASjQMPL2QvphMMEUU1ZKP6K3LvA15zSwJtLuOA2DyUIR4c6KArj1su SxUkoRpXVovTW7weql28Uj29S34QctudPYVkxFKslUlflWYVTx4RFX+xs9KFr9VpOejp 1GLFrpGJEPDIAd2yAmWo1U/WjVW/gd5BerCMpNGO2KD2qfvnzal/LMSGvRS/5bUbFd1L YvU5lpM392mUj0jTnE0f6jGjqkEqqXo3CzdVlo8CyBawnXA5gpaxWDeWImSK7SVBGRoV hi+g== 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=AOLbXVegWeORFZtq743ml15Yb8Ckaxj4q3eHhLhVT4U=; b=WyKKuCnKYzkXZ4QcDHGbn6/thQ782Jv11ozy5KHdFL5dO78bwR/+vB8HhwK9DzzKoB K6YHv3nkWAjfT52Nhg0wjTXiqsWZiWW9E/Wd0j4K0W5N0pLq1s6URjCI7X61kj7bfLi1 IUNYkKv9x16DCuNcvJEilUiJ0yMiM7oaSh85kVnRkhF/DAAZjSQmE8v6TK/b834xITD4 P5r/Foib73zT9+JlgLMu/L1ka8Tvg+AdtW+kff/GwQZjOeoqFZajke+1PbJv/diMVUBv qHnM7bISi8DsIkXh5D6dpvPEcSwEoyP/WJu+BHOgksK9b7xt9TrMpxWNELQiNq+KvWhX r6wA== 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 y1si546310ejh.219.2020.05.14.21.39.23; Thu, 14 May 2020 21:39:49 -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 S1726643AbgEOEeN (ORCPT + 99 others); Fri, 15 May 2020 00:34:13 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:46384 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725616AbgEOEeI (ORCPT ); Fri, 15 May 2020 00:34:08 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3650B3FC3A5A4A9C49D3; Fri, 15 May 2020 12:33:58 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 15 May 2020 12:33:48 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH 4/4] sysctl: Add register_sysctl_init() interface Date: Fri, 15 May 2020 12:33:44 +0800 Message-ID: <1589517224-123928-5-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1589517224-123928-1-git-send-email-nixiaoming@huawei.com> References: <1589517224-123928-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 --- include/linux/sysctl.h | 2 ++ kernel/hung_task_sysctl.c | 15 +-------------- kernel/sysctl.c | 19 +++++++++++++++++++ kernel/watchdog.c | 18 +----------------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 6d741d6..3cdbe89 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -207,6 +207,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/hung_task_sysctl.c b/kernel/hung_task_sysctl.c index 62a51f5..14d2ed6 100644 --- a/kernel/hung_task_sysctl.c +++ b/kernel/hung_task_sysctl.c @@ -59,21 +59,8 @@ {} }; -/* - * The hung task sysctl has a default value. - * Even if register_sysctl() fails, it does not affect the main function of - * the hung task. At the same time, during the system initialization phase, - * malloc small memory will almost never fail. - * So the return value is ignored here - */ void __init hung_task_sysctl_init(void) { - struct ctl_table_header *srt = register_sysctl("kernel", hung_task_sysctls); - - if (unlikely(!srt)) { - pr_err("%s fail\n", __func__); - return; - } - kmemleak_not_leak(srt); + register_sysctl_init("kernel", hung_task_sysctls, "hung_task_sysctls"); } diff --git a/kernel/sysctl.c b/kernel/sysctl.c index e394990..0a09742 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1823,6 +1823,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 */ /* diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 05e1d58..c1bebb1 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -23,9 +23,6 @@ #include #include #include -#ifdef CONFIG_SYSCTL -#include -#endif #include #include @@ -853,22 +850,9 @@ int proc_watchdog_cpumask(struct ctl_table *table, int write, {} }; -/* - * The watchdog sysctl has a default value. - * Even if register_sysctl() fails, it does not affect the main function of - * the watchdog. At the same time, during the system initialization phase, - * malloc small memory will almost never fail. - * So the return value is ignored here - */ static void __init watchdog_sysctl_init(void) { - struct ctl_table_header *p = register_sysctl("kernel", watchdog_sysctls); - - if (unlikely(!p)) { - pr_err("%s fail\n", __func__); - return; - } - kmemleak_not_leak(p); + register_sysctl_init("kernel", watchdog_sysctls, "watchdog_sysctls"); } #else #define watchdog_sysctl_init() do { } while (0) -- 1.8.5.6