Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp69762rdb; Mon, 14 Aug 2023 09:42:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwxEYAi8zLA//VRn6x5f75OZ5kk0DoNVLBqNmeniKvnQR5tCM+h7l91a7BrtBc4mxjq5Av X-Received: by 2002:a05:6a20:dda6:b0:13c:a846:366 with SMTP id kw38-20020a056a20dda600b0013ca8460366mr11289378pzb.2.1692031360120; Mon, 14 Aug 2023 09:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692031360; cv=none; d=google.com; s=arc-20160816; b=GBX19cBATjfx1thu4OI6f2CmOnr6iwSb0uBwXCTYwGMaC7tdYLzd9wJRIjHjiLFUgN 6hv1xnXYKAoL5ND0b3ssT7w6s4oEyLxCXXrgynRWya9p86PAWDB0q1ecnPcPUbqxDuGh BHPhp8GNqh/fj6fATxYTAt8fRGcZwHRf41fsGgLq5eBYn1K967dSiNuY7WO45qQiVLAh 6Wiy+xey/XSJ/ZaIkQHzmJJFV4UUyngbx1kHxmv4G5IhQUSRc/KExgwT8OjX83WhJQkV Fpsy/lF8IwtBMIQMNVFbr1qSGlm8IGqFvzYxcYv+2IzD09gLl0sov4Pnsza0kfRSVI0T VVPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8vjO5Vr4Iqwx53G4DlA4xQ/SuWmPFnqZp5UxmWeGppI=; fh=UeBMOWqmY7pvyk5be+8sGD0Bo6e0MV7IOFu2Gz9iaiI=; b=qYKqgzGAx5jKTE48UDYlsQlXIsr/rOOrhrAcEdbso294VgqZ+joAc81NUQe5CtQsSq Pu4bc4+vtyFjUCKXVoZ76JG705ARC6M4e8SY4eyLkFB6e90aqWoKZhV7QWe10qYfkFyS Z4OFXpyB2XvcmD057mePF4RbxcKd/USQ2WhQ/KiMGdQmjUkgNMEjLd81wfXZk9Rh4HU8 tcVY7bAUADYO4RvCNjeHLfaUHi8GjSqwE+5hlmeR5ubFdjsOInDo/JYcbcXsOKHDO3Xs Tr5qQcRwyHH6/TkcWmqmZY+qt+vPTU5Xs6wjhOM7Lb1pyn5i6L4K6xgBOfeXniQo2y6w KSpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GXcBKaGC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a056a001a9000b0064f78c32b89si8582091pfv.95.2023.08.14.09.42.26; Mon, 14 Aug 2023 09:42:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GXcBKaGC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231222AbjHNQRv (ORCPT + 99 others); Mon, 14 Aug 2023 12:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjHNQRq (ORCPT ); Mon, 14 Aug 2023 12:17:46 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3A1B106 for ; Mon, 14 Aug 2023 09:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8vjO5Vr4Iqwx53G4DlA4xQ/SuWmPFnqZp5UxmWeGppI=; b=GXcBKaGCu9y4BHouwwR94uvv3V GAKOL5U01e+9yy24mEyYKD8lM2LNFW8JuijYmcF9iaU8VcfVHT5EyCjp1uRVS7ZTV7ey769Qo7Z2l KqUBcyWiXY7llr+inmGpNJVx2ubEaEmdV6bEvExbjTplgVYQJPDXkJfcQVqjORrfaDFe27nwwJp2e qh5z9lUWYwZsGC/gHp0HHaAMu4iP7VLiTqBbEVhQ75bopT2QRQZSDB4mkqQ9gFYmayqtjhh2NW29c QUe/ULPnHCjDpXoYbv5agkS9oAXcXFijazUaCBm38tjLhwEC9bH1NbIFL7AYhL9tOSBKm4yOMat+c /ivwwvAg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qVaG3-002wjc-UG; Mon, 14 Aug 2023 16:17:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7BC3230020B; Mon, 14 Aug 2023 18:17:31 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5F844202C2249; Mon, 14 Aug 2023 18:17:31 +0200 (CEST) Date: Mon, 14 Aug 2023 18:17:31 +0200 From: Peter Zijlstra To: Greg Kroah-Hartman Cc: Dan Williams , linux-coco@lists.linux.dev, Andrew Morton , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/5] mm/slab: Add __free() support for kvfree Message-ID: <20230814161731.GN776869@hirez.programming.kicks-ass.net> References: <169199898909.1782217.10899362240465838600.stgit@dwillia2-xfh.jf.intel.com> <169199901230.1782217.9803098171993981037.stgit@dwillia2-xfh.jf.intel.com> <2023081449-blurry-bath-248e@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2023081449-blurry-bath-248e@gregkh> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 14, 2023 at 05:31:27PM +0200, Greg Kroah-Hartman wrote: > On Mon, Aug 14, 2023 at 12:43:32AM -0700, Dan Williams wrote: > > Allow for the declaration of variables that trigger kvfree() when they > > go out of scope. > > > > Cc: Andrew Morton > > Cc: Peter Zijlstra > > Cc: Greg Kroah-Hartman > > Signed-off-by: Dan Williams > > --- > > include/linux/slab.h | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index 848c7c82ad5a..241025367943 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -746,6 +746,8 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla > > extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags) > > __realloc_size(3); > > extern void kvfree(const void *addr); > > +DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T)) > > No need to check _T before calling this, right (as was also pointed out > earlier). Well, that does mean you get an unconditional call to kvfree() in the success case. Linus argued against this. This way the compiler sees: buf = NULL; if (buf) kvfree(buf); and goes: 'let me clean that up for you'. And all is well.