Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754560AbcLRGtY (ORCPT ); Sun, 18 Dec 2016 01:49:24 -0500 Received: from mail-dm3nam03on0078.outbound.protection.outlook.com ([104.47.41.78]:60416 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751004AbcLRGtX (ORCPT ); Sun, 18 Dec 2016 01:49:23 -0500 X-Greylist: delayed 927 seconds by postgrey-1.27 at vger.kernel.org; Sun, 18 Dec 2016 01:49:22 EST From: "Mintz, Yuval" To: Colin King , "netdev@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , "Elior, Ariel" , "Tayar, Tomer" Subject: RE: [PATCH] qed: fix memory leak of a qed_spq_entry on error failure paths Thread-Topic: [PATCH] qed: fix memory leak of a qed_spq_entry on error failure paths Thread-Index: AQHSV5sbDMlnlOq0m0ObrX9PQIi8daENQTig Date: Sun, 18 Dec 2016 06:33:50 +0000 Message-ID: References: <20161216125039.20969-1-colin.king@canonical.com> In-Reply-To: <20161216125039.20969-1-colin.king@canonical.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Yuval.Mintz@cavium.com; x-originating-ip: [31.168.140.228] x-microsoft-exchange-diagnostics: 1;DM2PR0701MB1344;7:h3PO7ee7F+dpbygzav0Da5Aax86pdeHUY5q2F3TAZ8wzFnPTh03Md6fBRpO9Z6P/ncfFQNpBUlPF3wbo4ev8bYed3xjt/VMvhMm0F1gvlibg3KVEyDRAy3P2HHUsjL1aCXtLg03IYs9qROJcfawJlayT/9qacFszryjm4ibldSUVbXGNRlFjlfSX1REUnhOAY+BvZLahszlCesTbR2J2vUGWKUFsBrFiB+mJJ2RzGJOua1EAccw/Bfx0gEnZJzl2IS1pCpUfSqL/YFkGp13nfbsv8RaZ7IFY1k6E/8vxT7iF2Nms6EsauHHxjZ+bCmHczyOe4zGy5Rad0vzWFETOACEHvf5c+iaFUa1kg7Fw+gE+JmlbJCNam1w1AoXTC8/xOBJv+3WBdmAEB14aTzN9hDETsWklKTR0ypZ1MeF5SMkB+x717/dY9gjVUQzUxpQQdL9lS8SMwnQFRqzK0nFo9A== x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(7916002)(39450400003)(199003)(189002)(5001770100001)(229853002)(5660300001)(6436002)(4326007)(107886002)(2906002)(77096006)(99286002)(6506006)(25786008)(2501003)(7736002)(305945005)(6116002)(8936002)(74316002)(102836003)(92566002)(3846002)(97736004)(86362001)(3280700002)(76176999)(50986999)(68736007)(2900100001)(101416001)(7696004)(122556002)(66066001)(54356999)(2950100002)(189998001)(33656002)(81156014)(4001430100002)(38730400001)(8676002)(3660700001)(76576001)(106116001)(9686002)(106356001)(105586002)(81166006);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0701MB1344;H:BL2PR07MB2306.namprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-correlation-id: 183b198a-5067-44a9-26e1-08d4270fd48f x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DM2PR0701MB1344; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148);SRVR:DM2PR0701MB1344;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0701MB1344; x-forefront-prvs: 01604FB62B spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Dec 2016 06:33:50.7434 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0701MB1344 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id uBI6nUZw002788 Content-Length: 666 Lines: 28 > From: Colin Ian King > > A qed_spq_entry entry is allocated by qed_sp_init_request but is not kfree'd > if an error occurs, causing a memory leak. Fix this by kfree'ing it and also > setting *pp_ent to NULL to be safe. > > Found with static analysis by CoverityScan, CIDs 1389468-1389470 > > Signed-off-by: Colin Ian King ... > +err: > + kfree(*pp_ent); > + *pp_ent = NULL; > + > + return rc; > } Hi Colin - thanks for this. It would have been preferable to return the previously allocated spq entry. I.e., do: +err: + qed_spq_return_entry(p_hwfn, *pp_ent); + *pp_ent = NULL; + return rc; Thanks, Yuval