Message ID | 20231012023840.3845703-4-david.e.box@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp942543vqb; Wed, 11 Oct 2023 19:38:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmz/4Uji9wSTCltHvStRB4amOfO3xsvyh7bJbvnCJLzOKKm7WjIjoARnMw9JH1vQnlrLCA X-Received: by 2002:a05:6a20:c18f:b0:16e:26fd:7c02 with SMTP id bg15-20020a056a20c18f00b0016e26fd7c02mr14361126pzb.2.1697078339659; Wed, 11 Oct 2023 19:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697078339; cv=none; d=google.com; s=arc-20160816; b=KLqJENzGLRtxMuVgr7a2pUONXcFpRx3deITyPvb/zI7HmHHYHpNYQ2AD8cT7ESniEp r8JBKUxaJTLSMNJrw10uQu5CTIT18uMOBVs+C9yxRURQr8tEJCldSCH4SDGDDSXv88P2 50qU2Ejll600Hha/67AJnfZ6v9fhI5YpZgD5XZFA3CidqbL8RBtiwxj3G6ePO7iInTnK yVuxHP2gxZmcgKTqbJZvnya3iS3+YS4IMGRfJQa1b/YZsjL/mLBHfkgXQrbpjH+/Pd96 loyg1K1noXGeGuZbFIq2FLJYzASONhaI3dFmShXZSbredMDJYy1wc369j/jeBNprk2cq 4LJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=LSGakL5RLvb9KDMfon3EIACwIfqbOQIDxewJadLS5uo=; fh=d9G4dsZtlI8UONIvGKwhW94hCYEPGxy6CqYeKEG646A=; b=ieELTWkWz01PQsGgrvUIBluYU8ekz3YOQDPi+OPusxiQEnzYg8fWrono95PBkhrH59 RFtoQLN1VEepHMIeJaEShmcc5wIv7l+631bfR6dNaYudp9IApVjzvh59pSItvvTzGsRm Cd5uGVvhUZARBw/vDWZR0WvN9wpb5rOA3s9mpv8jgIup5YVhZkzGwyVh7fC5F4DHeR/r i7uEEE0UpQwtiFGSk6FJMGvw4NlLC9BBHKusUSSi+rCjC4kO3SRaOtOhe7ajkUYof7Ei LW4F4U9LTqnsJojgGWYQOSenjRhaWOsK1QCiKX0XqiICHLIPsP3bPwcBGxb2lS/RdY09 t9yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SFxASy0A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id k1-20020a170902c40100b001beef8ccd05si1239692plk.489.2023.10.11.19.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 19:38:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SFxASy0A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 2CCA4802583F; Wed, 11 Oct 2023 19:38:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376775AbjJLCiv (ORCPT <rfc822;kartikey406@gmail.com> + 18 others); Wed, 11 Oct 2023 22:38:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbjJLCio (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 11 Oct 2023 22:38:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EF13A9; Wed, 11 Oct 2023 19:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697078323; x=1728614323; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=mdXRrafSW2vaWofevfN0nlDG8rsooz2jVNY8wgQKLnE=; b=SFxASy0AIWikny/QwYCKHUKEqrX35rFokCGnx5VF9h8aHAuKWBRcrbGm uMdUqpOe69sWj+DqNUdJ5pYrGPxm0AMoc625LzQNcRJz7nl5o7enXEL8+ GBhCe4ImmS0SEq4L859ZI52J/4NC3Bwufb6ViLOstJnOVcuIe++OyVlRc fZkIXbXxrpQu8+uPxvn745GALlg11c3xLdCOUnsmL6t+wqeDJT7HxrXTG ttZEJgSIoY/2hcTymAlvtc8AsaHs7cjJwHvfT+LakVlkZaj++hAaiUboR wvmSJJRpP79AZrJWxi5CEcKTjtI6FS/xb3rEqEt7R4uCLZjLH7FQakAxR A==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="3402623" X-IronPort-AV: E=Sophos;i="6.03,217,1694761200"; d="scan'208";a="3402623" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 19:38:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="783507858" X-IronPort-AV: E=Sophos;i="6.03,217,1694761200"; d="scan'208";a="783507858" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 19:38:41 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.105.238]) by linux.intel.com (Postfix) with ESMTP id 18E3A580E33; Wed, 11 Oct 2023 19:38:41 -0700 (PDT) From: "David E. Box" <david.e.box@linux.intel.com> To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h Date: Wed, 11 Oct 2023 19:38:27 -0700 Message-Id: <20231012023840.3845703-4-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012023840.3845703-1-david.e.box@linux.intel.com> References: <20231012023840.3845703-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 19:38:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779515617094260791 X-GMAIL-MSGID: 1779515617094260791 |
Series |
intel_pmc: Add telemetry API to read counters
|
|
Commit Message
David E. Box
Oct. 12, 2023, 2:38 a.m. UTC
Use cleanup.h helpers to handle cleanup of resources in
intel_vsec_add_dev() after failures.
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---
V3 - New patch.
drivers/platform/x86/intel/vsec.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
Comments
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on acce85a7dd28eac3858d44230f4c65985d0f271c] url: https://github.com/intel-lab-lkp/linux/commits/David-E-Box/platform-x86-intel-vsec-Move-structures-to-header/20231012-104217 base: acce85a7dd28eac3858d44230f4c65985d0f271c patch link: https://lore.kernel.org/r/20231012023840.3845703-4-david.e.box%40linux.intel.com patch subject: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h reproduce: (https://download.01.org/0day-ci/archive/20231012/202310121314.3Xpqom2w-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202310121314.3Xpqom2w-lkp@intel.com/ # many are suggestions rather than must-fix ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) #31: FILE: drivers/platform/x86/intel/vsec.c:159: + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; ^
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on acce85a7dd28eac3858d44230f4c65985d0f271c] url: https://github.com/intel-lab-lkp/linux/commits/David-E-Box/platform-x86-intel-vsec-Move-structures-to-header/20231012-104217 base: acce85a7dd28eac3858d44230f4c65985d0f271c patch link: https://lore.kernel.org/r/20231012023840.3845703-4-david.e.box%40linux.intel.com patch subject: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h reproduce: (https://download.01.org/0day-ci/archive/20231012/202310121333.TE7R7kSs-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202310121333.TE7R7kSs-lkp@intel.com/ # many are suggestions rather than must-fix ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) #31: FILE: drivers/platform/x86/intel/vsec.c:159: + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; ^
On Wed, 11 Oct 2023, David E. Box wrote: > Use cleanup.h helpers to handle cleanup of resources in > intel_vsec_add_dev() after failures. > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > --- > V3 - New patch. > > drivers/platform/x86/intel/vsec.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c > index 15866b7d3117..f03ab89ab7c0 100644 > --- a/drivers/platform/x86/intel/vsec.c > +++ b/drivers/platform/x86/intel/vsec.c > @@ -15,6 +15,7 @@ > > #include <linux/auxiliary_bus.h> > #include <linux/bits.h> > +#include <linux/cleanup.h> > #include <linux/delay.h> > #include <linux/kernel.h> > #include <linux/idr.h> > @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, INTEL_VSEC); > static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *header, > struct intel_vsec_platform_info *info) > { > - struct intel_vsec_device *intel_vsec_dev; > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > struct resource *res, *tmp; > unsigned long quirks = info->quirks; > - int i; > + int ret, i; > > if (!intel_vsec_supported(header->id, info->caps)) > return -EINVAL; > @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he > return -ENOMEM; > > res = kcalloc(header->num_entries, sizeof(*res), GFP_KERNEL); > - if (!res) { > - kfree(intel_vsec_dev); > + if (!res) > return -ENOMEM; > - } > > if (quirks & VSEC_QUIRK_TABLE_SHIFT) > header->offset >>= TABLE_OFFSET_SHIFT; > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he > else > intel_vsec_dev->ida = &intel_vsec_ida; > > - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > - intel_vsec_name(header->id)); > + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > + intel_vsec_name(header->id)); > + > + no_free_ptr(intel_vsec_dev); > + > + return ret; So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be freed because of the call call to no_free_ptr() before return. I that's not what you intended?
On Thu, 2023-10-12 at 17:46 +0300, Ilpo Järvinen wrote: > On Wed, 11 Oct 2023, David E. Box wrote: > > > Use cleanup.h helpers to handle cleanup of resources in > > intel_vsec_add_dev() after failures. > > > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > --- > > V3 - New patch. > > > > drivers/platform/x86/intel/vsec.c | 17 ++++++++++------- > > 1 file changed, 10 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/platform/x86/intel/vsec.c > > b/drivers/platform/x86/intel/vsec.c > > index 15866b7d3117..f03ab89ab7c0 100644 > > --- a/drivers/platform/x86/intel/vsec.c > > +++ b/drivers/platform/x86/intel/vsec.c > > @@ -15,6 +15,7 @@ > > > > #include <linux/auxiliary_bus.h> > > #include <linux/bits.h> > > +#include <linux/cleanup.h> > > #include <linux/delay.h> > > #include <linux/kernel.h> > > #include <linux/idr.h> > > @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, INTEL_VSEC); > > static int intel_vsec_add_dev(struct pci_dev *pdev, struct > > intel_vsec_header *header, > > struct intel_vsec_platform_info *info) > > { > > - struct intel_vsec_device *intel_vsec_dev; > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > struct resource *res, *tmp; > > unsigned long quirks = info->quirks; > > - int i; > > + int ret, i; > > > > if (!intel_vsec_supported(header->id, info->caps)) > > return -EINVAL; > > @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > struct intel_vsec_header *he > > return -ENOMEM; > > > > res = kcalloc(header->num_entries, sizeof(*res), GFP_KERNEL); > > - if (!res) { > > - kfree(intel_vsec_dev); > > + if (!res) > > return -ENOMEM; > > - } > > > > if (quirks & VSEC_QUIRK_TABLE_SHIFT) > > header->offset >>= TABLE_OFFSET_SHIFT; > > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > struct intel_vsec_header *he > > else > > intel_vsec_dev->ida = &intel_vsec_ida; > > > > - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > - intel_vsec_name(header->id)); > > + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > + intel_vsec_name(header->id)); > > + > > + no_free_ptr(intel_vsec_dev); > > + > > + return ret; > > So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be > freed because of the call call to no_free_ptr() before return. I that's > not what you intended? It will have been freed if intel_vsec_add_aux() fails. It's a little messy. That function creates the auxdev and assigns the release function which will free intel_vsec_dev when the device is removed. But there are failure points that will also invoke the release function. Because of this, for all the failure points in that function we free intel_vsec_dev so that it's state doesn't need to be questioned here. This happens explicitly if the failure is before auxiliary_device_init(), or through the release function invoked by auxiliary_device_uninit() if after. David >
On Thu, 2023-10-12 at 13:25 +0800, kernel test robot wrote: > Hi David, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on acce85a7dd28eac3858d44230f4c65985d0f271c] > > url: > https://github.com/intel-lab-lkp/linux/commits/David-E-Box/platform-x86-intel-vsec-Move-structures-to-header/20231012-104217 > base: acce85a7dd28eac3858d44230f4c65985d0f271c > patch link: > https://lore.kernel.org/r/20231012023840.3845703-4-david.e.box%40linux.intel.com > patch subject: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h > reproduce: > (https://download.01.org/0day-ci/archive/20231012/202310121314.3Xpqom2w-lkp@in > tel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version > of > the same patch/commit), kindly add following tags > > Reported-by: kernel test robot <lkp@intel.com> > > Closes: > > https://lore.kernel.org/oe-kbuild-all/202310121314.3Xpqom2w-lkp@intel.com/ > > # many are suggestions rather than must-fix > > ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) > #31: FILE: drivers/platform/x86/intel/vsec.c:159: > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; These looks like false positives. David > ^ >
Hi, I added checkpatch people, please check what looks a false positive below. On Thu, 12 Oct 2023, David E. Box wrote: > On Thu, 2023-10-12 at 13:25 +0800, kernel test robot wrote: > > Hi David, > > > > kernel test robot noticed the following build warnings: > > > > [auto build test WARNING on acce85a7dd28eac3858d44230f4c65985d0f271c] > > > > url: > > https://github.com/intel-lab-lkp/linux/commits/David-E-Box/platform-x86-intel-vsec-Move-structures-to-header/20231012-104217 > > base: acce85a7dd28eac3858d44230f4c65985d0f271c > > patch link: > > https://lore.kernel.org/r/20231012023840.3845703-4-david.e.box%40linux.intel.com > > patch subject: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h > > reproduce: > > (https://download.01.org/0day-ci/archive/20231012/202310121314.3Xpqom2w-lkp@in > > tel.com/reproduce) > > > > If you fix the issue in a separate patch/commit (i.e. not just a new version > > of > > the same patch/commit), kindly add following tags > > > Reported-by: kernel test robot <lkp@intel.com> > > > Closes: > > > https://lore.kernel.org/oe-kbuild-all/202310121314.3Xpqom2w-lkp@intel.com/ > > > > # many are suggestions rather than must-fix > > > > ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) > > #31: FILE: drivers/platform/x86/intel/vsec.c:159: > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > These looks like false positives. I agree. If I interpret the error message right checkpatch seems to think that's a multiplication which is not the case here.
On Thu, 12 Oct 2023, David E. Box wrote: > On Thu, 2023-10-12 at 17:46 +0300, Ilpo Järvinen wrote: > > On Wed, 11 Oct 2023, David E. Box wrote: > > > > > Use cleanup.h helpers to handle cleanup of resources in > > > intel_vsec_add_dev() after failures. > > > > > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > > --- > > > V3 - New patch. > > > > > > drivers/platform/x86/intel/vsec.c | 17 ++++++++++------- > > > 1 file changed, 10 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/platform/x86/intel/vsec.c > > > b/drivers/platform/x86/intel/vsec.c > > > index 15866b7d3117..f03ab89ab7c0 100644 > > > --- a/drivers/platform/x86/intel/vsec.c > > > +++ b/drivers/platform/x86/intel/vsec.c > > > @@ -15,6 +15,7 @@ > > > > > > #include <linux/auxiliary_bus.h> > > > #include <linux/bits.h> > > > +#include <linux/cleanup.h> > > > #include <linux/delay.h> > > > #include <linux/kernel.h> > > > #include <linux/idr.h> > > > @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, INTEL_VSEC); > > > static int intel_vsec_add_dev(struct pci_dev *pdev, struct > > > intel_vsec_header *header, > > > struct intel_vsec_platform_info *info) > > > { > > > - struct intel_vsec_device *intel_vsec_dev; > > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > > struct resource *res, *tmp; > > > unsigned long quirks = info->quirks; > > > - int i; > > > + int ret, i; > > > > > > if (!intel_vsec_supported(header->id, info->caps)) > > > return -EINVAL; > > > @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > > struct intel_vsec_header *he > > > return -ENOMEM; > > > > > > res = kcalloc(header->num_entries, sizeof(*res), GFP_KERNEL); > > > - if (!res) { > > > - kfree(intel_vsec_dev); > > > + if (!res) > > > return -ENOMEM; > > > - } > > > > > > if (quirks & VSEC_QUIRK_TABLE_SHIFT) > > > header->offset >>= TABLE_OFFSET_SHIFT; > > > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > > struct intel_vsec_header *he > > > else > > > intel_vsec_dev->ida = &intel_vsec_ida; > > > > > > - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > - intel_vsec_name(header->id)); > > > + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > + intel_vsec_name(header->id)); > > > + > > > + no_free_ptr(intel_vsec_dev); > > > + > > > + return ret; > > > > So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be > > freed because of the call call to no_free_ptr() before return. I that's > > not what you intended? > > It will have been freed if intel_vsec_add_aux() fails. It's a little messy. That > function creates the auxdev and assigns the release function which will free > intel_vsec_dev when the device is removed. But there are failure points that > will also invoke the release function. Because of this, for all the failure > points in that function we free intel_vsec_dev so that it's state doesn't need > to be questioned here. This happens explicitly if the failure is before > auxiliary_device_init(), or through the release function invoked by > auxiliary_device_uninit() if after. Oh, that's really convoluted and no wonder I missed it completely. It might even be that using cleanup.h here isn't really worth it. I know I pushed you into that direction but I didn't realize all the complexity at that point. If you still want to keep using cleanup.h, it would perhaps be less dangerous if you change the code such that no_free_ptr() for intel_vsec_dev and the resource (in 4/16, that's a similar case, isn't it?) are before the intel_vsec_add_aux() call (and I'd also add a comment to explain that freeing them is now responsability of intel_vsec_add_aux()). That way, we don't leave a trap into there where somebody happily adds another no_free_ptr() to the same group and it causes a mem leak.
On Fri, 2023-10-13 at 13:39 +0300, Ilpo Järvinen wrote: > Hi, > > I added checkpatch people, please check what looks a false positive below. Yeah, thanks I guess. The __free uses are very new. I'll play around with adding it to $Attributes and see what happens. > On Thu, 12 Oct 2023, David E. Box wrote: > > On Thu, 2023-10-12 at 13:25 +0800, kernel test robot wrote: > > > kernel test robot noticed the following build warnings: > > > # many are suggestions rather than must-fix [] > > > ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) > > > #31: FILE: drivers/platform/x86/intel/vsec.c:159: > > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > > > These looks like false positives. > > I agree. If I interpret the error message right checkpatch seems to think > that's a multiplication which is not the case here.
On Fri, 2023-10-13 at 13:54 +0300, Ilpo Järvinen wrote: > On Thu, 12 Oct 2023, David E. Box wrote: > > > On Thu, 2023-10-12 at 17:46 +0300, Ilpo Järvinen wrote: > > > On Wed, 11 Oct 2023, David E. Box wrote: > > > > > > > Use cleanup.h helpers to handle cleanup of resources in > > > > intel_vsec_add_dev() after failures. > > > > > > > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > > > --- > > > > V3 - New patch. > > > > > > > > drivers/platform/x86/intel/vsec.c | 17 ++++++++++------- > > > > 1 file changed, 10 insertions(+), 7 deletions(-) > > > > > > > > diff --git a/drivers/platform/x86/intel/vsec.c > > > > b/drivers/platform/x86/intel/vsec.c > > > > index 15866b7d3117..f03ab89ab7c0 100644 > > > > --- a/drivers/platform/x86/intel/vsec.c > > > > +++ b/drivers/platform/x86/intel/vsec.c > > > > @@ -15,6 +15,7 @@ > > > > > > > > #include <linux/auxiliary_bus.h> > > > > #include <linux/bits.h> > > > > +#include <linux/cleanup.h> > > > > #include <linux/delay.h> > > > > #include <linux/kernel.h> > > > > #include <linux/idr.h> > > > > @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, > > > > INTEL_VSEC); > > > > static int intel_vsec_add_dev(struct pci_dev *pdev, struct > > > > intel_vsec_header *header, > > > > struct intel_vsec_platform_info *info) > > > > { > > > > - struct intel_vsec_device *intel_vsec_dev; > > > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > > > struct resource *res, *tmp; > > > > unsigned long quirks = info->quirks; > > > > - int i; > > > > + int ret, i; > > > > > > > > if (!intel_vsec_supported(header->id, info->caps)) > > > > return -EINVAL; > > > > @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > > > struct intel_vsec_header *he > > > > return -ENOMEM; > > > > > > > > res = kcalloc(header->num_entries, sizeof(*res), GFP_KERNEL); > > > > - if (!res) { > > > > - kfree(intel_vsec_dev); > > > > + if (!res) > > > > return -ENOMEM; > > > > - } > > > > > > > > if (quirks & VSEC_QUIRK_TABLE_SHIFT) > > > > header->offset >>= TABLE_OFFSET_SHIFT; > > > > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > > > struct intel_vsec_header *he > > > > else > > > > intel_vsec_dev->ida = &intel_vsec_ida; > > > > > > > > - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > > - intel_vsec_name(header->id)); > > > > + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > > + intel_vsec_name(header->id)); > > > > + > > > > + no_free_ptr(intel_vsec_dev); > > > > + > > > > + return ret; > > > > > > So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be > > > freed because of the call call to no_free_ptr() before return. I that's > > > not what you intended? > > > > It will have been freed if intel_vsec_add_aux() fails. It's a little messy. > > That > > function creates the auxdev and assigns the release function which will free > > intel_vsec_dev when the device is removed. But there are failure points that > > will also invoke the release function. Because of this, for all the failure > > points in that function we free intel_vsec_dev so that it's state doesn't > > need > > to be questioned here. This happens explicitly if the failure is before > > auxiliary_device_init(), or through the release function invoked by > > auxiliary_device_uninit() if after. > > Oh, that's really convoluted and no wonder I missed it completely. It > might even be that using cleanup.h here isn't really worth it. I know > I pushed you into that direction but I didn't realize all the complexity > at that point. > > If you still want to keep using cleanup.h, it would perhaps be less > dangerous if you change the code such that no_free_ptr() for > intel_vsec_dev and the resource (in 4/16, that's a similar case, isn't > it?) yes > are before the intel_vsec_add_aux() call (and I'd also add a comment > to explain that freeing them is now responsability of > intel_vsec_add_aux()). That way, we don't leave a trap into there where > somebody happily adds another no_free_ptr() to the same group and it > causes a mem leak. Sure. After the comment I'd just do this then still the value is still needed, ret = intel_vsec_add_aux(pdev, NULL, no_free_ptr(intel_vsec_dev), intel_vsec_name(header->id)); David
On Fri, 13 Oct 2023, David E. Box wrote: > On Fri, 2023-10-13 at 13:54 +0300, Ilpo Järvinen wrote: > > On Thu, 12 Oct 2023, David E. Box wrote: > > > > > On Thu, 2023-10-12 at 17:46 +0300, Ilpo Järvinen wrote: > > > > On Wed, 11 Oct 2023, David E. Box wrote: > > > > > > > > > Use cleanup.h helpers to handle cleanup of resources in > > > > > intel_vsec_add_dev() after failures. > > > > > > > > > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > > > > --- > > > > > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, > > > > > struct intel_vsec_header *he > > > > > else > > > > > intel_vsec_dev->ida = &intel_vsec_ida; > > > > > > > > > > - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > > > - intel_vsec_name(header->id)); > > > > > + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, > > > > > + intel_vsec_name(header->id)); > > > > > + > > > > > + no_free_ptr(intel_vsec_dev); > > > > > + > > > > > + return ret; > > > > > > > > So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be > > > > freed because of the call call to no_free_ptr() before return. I that's > > > > not what you intended? > > > > > > It will have been freed if intel_vsec_add_aux() fails. It's a little messy. > > > That > > > function creates the auxdev and assigns the release function which will free > > > intel_vsec_dev when the device is removed. But there are failure points that > > > will also invoke the release function. Because of this, for all the failure > > > points in that function we free intel_vsec_dev so that it's state doesn't > > > need > > > to be questioned here. This happens explicitly if the failure is before > > > auxiliary_device_init(), or through the release function invoked by > > > auxiliary_device_uninit() if after. > > > > Oh, that's really convoluted and no wonder I missed it completely. It > > might even be that using cleanup.h here isn't really worth it. I know > > I pushed you into that direction but I didn't realize all the complexity > > at that point. ... > > are before the intel_vsec_add_aux() call (and I'd also add a comment > > to explain that freeing them is now responsability of > > intel_vsec_add_aux()). That way, we don't leave a trap into there where > > somebody happily adds another no_free_ptr() to the same group and it > > causes a mem leak. > > Sure. After the comment I'd just do this then still the value is still needed, > > ret = intel_vsec_add_aux(pdev, NULL, no_free_ptr(intel_vsec_dev), > intel_vsec_name(header->id)); True, I realized later that the variable gets NULLed because of how no_free_ptr() works so no_free_ptr() has to be within the call itself, but that's actually much better than my initial suggestion! So I think the best we can get out of this is along the lines of (with the subsequent change with res too): /* Pass the ownership of intel_vsec_dev and resource within it to intel_vsec_add_aux() */ no_free_ptr(res); return intel_vsec_add_aux(pdev, info->parent, no_free_ptr(intel_vsec_dev), intel_vsec_name(header->id)); That seems the least trappiest and actually nicely documents who is responsible for what. To contrast the earlier, this feels very elegant, the perceived complexity related to intel_vsec_add_aux() no longer feels tricky at all so we end up solving also that problem better than the original.
On Fri, 2023-10-13 at 11:14 -0700, Joe Perches wrote: > On Fri, 2023-10-13 at 13:39 +0300, Ilpo Järvinen wrote: > > Hi, > > > > I added checkpatch people, please check what looks a false positive below. > > Yeah, thanks I guess. > The __free uses are very new. > I'll play around with adding it to $Attributes > and see what happens. > > > > On Thu, 12 Oct 2023, David E. Box wrote: > > > On Thu, 2023-10-12 at 13:25 +0800, kernel test robot wrote: > > > > kernel test robot noticed the following build warnings: > > > > # many are suggestions rather than must-fix > [] > > > > ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) > > > > #31: FILE: drivers/platform/x86/intel/vsec.c:159: > > > > + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; > > > . > > > These looks like false positives. > > > > I agree. If I interpret the error message right checkpatch seems to think > > that's a multiplication which is not the case here. So __free is an odd $Attribute as it takes an argument. I've added it along with the other odd $Attribute __alloc_size to another variable called $ArgAttribute and $Attribute. Oddly, I don't understand why perl does not perform the elimination using $foo =~ s/\b$ArgAttribute\b//g; but does do the elimination using $foo =~ s/\b$ArgAttribute//g; maybe something to do with the closing parenthesis in the match. So now there is a separate substitution for this in a test. Comments? --- scripts/checkpatch.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 25fdb7fda1128..501383fa31c55 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -488,9 +488,14 @@ our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; +our $ArgAttribute = qr{(?x: + __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)| + __free\s*\(\s*\w+\s*\) +)}; + # Notes to $Attribute: # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check -our $Attribute = qr{ +our $Attribute = qr{(?x: const| volatile| __percpu| @@ -516,8 +521,8 @@ our $Attribute = qr{ ____cacheline_aligned_in_smp| ____cacheline_internodealigned_in_smp| __weak| - __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) - }x; + $ArgAttribute + )}; our $Modifier; our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__}; our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; @@ -4091,6 +4096,9 @@ sub process { # remove $Attribute/$Sparse uses to simplify comparisons $sl =~ s/\b(?:$Attribute|$Sparse)\b//g; $pl =~ s/\b(?:$Attribute|$Sparse)\b//g; + $sl =~ s/\b(?:$ArgAttribute)//g; + $pl =~ s/\b(?:$ArgAttribute)//g; + if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || # function pointer declarations $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 15866b7d3117..f03ab89ab7c0 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -15,6 +15,7 @@ #include <linux/auxiliary_bus.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/idr.h> @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, INTEL_VSEC); static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *header, struct intel_vsec_platform_info *info) { - struct intel_vsec_device *intel_vsec_dev; + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; struct resource *res, *tmp; unsigned long quirks = info->quirks; - int i; + int ret, i; if (!intel_vsec_supported(header->id, info->caps)) return -EINVAL; @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he return -ENOMEM; res = kcalloc(header->num_entries, sizeof(*res), GFP_KERNEL); - if (!res) { - kfree(intel_vsec_dev); + if (!res) return -ENOMEM; - } if (quirks & VSEC_QUIRK_TABLE_SHIFT) header->offset >>= TABLE_OFFSET_SHIFT; @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he else intel_vsec_dev->ida = &intel_vsec_ida; - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, - intel_vsec_name(header->id)); + ret = intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, + intel_vsec_name(header->id)); + + no_free_ptr(intel_vsec_dev); + + return ret; } static bool intel_vsec_walk_header(struct pci_dev *pdev,