Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp420260rdh; Thu, 23 Nov 2023 07:29:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWwqeFdpKoQ8nh6tOaYLsXgwpfc2r12Yr16CI+QPM4R+5xgqxdqMc83wD1CCnhXnPadkaf X-Received: by 2002:a05:6a21:3288:b0:187:67b0:73e with SMTP id yt8-20020a056a21328800b0018767b0073emr5959944pzb.14.1700753352507; Thu, 23 Nov 2023 07:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700753352; cv=none; d=google.com; s=arc-20160816; b=Ic/kNcetsEL6YZ+bjkn7XKOFhmLuOO1/XAu61Lq3jg3DdpDsSFAAgoaBpDTOQi7Dx5 tQp/bdWcjyAiiTUqiowgj8Wd9fyHgDFbT9A4iZCDxJO6PgUFEvH/3NTXB0Z5chp2To5E yIuesIRYNj2cumi1OMTE8OV98zKziFxPhGtwWt2cih2Babuh7fERXWW1a31R/fWE3h7S H7jma9GAN1Ihkn3FW5QTBHp1lpELwd4VOmhdJilnrhUBXYr/G92giketMj8STN0qmxPa L+4BIDKecVbFdhr0wMCllrgRF7kQ5YSGHmySHNIByZ2guPmbbuJkgshdGnxpGmLm2uZN FBFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=lxBpRwynrPKcBHLlElP6fRAprhdNCbSw2dwaa2dsqk8=; fh=mOqrdtzLxfRdhx+JUcCLIFZwj5ZpRA4B+MTwRGfrWMA=; b=BRn95o/CqftjmQf3xYKevZHhTkgouELxFCCgHwk1v/1q6YEsFPs7punIVxG8ZiOLV8 fiM/zBZHHq8DiTx+rujZhbr9cpfBuUN7fk0AVK247sZGBRIu2gr+XSl8X/HM9s/00SLE ApjZcXSmBGAL6i7Iw+x0a58K2vyVzKreU/aj0IFn9aSPs94dRQsbTcgb/k2ieXcaWi5o tEUHdcWgcC3DikjzcPrQ6/ldpEWA00Mf3gKTFRjUefse3LVcc95CM2IfNXFTzxJuP11L XtPpFZyAjI1PV3gy/vRDIWnr4bFHwYRN92lTsoIa3uaZalO+PGzHbvePCdKXEOQu3DQ8 AmqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KzFaMzY2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id g9-20020a632009000000b005c203ad0e2csi1473526pgg.827.2023.11.23.07.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 07:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KzFaMzY2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4EB7C81EEBFA; Thu, 23 Nov 2023 07:29:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346231AbjKWP2w (ORCPT + 99 others); Thu, 23 Nov 2023 10:28:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346232AbjKWP2Z (ORCPT ); Thu, 23 Nov 2023 10:28:25 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4006A10F5; Thu, 23 Nov 2023 07:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700753248; x=1732289248; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=l8dcelsKzETRTjIVJYVStptG7enmi7tz5AG7PIw2WtA=; b=KzFaMzY2sBJrcLJ6vPpB07e/ShcnrV6X9ki6Vn12/cmivsiFOS8x/t6j ZkEOzoCtdtLm2kmvQbpBf9+HYHp89AKZwPQeOP3E+VkPoAQzv+21dspa/ DjDVV316no8xrU+jJ+PB9VhjzoNDadgT9w/PUOBpEn0I3FzPOoMqFDhgE EcNumEp6eIIXGLAv8ojQ+YQqRYv2Y1gB5ZPJo6FnfwPX2NbSF9NIyf7fc GkjNl6agZzLlP9RmfrOpSQ3CfXGqFrJh3JmrTp5zVUirx1CsyGfrKcVfb k/lMJ+1aVMe75MKuM9+35Ybku4JzvzhiF+OYaz+gE//D40X95N8fwdtLv g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="396190659" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="396190659" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 07:27:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="15376681" Received: from mstrobel-mobl.ger.corp.intel.com ([10.252.40.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 07:27:26 -0800 Date: Thu, 23 Nov 2023 17:27:23 +0200 (EET) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: "David E. Box" cc: LKML , platform-driver-x86@vger.kernel.org, rajvi.jingar@linux.intel.com Subject: Re: [PATCH V5 01/20] platform/x86/intel/vsec: Fix xa_alloc memory leak In-Reply-To: <20231123040355.82139-2-david.e.box@linux.intel.com> Message-ID: <52a6e750-71ed-b1d5-8693-2759be4cd6e5@linux.intel.com> References: <20231123040355.82139-1-david.e.box@linux.intel.com> <20231123040355.82139-2-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 07:29:10 -0800 (PST) On Wed, 22 Nov 2023, David E. Box wrote: > Fixes memory leak, caught be kmemleak, due to failure to erase auxiliary > device entries from an xarray on removal. > > Signed-off-by: David E. Box > --- > V5 - New patch > > drivers/platform/x86/intel/vsec.c | 24 ++++++++++++++++-------- > drivers/platform/x86/intel/vsec.h | 1 + > 2 files changed, 17 insertions(+), 8 deletions(-) > > diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c > index c1f9e4471b28..ae811bb65910 100644 > --- a/drivers/platform/x86/intel/vsec.c > +++ b/drivers/platform/x86/intel/vsec.c > @@ -120,6 +120,8 @@ static void intel_vsec_dev_release(struct device *dev) > { > struct intel_vsec_device *intel_vsec_dev = dev_to_ivdev(dev); > > + xa_erase(&auxdev_array, intel_vsec_dev->id); > + > mutex_lock(&vsec_ida_lock); > ida_free(intel_vsec_dev->ida, intel_vsec_dev->auxdev.id); > mutex_unlock(&vsec_ida_lock); > @@ -136,9 +138,21 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, > int ret, id; > > mutex_lock(&vsec_ida_lock); > - ret = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL); > + id = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL); > mutex_unlock(&vsec_ida_lock); > + if (id < 0) { > + kfree(intel_vsec_dev->resource); > + kfree(intel_vsec_dev); > + return ret; > + } > + > + ret = xa_alloc(&auxdev_array, &intel_vsec_dev->id, intel_vsec_dev, > + PMT_XA_LIMIT, GFP_KERNEL); > if (ret < 0) { > + mutex_lock(&vsec_ida_lock); > + ida_free(intel_vsec_dev->ida, id); > + mutex_unlock(&vsec_ida_lock); > + > kfree(intel_vsec_dev->resource); > kfree(intel_vsec_dev); > return ret; > @@ -147,7 +161,7 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, > if (!parent) > parent = &pdev->dev; > > - auxdev->id = ret; > + auxdev->id = id; > auxdev->name = name; > auxdev->dev.parent = parent; > auxdev->dev.release = intel_vsec_dev_release; > @@ -169,12 +183,6 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, > if (ret < 0) > return ret; > > - /* Add auxdev to list */ > - ret = xa_alloc(&auxdev_array, &id, intel_vsec_dev, PMT_XA_LIMIT, > - GFP_KERNEL); > - if (ret) > - return ret; > - > return 0; BTW, there's also another unnecessary return construct around this which remains after this removal. The devm_add_Action_or_reset() value can be returned directly (maybe make another patch from that cleanup though since this is a Fixes patch). -- i.