From nobody Fri Dec 19 17:56:19 2025 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 4CCC8C6FA8F for ; Wed, 30 Aug 2023 20:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240226AbjH3UBF (ORCPT ); Wed, 30 Aug 2023 16:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240399AbjH3UAj (ORCPT ); Wed, 30 Aug 2023 16:00:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648257D263 for ; Wed, 30 Aug 2023 12:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424193; x=1724960193; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=igrcA3q8KN5WrWYA/jTLGNsZx4aaW/jLTGUAudQ8oU0=; b=DtqfTekGxhkqsTmhtppYugPo1njhTMnGpmleVlTB5dJx3KWfmTv4vQXX VfWM0lNiwRbikeYguENReYVcIYsSKbhDCK4WVkMZbAR83XgnpsfNLFMKb R6qxJ2Me5g4duqGOg+1XPBzl855u18T0jpO4yIpumFDa70a4O9DifJ/Po hHxSgWYSvjMtE7yMOZ0zOUuw/cVIhl/Y/lsrpx2q+W640OACGd1CKhTpE 7VvKLto/akGMtw7/QwW4PjTFSRnnOp+ig8TX63FXjXTO6P5cbN7S22CiM 05tTQ690btCrB52QpoGv+WhDPi8dP8bKEzMIhc+lCL3v/Y1Mpvyyw0KkK Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723668" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723668" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844876" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844876" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:37 -0700 Subject: [PATCH v3 4/5] mm/slab: Add __free() support for kvfree From: Dan Williams To: linux-coco@lists.linux.dev Cc: Andrew Morton , Peter Zijlstra , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:36 -0700 Message-ID: <169342401666.3934343.5520453508283712955.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow for the declaration of variables that trigger kvfree() when they go out of scope. The check for NULL and call to kvfree() can be elided by the compiler in most cases, otherwise without the NULL check an unnecessary call to kvfree() may be emitted. Peter proposed a comment for this detail [1]. Link: http://lore.kernel.org/r/20230816103102.GF980931@hirez.programming.ki= cks-ass.net [1] Cc: Andrew Morton Cc: Peter Zijlstra Cc: Greg Kroah-Hartman Signed-off-by: Dan Williams Acked-by: Greg Kroah-Hartman Acked-by: Pankaj Gupta --- 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)) + extern void kvfree_sensitive(const void *addr, size_t len); =20 unsigned int kmem_cache_size(struct kmem_cache *s);