Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C93EC433EF for ; Wed, 15 Jun 2022 06:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352231AbiFOG2q (ORCPT ); Wed, 15 Jun 2022 02:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236311AbiFOG2q (ORCPT ); Wed, 15 Jun 2022 02:28:46 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60BEB36E39; Tue, 14 Jun 2022 23:28:44 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 37FB567373; Wed, 15 Jun 2022 08:28:41 +0200 (CEST) Date: Wed, 15 Jun 2022 08:28:40 +0200 From: Christoph Hellwig To: "Tian, Kevin" Cc: Christoph Hellwig , Kirti Wankhede , Tony Krowiak , Halil Pasic , Jason Herne , Eric Farman , Matthew Rosato , Zhenyu Wang , "Wang, Zhi A" , Alex Williamson , "linux-s390@vger.kernel.org" , "intel-gvt-dev@lists.freedesktop.org" , "kvm@vger.kernel.org" Subject: Re: [PATCH 03/13] vfio/mdev: simplify mdev_type handling Message-ID: <20220615062840.GB22728@lst.de> References: <20220614045428.278494-1-hch@lst.de> <20220614045428.278494-4-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-s390@vger.kernel.org On Tue, Jun 14, 2022 at 10:06:16AM +0000, Tian, Kevin wrote: > > + gvt->mdev_types = kcalloc(num_types, sizeof(*gvt->mdev_types), > > + GFP_KERNEL); > > + if (!gvt->mdev_types) { > > + kfree(gvt->types); > > + return -ENOMEM; > > + } > > + > > min_low = MB_TO_BYTES(32); > > for (i = 0; i < num_types; ++i) { > > if (low_avail / vgpu_types[i].low_mm == 0) > > @@ -150,19 +157,21 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) > > high_avail / > > vgpu_types[i].high_mm); > > there is a memory leak a few lines above: > > if (vgpu_types[i].weight < 1 || > vgpu_types[i].weight > VGPU_MAX_WEIGHT) > return -EINVAL; > > both old code and this patch forgot to free the buffers upon error. Yeah. I'll add a patch to the beginning of the series to fix the existing leak and will then make sure to not leak the new allocation either.