Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1130626ybk; Sat, 16 May 2020 01:57:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM3/xrQp3VGEaieQuZuFiDvqK/yLpM7IH8AxrwO5wgooCdmEaraU9yQBVFDZFlo6eAXUNK X-Received: by 2002:a17:906:bce3:: with SMTP id op3mr6681355ejb.230.1589619471007; Sat, 16 May 2020 01:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589619471; cv=none; d=google.com; s=arc-20160816; b=hfWSE8Vw9IApWTJMaX18xzRAjHZHKsdtRZiwcNrdyDwYmXIza6fRK2BsdkM4Y7GxQo xI/x0LZk/L3h+Vs82dC0mfPDCZX1/X6xReiWA4xBvNkFOjvcPjPNw1S8Jcb6fZCb9tDX Dr/Eb9/SzQmDh7m+PYcqE9+WmJGRODvRlcPAbLpvoKXo1/GzuCBHQfr0Xe8Za1Qk+PV5 DE6siFDY8OQeH1k6HYTtyKDYPKD3sFXuuIR4gB5CPyndrorDpQK7cIoHenpNtMnxUeAe A/oxQ/82TYcVgCFYK3iQnaoXFIStdkJ5sqJvIhoMSU0U95mZIKccCftShAkLhEQFCuQy GQXQ== 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=JGM5s7YGoSRdPG9i5XOJAAYJZEx49ahyQcFjTEULfc0=; b=Xn1ceWEIxcWXpTG2hActMVDcPxHSFSQALDnbGJcy3il/yGGvnNdQoqRnREaBXuYViG UvGSp6hlOPfX0wjHPOv9AZ8LSruGIh86GwLxHcHre0WgV1jGZF8pU45Ei2WJfyxSHykN 76/dcr7AVk1SL2Pw++5VjX2mFjXGBX/7Ru21ramukkqO+LQUaevSGyFMgsvrreBmrbst 3AEBDocxomoflq5O4xPDnK0G3bHZROAvt4yxnsUs2mUnGIA2l9smqYZU384Ido1hQLGz BqxSD7vkdFZl39IWqkSzbWFsYoY5/tDjtkUn8Hpks2fn2R33f1Ib0x0m2keuOeof010A UJfQ== 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 p23si3120906ejb.217.2020.05.16.01.57.27; Sat, 16 May 2020 01:57:50 -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 S1726993AbgEPIzf (ORCPT + 99 others); Sat, 16 May 2020 04:55:35 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:50420 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726899AbgEPIze (ORCPT ); Sat, 16 May 2020 04:55:34 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 702BF66F73B25B48AE89; Sat, 16 May 2020 16:55:25 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Sat, 16 May 2020 16:55:18 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , CC: , , , Subject: [PATCH v2 1/4] sysctl: Add register_sysctl_init() interface Date: Sat, 16 May 2020 16:55:12 +0800 Message-ID: <1589619315-65827-2-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1589619315-65827-1-git-send-email-nixiaoming@huawei.com> References: <1589619315-65827-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/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 b9ff323..20c31f5 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1970,6 +1970,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