Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757332AbcLRPhW (ORCPT ); Sun, 18 Dec 2016 10:37:22 -0500 Received: from shards.monkeyblade.net ([184.105.139.130]:55416 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753059AbcLRPhV (ORCPT ); Sun, 18 Dec 2016 10:37:21 -0500 Date: Sun, 18 Dec 2016 10:37:17 -0500 (EST) Message-Id: <20161218.103717.315074604605472721.davem@davemloft.net> To: Yuval.Mintz@cavium.com Cc: colin.king@canonical.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Ariel.Elior@cavium.com, Tomer.Tayar@cavium.com Subject: Re: [PATCH] qed: fix memory leak of a qed_spq_entry on error failure paths From: David Miller In-Reply-To: References: <20161216125039.20969-1-colin.king@canonical.com> X-Mailer: Mew version 6.7 on Emacs 25.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Sun, 18 Dec 2016 06:38:02 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 831 Lines: 30 From: "Mintz, Yuval" Date: Sun, 18 Dec 2016 06:33:50 +0000 >> 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; Looking at this last night, I came to the same conclusion.