From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6451C05052 for ; Mon, 14 Aug 2023 18:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231689AbjHNSpD (ORCPT ); Mon, 14 Aug 2023 14:45:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231721AbjHNSov (ORCPT ); Mon, 14 Aug 2023 14:44:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7486199F for ; Mon, 14 Aug 2023 11:44:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 869BF629E5 for ; Mon, 14 Aug 2023 18:44:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F27C433C7; Mon, 14 Aug 2023 18:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1692038686; bh=LEuGpdKZpA8/+x9gfEcRV35HQ0BKOWtN4ZWuxG+F7EU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H2dnfqsJuLn/jmcKvc3pqBB/Igfw+P5XPRRSEw9tO/PmZRKXV3tF49ukrzxqlAY6H 582Mf+7xYJWsYDx8xUc4PXgV789jx6Ve3LXT8SRGw3fZqMhB4GcJnC5VJXJ7ranB+a 884DDsAZNfBl5MBCDep+IE+qxwhQvc3B82qKztOw= Date: Mon, 14 Aug 2023 20:44:43 +0200 From: Greg Kroah-Hartman To: Peter Zijlstra 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: <2023081434-stoppage-fracture-9812@gregkh> References: <169199898909.1782217.10899362240465838600.stgit@dwillia2-xfh.jf.intel.com> <169199901230.1782217.9803098171993981037.stgit@dwillia2-xfh.jf.intel.com> <2023081449-blurry-bath-248e@gregkh> <20230814161731.GN776869@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230814161731.GN776869@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 14, 2023 at 06:17:31PM +0200, Peter Zijlstra wrote: > 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. Ah, didn't realize that, ok, nevermind :)