Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1828562ybn; Thu, 26 Sep 2019 02:52:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiM11+h1KnkxbShJCcdp21AhNPLTo7Fh7RtFu9QzlSCSnK7rZZ3wBzuvAbDZR94T6+KN81 X-Received: by 2002:a50:f603:: with SMTP id c3mr2486403edn.208.1569491536196; Thu, 26 Sep 2019 02:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569491536; cv=none; d=google.com; s=arc-20160816; b=vS+cMBervvbn8GOhNDQeac0IbdRKKuokkR8bLTAVkThR0KsDxez/CyGj31WGJnAPQN hO2RYE8dyLoy3ftSqeV0n88xA1CbvO4J5JRX5OaOOsYlxqdRR6neD/n3/Ew3JFjgpUY7 v9LqYcru6ViXKQZXPQfz8f1kGUw6LRcu1/zq2zwfwtRxS66lKgLq0Ycx3vWNRzNzfXk3 vICIyrXjFhfyRKKaFL9SEOBX7N6pROsVH4+BLNkTKH5YSMGl6U0GL/I3Tbi34HoC+Zp3 e5RPt8PPs72GyRH1IV/Ix9Fnk+Uec1pkHev3enxtKoOJj5tMMDxhFj84BEy7SYDcGo0Z iEmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature; bh=6xjol+n/30NhNrorA1nuQM26Ppj6oKqSnjtWLX2XseA=; b=GD5qRnUU1WnReYxt6oINuURWD3teTnNNPiZhIaFWpChuib24Td+UPBbm0CoLVuZC02 /ttpWhAu2SbPrCa63F85+fLpK0FHlUaL/b18wQDjFtFjdJXgz2P9k9fIBwSr4E2xvICG YMAyoTnDt8XOhkpS+1iyVHUjBAwm8zcSclTU8dCtu+Ie7LiyKrrgW/hekBTB1vQBvn9q bFoPc4Jg3U1wy2huNK8M3N52vzJgflxeAatsTiRZLB/igg1ee4klWT7G4xF0T464SXtl SchepNQIyLJnAe7h0X7H2r0yBBGVQurdb4RdRGDjQLAt4g8k99WZiedNutgg8eIf0z5K j4GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CJBIqnUi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si912430ede.131.2019.09.26.02.51.53; Thu, 26 Sep 2019 02:52:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CJBIqnUi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2501938AbfIYSYP (ORCPT + 99 others); Wed, 25 Sep 2019 14:24:15 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:41189 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408520AbfIYSYP (ORCPT ); Wed, 25 Sep 2019 14:24:15 -0400 Received: by mail-io1-f67.google.com with SMTP id r26so1264213ioh.8; Wed, 25 Sep 2019 11:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6xjol+n/30NhNrorA1nuQM26Ppj6oKqSnjtWLX2XseA=; b=CJBIqnUij2EVW5e23A7nSjpCnt1SNL0X/3euzdTJ/z9TUR3gImi+QltSfURY/pxSby Wg7kQV1LnchSeJl2ak/EBCScicYBJB/GnNj+ZOC3TBrs22gzdklX6DICoD3Xg61kD21+ k8cTBNqMRZ+Tzr35lTTsQWK+AaD9GhyIdqUv9n0CDdo2tyjcYg6twfdHWfusvAWeiaC/ TjOaNSmgWaD0zAiYXvdwKeWSc0MfSFlfC73Pmsr0rhX0KRpJgrn//XnSktpTykEXSUry PeMeVKxQskUGP7FZb2+Sd6l4hzusEaXdoG5aKbSLFH7YyLhDKbg2kPWgSiMwyxd1o0at Dn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6xjol+n/30NhNrorA1nuQM26Ppj6oKqSnjtWLX2XseA=; b=mWh41TgoTzIxSmuGQytNyRoOtlmY11GmwHF/kmH05VQauj59zor/fMx+eOBIijYKkE Ts28dEj0kaGINFm8Tda/TIq8WsQWCsTxFfe3o/0LLVIcK4amywcB7IT2+kzDC2p2KSaC mwyVN4tcB7wxtyUuLY52AVhhKGbZaLytk2hleqYxfIQkkPkOX/yzprpMeR6Aavf+KgqN cfPlLuNRgPRzVjl70dCugrHQPOQ/rSb8ZdEJztuim0/W3dzwMiVEu20afygH0vjSj/jY jOqHlMJZjmbi3Kdt0J4GOJOzLx67Q6Hk9bw9f0LlRtM8qwdiYTP5GzkB92nLgGWUWA5u MMLA== X-Gm-Message-State: APjAAAXyRfsDwMKwfcKjk30Ix+N77ABLTomRmNIUJVdVhQTiCQYCYLvy VMQyEffw+vbzpHPIAE1MEF8= X-Received: by 2002:a5d:8911:: with SMTP id b17mr779988ion.287.1569435853982; Wed, 25 Sep 2019 11:24:13 -0700 (PDT) Received: from cs-dulles.cs.umn.edu (cs-dulles.cs.umn.edu. [128.101.35.54]) by smtp.googlemail.com with ESMTPSA id f7sm185591ioj.66.2019.09.25.11.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 11:24:13 -0700 (PDT) From: Navid Emamdoost Cc: emamd001@umn.edu, kjlu@umn.edu, smccaman@umn.edu, Navid Emamdoost , Jakub Kicinski , "David S. Miller" , John Hurley , Simon Horman , Pieter Jansen van Vuuren , Fred Lotter , oss-drivers@netronome.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] nfp: flower: prevent memory leak in nfp_flower_spawn_phy_reprs Date: Wed, 25 Sep 2019 13:24:02 -0500 Message-Id: <20190925182405.31287-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In nfp_flower_spawn_phy_reprs, in the for loop over eth_tbl if any of intermediate allocations or initializations fail memory is leaked. requiered releases are added. Signed-off-by: Navid Emamdoost --- drivers/net/ethernet/netronome/nfp/flower/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c index 7a20447cca19..91a47899220f 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/main.c +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c @@ -515,6 +515,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) repr_priv = kzalloc(sizeof(*repr_priv), GFP_KERNEL); if (!repr_priv) { err = -ENOMEM; + nfp_repr_free(repr); goto err_reprs_clean; } @@ -525,11 +526,13 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, repr); if (IS_ERR(port)) { err = PTR_ERR(port); + kfree(repr_priv); nfp_repr_free(repr); goto err_reprs_clean; } err = nfp_port_init_phy_port(app->pf, app, port, i); if (err) { + kfree(repr_priv); nfp_port_free(port); nfp_repr_free(repr); goto err_reprs_clean; @@ -542,6 +545,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) err = nfp_repr_init(app, repr, cmsg_port_id, port, priv->nn->dp.netdev); if (err) { + kfree(repr_priv); nfp_port_free(port); nfp_repr_free(repr); goto err_reprs_clean; -- 2.17.1