Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1115130pxu; Wed, 6 Jan 2021 12:42:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMCTYcJw4xbvcSnnzW1jp2ooT1vCVHe5UHUwY3+VadgLyQh7NpDMa9tnxPh64rZGb//Vp5 X-Received: by 2002:a05:6402:3c3:: with SMTP id t3mr5282934edw.86.1609965778538; Wed, 06 Jan 2021 12:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609965778; cv=none; d=google.com; s=arc-20160816; b=b7Uonw5SGoz+OoUBuBUjl1LE6m/HnEnydHmAw7ZJTtLPSj/+jsBHwD4lzGkjj5uf0w KF5CFjpZm8dDAhj1QB1C2qvMCNK/mNuAI9LyPhRxq2yBDU8hC7OBt37/j0+OPBUTCQLv TDem0kAxZPyAsmXz3Y8a9w0aoRPdZ4by6YqyHbu1FfwAWqXTDfsU2vBaXWni95mTLiuB RQn8l8oOMgFNsazv62NvPwZuoxVDJQeUArsx7UX2Minl3e+Pm9su2HVRkr1ttro/nIgV +68yAtgOR1t+7UrHoihcAJ5/KoYe7kj3CfEaLQVttVJmVS7c0tyatVe6Lk0nqSgjC1kG lrYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=VeALibfQe4iazgZFIJD/vfdV5BE9bJBaSBq4Sr4e3Ss=; b=zCYrFaOrgDMJZCIVCV2Dn6tqcBT0mdgylI1RGJskLJp/1HtJMfoBH5jFW9VS8WbzYm qLIhhdaH4FWxAwI/JxR59C1S9+lzpFWIO9D0Dsn3VGicfSK4nmglhUM3jhxh9TXmuoiZ qVSIXK+ydSP3N3jY3SydRq0r+0ms9lrTIRbZW0hbInGigvr6rC3xubvIOLv4ZHxFVCuC urM0dfNhTEsbSJcnCJTOJrfvCb77ih1LYmjkF/L7prLQgzffefQfLz8ZPfY1fjuI9Cpz covgThhilmqa61V5nX5CrcwM2bluAvZ/luJVBjwMBMPk4biD1TB/qB+nKvMGkfgYsyAY z+rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=NZDOUYJF; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si1282889edf.22.2021.01.06.12.42.31; Wed, 06 Jan 2021 12:42:58 -0800 (PST) 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; dkim=pass header.i=@pm.me header.s=protonmail header.b=NZDOUYJF; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbhAFUlW (ORCPT + 99 others); Wed, 6 Jan 2021 15:41:22 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:15838 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbhAFUlU (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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 =3D { =09.exit =3D sysctl_net_exit, }; =20 -static struct ctl_table_header *net_header; __init int net_sysctl_init(void) { -=09static struct ctl_table empty[1]; +=09struct ctl_table_header *net_header; +=09struct ctl_table *empty; =09int ret =3D -ENOMEM; + =09/* Avoid limitations in the sysctl implementation by =09 * registering "/proc/sys/net" as an empty directory not in a =09 * network namespace. =09 */ + +=09empty =3D kzalloc(sizeof(*empty), GFP_KERNEL); +=09if (!empty) +=09=09return ret; + =09net_header =3D register_sysctl("net", empty); =09if (!net_header) -=09=09goto out; +=09=09goto err_free; + =09ret =3D register_pernet_subsys(&sysctl_pernet_ops); -=09if (ret) -=09=09goto out1; -out: -=09return ret; -out1: +=09if (!ret) +=09=09return 0; + =09unregister_sysctl_table(net_header); -=09net_header =3D NULL; -=09goto out; +err_free: +=09kfree(empty); + +=09return ret; } =20 struct ctl_table_header *register_net_sysctl(struct net *net, --=20 2.30.0