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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0760C54E68 for ; Thu, 21 Mar 2024 16:27:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CA6B6B007B; Thu, 21 Mar 2024 12:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 452826B0082; Thu, 21 Mar 2024 12:27:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31AB66B0083; Thu, 21 Mar 2024 12:27:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1FD0F6B007B for ; Thu, 21 Mar 2024 12:27:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EEC7AA0A15 for ; Thu, 21 Mar 2024 16:27:00 +0000 (UTC) X-FDA: 81921575400.19.550DEF0 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by imf08.hostedemail.com (Postfix) with ESMTP id 770E5160004 for ; Thu, 21 Mar 2024 16:26:58 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=b4U6X2pe; spf=pass (imf08.hostedemail.com: domain of przemyslaw.kitszel@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=przemyslaw.kitszel@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711038419; a=rsa-sha256; cv=none; b=qegFEK8BmfgRfY8pOTm5N3V+eyNzyDF3hV/BtVwZ1X0DVlFqCeo8r48j6bqOBqdWjzEVtw lq2xlgqZybTv45ddiQs9Fc0lo6Q87YOPdGHLuQilQolWl9maRJWAMGm6C5wrGVfb6BGA3A Wx1TCFZOQlci8jUqPeRDCtQ9mtJ+R8Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=b4U6X2pe; spf=pass (imf08.hostedemail.com: domain of przemyslaw.kitszel@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=przemyslaw.kitszel@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711038419; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sK49JlcN1XbxGg89E8y71B45lAOhKaor6wAte6Tcze4=; b=Var6EdgkpdSuwfeoz4ldt8L1tWCYhTNbPHrLii+Sni7cgpUrMxJoXzZkrQx75UYyH7e/YX 7o+Dh3ZTT2s3l+MAuiT3VzUJZlG/J3NonglYRb05O6gsnv3icT3cJJqBR8B6THJ177kmjT HpJcbWpZu3xtL+J0N+3efBVux4vTxfg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711038418; x=1742574418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D7HGVSLVQqGuARtC5/0x7M5RBu9MLX3psyFHyMMmHxs=; b=b4U6X2peIZ8y4tYwhdbhE5R+riN0qCc8+z1N6ffX98GBiHPbJJrUY+lp DURsdoQs05I57uIylS5Kvi7w0AbH6mXcFYJ0mcrr9SpnP0AOhmtOi1NZL JWdOS7eZ+ZRQ5+1ByEXov6FKsfPG51sqHJC1bIMo9D9txMIdqko3FBbC9 2/5M7kZgSJpvasacFHuEcnTXUCIwTXDeE1y6vKzt0GOWy7NlCLDwm9BC8 m7kZgcBMdtfGpOozgzgsoT540ron2igGdI5cyshqHhKNSmgGkh0UhSNvt o0knm2T2C4dwxjUWzTJxZccFGBGTwHk5JprYw6qXuJBBIEyRMLc2iuJT9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,11020"; a="5875244" X-IronPort-AV: E=Sophos;i="6.07,143,1708416000"; d="scan'208";a="5875244" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 09:26:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,143,1708416000"; d="scan'208";a="52010322" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by orviesa001.jf.intel.com with ESMTP; 21 Mar 2024 09:26:51 -0700 Received: from pkitszel-desk.intel.com (unknown [10.249.142.68]) by irvmail002.ir.intel.com (Postfix) with ESMTP id B9AC42819D; Thu, 21 Mar 2024 16:26:48 +0000 (GMT) From: Przemek Kitszel To: jiri@resnulli.us Cc: 42.hyeyoo@gmail.com, akpm@linux-foundation.org, cl@linux.com, danielj@nvidia.com, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mingo@kernel.org, penberg@kernel.org, peterz@infradead.org, rientjes@google.com, roman.gushchin@linux.dev, vbabka@suse.cz Subject: Re [patch RFC] mm/slab: introduce KZALLOC_FREE() cleanup-ed allocation macro Date: Thu, 21 Mar 2024 17:26:48 +0100 Message-ID: <20240321162648.23693-1-przemyslaw.kitszel@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240315132249.2515468-1-jiri@resnulli.us> References: <20240315132249.2515468-1-jiri@resnulli.us> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 770E5160004 X-Stat-Signature: w5yptnopfu3x3cxna7fxd5r6swx57euc X-Rspam-User: X-HE-Tag: 1711038418-403029 X-HE-Meta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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: > From: Jiri Pirko > > With introduction of __free() macro using cleanup infrastructure, it > will very likely become quite common to see following pattern: > type *var __free(kfree) = kzalloc(sizeof(*var), GFP_KERNEL); > > To follow the CLASS() flow from cleanup.h, introduce a simple macro > KZALLOC_FREE() to wrap this over and allow the same flow. > > Show an example usage in gpio-sim driver. > > Signed-off-by: Jiri Pirko > --- > drivers/gpio/gpio-sim.c | 3 +-- > include/linux/slab.h | 3 +++ > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c > index c4106e37e6db..997237b3d80c 100644 > --- a/drivers/gpio/gpio-sim.c > +++ b/drivers/gpio/gpio-sim.c > @@ -1496,8 +1496,7 @@ gpio_sim_config_make_device_group(struct config_group *group, const char *name) > { > int id; > > - struct gpio_sim_device *dev __free(kfree) = kzalloc(sizeof(*dev), > - GFP_KERNEL); > + KZALLOC_FREE(struct gpio_sim_device *, dev, GFP_KERNEL); > if (!dev) > return ERR_PTR(-ENOMEM); > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index b5f5ee8308d0..baee6acd58d3 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -711,6 +711,9 @@ static inline __alloc_size(1) void *kzalloc(size_t size, gfp_t flags) > return kmalloc(size, flags | __GFP_ZERO); > } > > +#define KZALLOC_FREE(_type, var, _gfp_t) \ > + _type var __free(kfree) = kzalloc(sizeof(*var), _gfp_t) > + Nice, but I would rather see this wrapper in the cleanup.h file, that have all of the rest of related stuff. On top of that, I want to propose also a wrapper that is simpler in that it does not allocate but just assigns null, with that in mind `_FREE` part of your proposed name does not sound right. Most of the similar functions that define or declare something are named DEFINE_STH... (Please CC me on any future version, I have to go, sorry). > /** > * kzalloc_node - allocate zeroed memory from a particular memory node. > * @size: how many bytes of memory are required. > -- > 2.44.0 > >