From patchwork Thu Nov 23 04:03:39 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: 168682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp207212vqx; Wed, 22 Nov 2023 20:04:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQ/WsqvAeEYZHX8+XfjcFqfYfDA9Q1+YbMKOMVYwgdHZ1vzfomVLQ4mHPgGQoIJ8JbbXed X-Received: by 2002:a05:6a20:d044:b0:18b:4dc2:a4c7 with SMTP id hv4-20020a056a20d04400b0018b4dc2a4c7mr3961177pzb.14.1700712255594; Wed, 22 Nov 2023 20:04:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700712255; cv=none; d=google.com; s=arc-20160816; b=pi+SFn536+j1zfwvWl6wcF/FnLYMgTOdII0e4HyaTAU30+LEy3rTcj2KaRrq85tbYA sgKzud3BksWLC0oV41fvqrDzFcpJ24OHRXFwaWKcpEuUhOr+AEQi5CVx4r6SeR4w2nBH oQ1H0HL4tWTTWKohMRQI7BgcMofQFmF//lfwNLRUbfjRzB1nOzv/1HrhkrNK+xcWzq+g jTN4irCO2fSiLXIPh4yMtNUcxFOuW26uxRW5KgLlkWOz6Eq+fvSCJu3NcXjK3u+guf82 XPqWiUAoJpQmE8w9/FK37Ul5pFIwb9FenPAPHUjGMfXqDmLRjCE3yUMDm3O1l+A/Hpmq 4rvg== 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=wU676TANEsrBKxehYCoPXYO/VKGGPFFqnATADITdXeo=; fh=d9G4dsZtlI8UONIvGKwhW94hCYEPGxy6CqYeKEG646A=; b=mH2VT3+X6Am9qaBQFiVNhLNpT8z3fcdW7jXKjoRc+6YnTEGey9ibKFCBrgEvM65KG4 8ew1zRfnAGkGf2T9pFbjx60MLEyzXSHirlALhEXsvaD4b30JlcpPzzvC3yYOC1qp06wm fbfm1f/OxxAdn6DA8nw5TBx4BPM2KZ6iney+BgIM7GkEQu64hEqn1MbFgEFQJG8Pq0Ty ajgr0mklEnoyYOIrOd9V8s4XYYst1cBBKSVWiiOw1ohlJqmX7CZSMbcE1z9EH5KII4Uv hmO1CyeUsTRdfNUOlwd7P9sGLuDeAunN/kZW2hM0Bdjk/lFaNnNnM8k/xmfZ+bdxSp85 x/sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nBVy1VBo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s38-20020a635266000000b005b8ee1c0c67si477717pgl.594.2023.11.22.20.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 20:04:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nBVy1VBo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id DFA58807DE25; Wed, 22 Nov 2023 20:04:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344542AbjKWEEB (ORCPT + 99 others); Wed, 22 Nov 2023 23:04:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232615AbjKWEDv (ORCPT ); Wed, 22 Nov 2023 23:03:51 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8170F1B5; Wed, 22 Nov 2023 20:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700712238; x=1732248238; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=gLcHQ9sSpRvNAc/JiEVqzwzgfQlZmnW1+ez8U6GM0yo=; b=nBVy1VBo5Ih/us4VR+z9qW5HPEaK6/7XqSrhnVsH3ZR60ZCvY73FeaBF G8yTtmzymJ6OSMbfy5qK4dlnitiFhcgNJ34fsvf5EFWGUqclSWsWXZPKY NJue6fBTIWX8xWtmMTJzB16qAFqcWugpGuwhcNRdYKK1MOkLozITjxTv6 H4X1KxozeRBNDFJlVSR+3b7kSwKTo/9H0ZMcqxF2r2FIGiPjxYOMlvf2h 19Ndasgx0COOTqtJxFZPeSjOTYhQE9+1lMmHGR8WfgnBSs6Ddgi8qUF2V C4l5oIK2G2dxCYZggwd0U2gU/zyf9nIj2W0zG/St0ekoPQsINOZtn+cfo w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="5334659" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="5334659" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="837671147" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="837671147" Received: from linux.intel.com ([10.54.29.200]) by fmsmga004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:56 -0800 Received: from debox1-desk4.lan (snpatel1-mobl.amr.corp.intel.com [10.209.89.91]) by linux.intel.com (Postfix) with ESMTP id D4ABC580CA6; Wed, 22 Nov 2023 20:03:55 -0800 (PST) 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 V5 04/20] platform/x86/intel/vsec: Use cleanup.h Date: Wed, 22 Nov 2023 20:03:39 -0800 Message-Id: <20231123040355.82139-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231123040355.82139-1-david.e.box@linux.intel.com> References: <20231123040355.82139-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 22 Nov 2023 20:04:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783326054503126061 X-GMAIL-MSGID: 1783326054503126061 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 --- V5 - Assign no_free_ptr(res) to resource member. This fixes __must_check_fn warning. - Remove unsed ret variable. 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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 15866b7d3117..7dc3650f2757 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 @@ -155,8 +156,9 @@ 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; @@ -178,10 +180,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; @@ -199,7 +199,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he } intel_vsec_dev->pcidev = pdev; - intel_vsec_dev->resource = res; + intel_vsec_dev->resource = no_free_ptr(res); intel_vsec_dev->num_resources = header->num_entries; intel_vsec_dev->quirks = info->quirks; @@ -208,7 +208,11 @@ 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, + /* + * Pass the ownership of intel_vsec_dev and resource within it to + * intel_vsec_add_aux() + */ + return intel_vsec_add_aux(pdev, NULL, no_free_ptr(intel_vsec_dev), intel_vsec_name(header->id)); }