From patchwork Wed Jan 6 20:40:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 357994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5814CC433E0 for ; Wed, 6 Jan 2021 20:41:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2776B23133 for ; Wed, 6 Jan 2021 20:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727655AbhAFUlV (ORCPT ); Wed, 6 Jan 2021 15:41:21 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:31570 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbhAFUlU (ORCPT ); Wed, 6 Jan 2021 15:41:20 -0500 Date: Wed, 06 Jan 2021 20:40:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1609965638; bh=VeALibfQe4iazgZFIJD/vfdV5BE9bJBaSBq4Sr4e3Ss=; h=Date:To:From:Cc:Reply-To:Subject:From; b=NZDOUYJFmgCYadtfcfwenuX+FyotOLU7RXjXD7lCNsEilqrCWaGBL2HlF2Tz8V6Fo GKi+nVoQ+pmGnJcRcdnRcawVZlzJTecaJWD4fj31o1BKfymN/Zsm3z/F6WHMHjoSpb XFlZF2fvpmnjei6G0CSMUsCe6ZlIydaITvVSg9lChWxZCZ5+t+wy+YLHVXTprefgF6 d2ydKsQMpesC77Z5k7SfAmpKY7eBik7jQXaCyBruiL/LFE4wbtYvK1uU+qcSXBErC2 DlbPpAoek0MH2jNaF86lBXcUxUz+Zr2K4pOch9VsN6drXVAWwXU6JN+OgCDxl61Thq M8XBUHEgrlgRA== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Alexander Lobakin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH net-next] net: sysctl: cleanup net_sysctl_init() Message-ID: <20210106204014.34730-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 'net_header' is not used outside of this function, so can be moved from BSS onto the stack. Declarations of one-element arrays are discouraged, and there's no need to store 'empty' in BSS. Simply allocate it from heap at init. Signed-off-by: Alexander Lobakin --- net/sysctl_net.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/net/sysctl_net.c b/net/sysctl_net.c index d14dab8b6774..4cf81800a907 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -92,27 +92,34 @@ static struct pernet_operations sysctl_pernet_ops = { .exit = sysctl_net_exit, }; -static struct ctl_table_header *net_header; __init int net_sysctl_init(void) { - static struct ctl_table empty[1]; + struct ctl_table_header *net_header; + struct ctl_table *empty; int ret = -ENOMEM; + /* Avoid limitations in the sysctl implementation by * registering "/proc/sys/net" as an empty directory not in a * network namespace. */ + + empty = kzalloc(sizeof(*empty), GFP_KERNEL); + if (!empty) + return ret; + net_header = register_sysctl("net", empty); if (!net_header) - goto out; + goto err_free; + ret = register_pernet_subsys(&sysctl_pernet_ops); - if (ret) - goto out1; -out: - return ret; -out1: + if (!ret) + return 0; + unregister_sysctl_table(net_header); - net_header = NULL; - goto out; +err_free: + kfree(empty); + + return ret; } struct ctl_table_header *register_net_sysctl(struct net *net,