Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1246190rdg; Fri, 13 Oct 2023 15:16:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI38Uot1ktXulK0Ss0vQWKzZ68lXbxZaXJn2yPHqn/yZRK8pzUe8wtWDiEhsexXr4AmOWh X-Received: by 2002:a05:6358:2496:b0:13a:cb52:4837 with SMTP id m22-20020a056358249600b0013acb524837mr26410041rwc.31.1697235400259; Fri, 13 Oct 2023 15:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697235400; cv=none; d=google.com; s=arc-20160816; b=MFU/KLRUMg4BsbY2/Vv8eqvYblTUH4LyMx3wf0EypQJLNtblbeUT7EtBiO4/gX1y2R 6JTQ9w29UAHUh+wLqwe01RRO6HYn4m2NM4s5amr8L8uJCesJuuBWqrsft52o4/dTIjGr tQxfp6Td+/a1GHsaQ46O2yxJIlMxaE4Ti8LRn9vyrviYzCOyme7wmgoog20V3gZ6TF1Z hcGi1f+4SmIuWakwfK2SZpmRJwXujV8Ze4Ed6mTywivjU0VOt2OvAALwLpiQBgDD4c/m xWnVDa7/BgSunxkprYGSIw7DGkPU6SVkC2L+yMMYlgkAECKuI4Wymoe4ODWtTGlocIii cl9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:organization:references:in-reply-to:date :cc:to:reply-to:from:subject:message-id:dkim-signature; bh=wGnmB7e4w/YXNkUJ8BIngQz+mqzhZmd31qpgo7XVTmM=; fh=0L++fcZ3j4NivmPj2WckG6xGYIwVb3dCYAxPxor6gRM=; b=InOPWkGL26EJPwQoJg6n5AP4M0AcZf/SdugOex2nM3K2lZQRZtxy5OAO+7bLsbyfjQ 5wqnwBeMV0p4FPxvnN5aCMsMVZge3Xr3pH6NIcITatDLBxJXMmPmCdEp1SJy4auOB0T8 jz9QFEInv9U2CxDxdXepyvyc988yt14lGgd98j+gNuJZ/vGWA1QIP5FNdNgjQYRQnSRr WNWpmTNB2x8GnsnhZ2Q7IKraWUxxJGS1O6REkd2c07iUyb6xhlp5GsaJe9FKBXBtsj7e oRlN4VcL1XIZMeY89cu0PtRRSPWhBwhurcO/Eze+O2L+Vb5+uQlthVytgdAU5R+3pcqX hiBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LDRMy0Rj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bq11-20020a056a02044b00b005898e5f41f8si2202725pgb.53.2023.10.13.15.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LDRMy0Rj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 431FA804AD2A; Fri, 13 Oct 2023 15:16:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232021AbjJMWQM (ORCPT + 99 others); Fri, 13 Oct 2023 18:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjJMWQL (ORCPT ); Fri, 13 Oct 2023 18:16:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC0BC2; Fri, 13 Oct 2023 15:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697235370; x=1728771370; h=message-id:subject:from:reply-to:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=MZOWfH1PAK2h89+1m5wg+GI+vWQsVXrKmtOPocFipGg=; b=LDRMy0RjppZqFN1h0jFKM92aaOruDa38uq5lKDw/B/K283lh0o6GB/cY ARU7f6NkmhTv8zzszA7bi4CSJJ2FkfJFoJxNvF9AR200KBs9Ie4yuTF1G prcreav1RA1eMCAmljEbVWQlSVaqU/VOVv0gsNB6YcxU4nY+Qcv/N5tkV 9UElzt+2lS4tEDJvqYuan449YrDag8Z5W72uXit5Sbt0wcXFY4olaTs6r vT5tvjiL1nHcvzeLS9YEzpyoXzvnZjgKyxNBJs1rncjrLuPcdVQvrRm9g hvgso0P9xbRfB0a+euqDkjNwzet1DkiP+DraNojeWD5uOve3rpoXY0/B3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="471507608" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="471507608" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 15:16:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="754865755" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="754865755" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 15:16:08 -0700 Received: from jmloza-mobl.amr.corp.intel.com (unknown [10.212.236.32]) by linux.intel.com (Postfix) with ESMTP id 89D34580BF0; Fri, 13 Oct 2023 15:16:08 -0700 (PDT) Message-ID: Subject: Re: [PATCH V3 03/16] platform/x86/intel/vsec: Use cleanup.h From: "David E. Box" Reply-To: david.e.box@linux.intel.com To: Ilpo =?ISO-8859-1?Q?J=E4rvinen?= Cc: LKML , platform-driver-x86@vger.kernel.org, rajvi.jingar@linux.intel.com Date: Fri, 13 Oct 2023 15:16:08 -0700 In-Reply-To: <4315a8db-16fe-7421-c482-5aede4d5cdd@linux.intel.com> References: <20231012023840.3845703-1-david.e.box@linux.intel.com> <20231012023840.3845703-4-david.e.box@linux.intel.com> <114e1cc4-f129-b6cd-a83b-7d822cde178@linux.intel.com> <4315a8db-16fe-7421-c482-5aede4d5cdd@linux.intel.com> Organization: David E. Box Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 15:16:22 -0700 (PDT) On Fri, 2023-10-13 at 13:54 +0300, Ilpo J=C3=A4rvinen wrote: > On Thu, 12 Oct 2023, David E. Box wrote: >=20 > > On Thu, 2023-10-12 at 17:46 +0300, Ilpo J=C3=A4rvinen wrote: > > > On Wed, 11 Oct 2023, David E. Box wrote: > > >=20 > > > > Use cleanup.h helpers to handle cleanup of resources in > > > > intel_vsec_add_dev() after failures. > > > >=20 > > > > Signed-off-by: David E. Box > > > > --- > > > > V3 - New patch. > > > >=20 > > > > =C2=A0drivers/platform/x86/intel/vsec.c | 17 ++++++++++------- > > > > =C2=A01 file changed, 10 insertions(+), 7 deletions(-) > > > >=20 > > > > 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 @@ > > > > =C2=A0 > > > > =C2=A0#include > > > > =C2=A0#include > > > > +#include > > > > =C2=A0#include > > > > =C2=A0#include > > > > =C2=A0#include > > > > @@ -155,10 +156,10 @@ EXPORT_SYMBOL_NS_GPL(intel_vsec_add_aux, > > > > INTEL_VSEC); > > > > =C2=A0static int intel_vsec_add_dev(struct pci_dev *pdev, struct > > > > intel_vsec_header *header, > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct intel_vsec_platform_info *info) > > > > =C2=A0{ > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct intel_vsec_device= *intel_vsec_dev; > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct intel_vsec_device= __free(kfree) *intel_vsec_dev =3D NULL; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct resource *re= s, *tmp; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0unsigned long quirk= s =3D info->quirks; > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0int i; > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0int ret, i; > > > > =C2=A0 > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (!intel_vsec_sup= ported(header->id, info->caps)) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return -EINVAL; > > > > @@ -178,10 +179,8 @@ static int intel_vsec_add_dev(struct pci_dev *= pdev, > > > > struct intel_vsec_header *he > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return -ENOMEM; > > > > =C2=A0 > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0res =3D kcalloc(hea= der->num_entries, sizeof(*res), GFP_KERNEL); > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (!res) { > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0kfree(intel_vsec_dev); > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (!res) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return -ENOMEM; > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > > > > =C2=A0 > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (quirks & VSEC_Q= UIRK_TABLE_SHIFT) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0header->offset >>=3D TABLE_OFFSET_SHIFT; > > > > @@ -208,8 +207,12 @@ static int intel_vsec_add_dev(struct pci_dev *= pdev, > > > > struct intel_vsec_header *he > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0else > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0intel_vsec_dev->ida =3D &intel_vsec_ida; > > > > =C2=A0 > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return intel_vsec_add_au= x(pdev, NULL, intel_vsec_dev, > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 intel_vsec_name(header-= >id)); > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0ret =3D intel_vsec_add_a= ux(pdev, NULL, intel_vsec_dev, > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 intel_vsec_name(header->id)); > > > > + > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0no_free_ptr(intel_vsec_d= ev); > > > > + > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return ret; > > >=20 > > > So if intel_vsec_add_aux() returned an error, intel_vsec_dev won't be= =20 > > > freed because of the call call to no_free_ptr() before return. I that= 's=20 > > > not what you intended? > >=20 > > It will have been freed if intel_vsec_add_aux() fails. It's a little me= ssy. > > 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 fai= lure > > 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. >=20 > Oh, that's really convoluted and no wonder I missed it completely. It=20 > might even be that using cleanup.h here isn't really worth it. I know=20 > I pushed you into that direction but I didn't realize all the complexity > at that point. >=20 > If you still want to keep using cleanup.h, it would perhaps be less=20 > 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= =20 > it?) yes > are before the intel_vsec_add_aux() call (and I'd also add a comment=20 > to explain that freeing them is now responsability of=20 > intel_vsec_add_aux()). That way, we don't leave a trap into there where= =20 > somebody happily adds another no_free_ptr() to the same group and it=20 > causes a mem leak. Sure. After the comment I'd just do this then still the value is still need= ed, ret =3D intel_vsec_add_aux(pdev, NULL, no_free_ptr(intel_vsec_dev), intel_vsec_name(header->id)); David