From mboxrd@z Thu Jan 1 00:00:00 1970 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=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS 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 5D42CC43381 for ; Wed, 27 Mar 2019 08:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AFE22075D for ; Wed, 27 Mar 2019 08:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="qzgshniM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726262AbfC0IMQ (ORCPT ); Wed, 27 Mar 2019 04:12:16 -0400 Received: from mail-eopbgr50062.outbound.protection.outlook.com ([40.107.5.62]:27618 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725763AbfC0IMP (ORCPT ); Wed, 27 Mar 2019 04:12:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fCW4PAPKQXo3tRsoUkuXWUs5/MUh5KVYeGTCCES6zSQ=; b=qzgshniMPVuz33u+yJTv5w7sZk8eQikh2nHtK/jB4XyxVcnHjSgrLRfnnSUe69WQNrPOfA1dGnNMDVDrJr4ivAN8SsQ5ps83B/7d73u7zDbrhFEb8vm8eidmgKVMNByijdU3A9nALai7f1ei3p0D1bku4qkwcYgnBy41n5rPopM= Received: from AM0PR05MB6100.eurprd05.prod.outlook.com (20.178.119.209) by AM0PR05MB4337.eurprd05.prod.outlook.com (52.134.93.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.17; Wed, 27 Mar 2019 08:12:12 +0000 Received: from AM0PR05MB6100.eurprd05.prod.outlook.com ([fe80::85ee:723:721e:51f9]) by AM0PR05MB6100.eurprd05.prod.outlook.com ([fe80::85ee:723:721e:51f9%4]) with mapi id 15.20.1730.019; Wed, 27 Mar 2019 08:12:12 +0000 From: Ido Schimmel To: David Ahern CC: "davem@davemloft.net" , "netdev@vger.kernel.org" , Jiri Pirko , Saeed Mahameed , David Ahern Subject: Re: [PATCH net-next 03/13] ipv4: Create init helper for fib_nh Thread-Topic: [PATCH net-next 03/13] ipv4: Create init helper for fib_nh Thread-Index: AQHU5E1aR5x145a1t0G42ggSnUYYNaYfIPGA Date: Wed, 27 Mar 2019 08:12:11 +0000 Message-ID: <20190327081209.GC12504@splinter> References: <20190327032942.20473-1-dsahern@kernel.org> <20190327032942.20473-4-dsahern@kernel.org> In-Reply-To: <20190327032942.20473-4-dsahern@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:20b::16) To AM0PR05MB6100.eurprd05.prod.outlook.com (2603:10a6:208:12e::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=idosch@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f5952392-e7b1-4632-ac99-08d6b28be9f9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM0PR05MB4337; x-ms-traffictypediagnostic: AM0PR05MB4337: x-microsoft-antispam-prvs: x-forefront-prvs: 0989A7979C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(7916004)(346002)(136003)(396003)(366004)(39850400004)(376002)(189003)(199004)(11346002)(478600001)(9686003)(305945005)(6916009)(6436002)(6116002)(7736002)(476003)(3846002)(8676002)(4326008)(54906003)(446003)(76176011)(186003)(2906002)(66066001)(6512007)(33716001)(53936002)(71200400001)(52116002)(71190400001)(68736007)(8936002)(6486002)(99286004)(386003)(102836004)(486006)(5660300002)(14444005)(26005)(14454004)(25786009)(316002)(105586002)(229853002)(81166006)(86362001)(6246003)(106356001)(256004)(1076003)(81156014)(6506007)(33656002)(97736004);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR05MB4337;H:AM0PR05MB6100.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Rr3eyoDi7VXc91iz6VgzmSihChj3As8Q6ceNC/WuGwiGaXuKzaC9s8Wn/Q8yuVYUdQlDiWbet5ZTSw7Vzen7eXiVQvsrYttVO2ttTHtQpAvVC2uUijpUkJCB4b9LuVpY7WFs9RtVJPCT5ZhqlXRc6v+ECHp9cP578banu6GV11G7c1LOEqsbAzL812YP+bW/arBzrae8BuYRRcnis45YA00HimsqBNnHYR33m7lboOMq3+gZeCqFG/gqc1e93H+pPWg8YRb44BD3PoVm8oq42RBSmkFubYKKWQEitvc1Ajf+5n4/kaISd9x/AkvqtxT+ioaF7MyMUC5ywDodiCpNuTTkUGOFe47jn3EVc02tesBLDi3yVPzDR4Ui1LVRDpX5OhVL+OrRlAAQa9jOjC75H8qqVieMziH91DqpNAuJrXE= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5952392-e7b1-4632-ac99-08d6b28be9f9 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2019 08:12:11.8978 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4337 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Mar 26, 2019 at 08:29:32PM -0700, David Ahern wrote: > +int fib_nh_init(struct net *net, struct fib_nh *nh, > + struct fib_config *cfg, int nh_weight, > + struct netlink_ext_ack *extack) > +{ > + int err =3D -ENOMEM; > + > + nh->nh_pcpu_rth_output =3D alloc_percpu(struct rtable __rcu *); > + if (!nh->nh_pcpu_rth_output) > + goto failure; > + > + if (cfg->fc_encap) { > + struct lwtunnel_state *lwtstate; > + > + err =3D -EINVAL; > + if (cfg->fc_encap_type =3D=3D LWTUNNEL_ENCAP_NONE) { > + NL_SET_ERR_MSG(extack, "LWT encap type not specified"); > + goto failure; This is very confusing and probably error-prone. You call alloc_percpu(), but don't free it in the error path and instead rely on the call to free_fib_info() in the error path of fib_create_info(). Better to free it here and NULL-ify the pointer. Then the call to rt_fibinfo_free_cpus() in free_fib_info_rcu() is basically a NOP. > + } > + err =3D lwtunnel_build_state(cfg->fc_encap_type, > + cfg->fc_encap, AF_INET, cfg, > + &lwtstate, extack); > + if (err) > + goto failure; > + > + nh->nh_lwtstate =3D lwtstate_get(lwtstate); > + } > + > + nh->nh_oif =3D cfg->fc_oif; > + nh->nh_gw =3D cfg->fc_gw; > + nh->nh_flags =3D cfg->fc_flags; > + > +#ifdef CONFIG_IP_ROUTE_CLASSID > + nh->nh_tclassid =3D cfg->fc_flow; > + if (nh->nh_tclassid) > + net->ipv4.fib_num_tclassid_users++; > +#endif > +#ifdef CONFIG_IP_ROUTE_MULTIPATH > + nh->nh_weight =3D nh_weight; > +#endif > + err =3D 0; > + > +failure: > + return err; > +}