From patchwork Wed Oct 18 23:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 155224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp52532vqb; Wed, 18 Oct 2023 16:19:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0K5ogCSF0i0QqbisA7XrM+347BowO8O+XypcVWf+7rzcZXBUQEpD5VgZjQFPwoho/6VJH X-Received: by 2002:a05:6808:a06:b0:3ab:84f0:b490 with SMTP id n6-20020a0568080a0600b003ab84f0b490mr591509oij.27.1697671146725; Wed, 18 Oct 2023 16:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671146; cv=none; d=google.com; s=arc-20160816; b=LPXPW+PdMyb19br/Ba9FQFZIGvq/J3vppvaeZIl+dWiKCrqNEtPCFdrrs4ElcEcq0D AqdgnqqM4r+hG+k5ymAB3cOZ9VUirn1lLj9v2kUeAJJWj1ylsoLcreLwvnUQ7+f5sZ/y Oyz7uUvtNSeRS3Uz0ZlSOYtEmMCmxs404mjMXyUcmD26rKr8+V7FO1H73c3FeE6SksH2 Rmm0IYJN8nr+PxYqY5aRL17tZ1B7KsTLHRUViVqIwKte87Y5+Pj6RGuA6Li6sPmZlXR+ qVJZnstuQhZq4nocrH2YChy0vEfJtYWW/8tESsTf9vF2gqAZw6zcxiRPdjOVKoANiURy ik6A== 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=4l00Pz5fPPCAi3pw81rLImHIpW3vqCQnvxdPxEwQbdY=; fh=d9G4dsZtlI8UONIvGKwhW94hCYEPGxy6CqYeKEG646A=; b=09XdAyH0S7/lLFQ5qLuxWzlBBWoa6T372QOC+bvU0c1HDMzVJ2I0OpQ2trmzatkqqf eMU4+SiNVDt5sZ/hZC/Jt/63J2+PBRWD7BcvCtbhyK6PNcZJFgkld9yIoyox05hV5hYR XQGCUzsTygX3w2PLaHX8+NVF/zg2N6gcO9XIBf+YzEaeElp+f/C263F5k1ET2CLkqVDQ RlCd2S/z1uy5RRw0RNuWECsRbp9reQhHktpKBaa4ozBe6XlzGmksAiWtBL2H5u3100WN QOpeUQ0d8V3JxqMZca8EiROWdn8xX3y/WiYXMTXwRcEf7yFRm38gxdX1wxMwXd5hwjlP qvrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Enp1832c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id w8-20020a63f508000000b0059c36d79520si3205526pgh.772.2023.10.18.16.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:19:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Enp1832c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id BF67E8158391; Wed, 18 Oct 2023 16:18:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232047AbjJRXQj (ORCPT + 24 others); Wed, 18 Oct 2023 19:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbjJRXQ2 (ORCPT ); Wed, 18 Oct 2023 19:16:28 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B5AF11F; Wed, 18 Oct 2023 16:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697670986; x=1729206986; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=EiqQPHnFVS6pUKJtmCiJu9NxgHDIMiqEYmzDV9uhkOE=; b=Enp1832cZDBOxPDbHhX0P3Y4HiYsqe9tmA0D4IgOnzi3T695MU5tgjoY XDqSY/JJXuIDIZH9cR5bcptobP4TJwhh7l6OxSaNPttXQEtctRB3rNkRk idDmh5VIFAj1stkm+z4/TAUuMqMt7z5zVqeB0RwIUPN94OWfVqBu92z7E E4M06fz3LE6UGij0h51bIpp9ezVmEFTLbw6M0B5pcIVcCXIHqHEd+pErS ZNWawDGiNrYLJJVugPfSSBXLlaFOkZdEzzw36IeLNIw2RRPtjz7VvmaMu ksla5k9g9db1cda00AbXbsRolCCeKPDFreIw69+M36w9GWmew7srwHnAo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="452605954" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="452605954" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 16:16:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="756782169" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="756782169" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 16:16:25 -0700 Received: from debox1-desk4.lan (unknown [10.209.71.91]) by linux.intel.com (Postfix) with ESMTP id EE08A580E33; Wed, 18 Oct 2023 16:16:24 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH V4 03/17] platform/x86/intel/vsec: Use cleanup.h Date: Wed, 18 Oct 2023 16:16:10 -0700 Message-Id: <20231018231624.1044633-4-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018231624.1044633-1-david.e.box@linux.intel.com> References: <20231018231624.1044633-1-david.e.box@linux.intel.com> MIME-Version: 1.0 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:18:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780137220157869344 X-GMAIL-MSGID: 1780137220157869344 Use cleanup.h helpers to handle cleanup of resources in intel_vsec_add_dev() after failures. Signed-off-by: David E. Box Reviewed-by: Ilpo Järvinen --- V4 - Do no_free_ptr() before and in call to intel_vsec_add_aux(). - Add resource cleanup in this patch. V3 - New patch. drivers/platform/x86/intel/vsec.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index b14eba545770..28191313d515 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -147,10 +148,11 @@ 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 resource *res, *tmp; + struct intel_vsec_device __free(kfree) *intel_vsec_dev = NULL; + struct resource __free(kfree) *res = NULL; + struct resource *tmp; unsigned long quirks = info->quirks; - int i; + int ret, i; if (!intel_vsec_supported(header->id, info->caps)) return -EINVAL; @@ -170,10 +172,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; @@ -200,8 +200,15 @@ 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)); + /* + * Pass the ownership of intel_vsec_dev and resource within it to + * intel_vsec_add_aux() + */ + no_free_ptr(res); + ret = intel_vsec_add_aux(pdev, NULL, no_free_ptr(intel_vsec_dev), + intel_vsec_name(header->id)); + + return ret; } static bool intel_vsec_walk_header(struct pci_dev *pdev,