Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp45453lqb; Fri, 15 Mar 2024 14:39:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG2is4D2Ynx3So8F9sffnAJLOJqBcuuigdEsXz4n2NsJkeYLpsumtK0A+Anr74px7Ms0uk4YLOuMNXzeFQwnrlox56EmAR8xXraKwd/Q== X-Google-Smtp-Source: AGHT+IEaLUTSlGHNyc0vZ0xljb4pGnd8tvsRJniL5EgDmcUQqdM4nH2nj1mNBHWDkZyoosc8g4XR X-Received: by 2002:a17:903:22d0:b0:1dc:fca8:f9b with SMTP id y16-20020a17090322d000b001dcfca80f9bmr7472658plg.3.1710538757469; Fri, 15 Mar 2024 14:39:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710538757; cv=pass; d=google.com; s=arc-20160816; b=S/PiIMvX8i22fGENifvhD6pocp7hMDRT3E+7w1sKH5bwayjO17VXzktU4PCeM7MNnE piw31OMGjVe1RPGjlD81fWDmiOnIjPKJGaCiH2tV+ezPSHQ9X9eeoiXGlEUqpz2mGTPF RaQnzioLbco83HU/2t3pYjSYQuXuftqaNdXMASWnuQCyo9bsHdpxvKl2iPx62xzcPvgu XNfd4hI/LlDd3k9kWiI2XNYQXm6krYUAgOSbS4gqXu5v23wDS5PTA+IPLwMGegNCWm6w xybQYOtlUUk49zt7po58LfuFmpSa++eVYP0xZuYDYjWFC3eMyfSeB0XruF1nU4KL7OGe YiXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=F4UFAX4z3jJDBCRUy6WDZJz3SsJI5lq7JeGg/ZMI7/c=; fh=aGBwh4Wfym3j9N8LX3Azj7KQUqJ00l1kES4vsqNngE0=; b=XD68ecjDaRYpALWxYqt+SdKg4S/pdpzcDOKRq+b+0bJdpJpTYShRhBsznbTqe7gvAk +ESdq05URYrqS3NDTGOAj4an4iTdbDBkYAAghAE/2ifhgU/8DJPCCuvOemhoerYrLryc CTIckbeUTkNSG5PTskET+XV7qHmNVLHLhDE1R4l3AgTOabRDj4L68sxCAKAUI4p81OGM Mwx6G4L4L8f/V+fwDYrSz4QteclJK4qZVxC0cp03HktyVd5/eIQDMTLWeZ5ydo79LPff zlBzKFwgBmKm+rwYSPkB5q35pgVLZZ1lc9uCTxgcDkIcIx53uJP3ST6bjODWk+rVVnor +L1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jjcCyFg2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-104947-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104947-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k2-20020a170902d58200b001dda236d9acsi4419572plh.407.2024.03.15.14.39.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 14:39:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104947-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jjcCyFg2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-104947-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104947-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A4C47B21C9E for ; Fri, 15 Mar 2024 21:39:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A803B5491A; Fri, 15 Mar 2024 21:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jjcCyFg2" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02E8154908 for ; Fri, 15 Mar 2024 21:39:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710538747; cv=none; b=X2hmJ0m0ybhm6jvxrPQLfnOrA4QXzpbPpSMhx1ERS/Uz+ZDrDXM/5gU7UcsYH3ymEJGBeunsYVDFeiD7lQW/YxpqU0m/+uWmUMJe7DcJDhfrNVPcXjDOMQXc0XubDkNK7cmQN0EUn6WbabK4RoaqSWSpcSB1S4Wcem/XeTjnaYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710538747; c=relaxed/simple; bh=RmGZydm8dUms/pt/l8u+2Hq02hkxE9ZbOrRu3WhgwMU=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=ZwZH14SkeC9dvVRwZZmirWu4rsJYZ6YF96ZhLtiTalX7rXdxjRD98u9VecQ97n7vLs05dAI3Z3c6oSYdRns14EmKz/T2AtI3dADbt7GbTHBl/IbLlwB74XPs+SByFAGNC8WXfCohtsaAHhDz4eue6QiaMWCNNglPpoVmHqKv1aE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jjcCyFg2; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1dddd7d64cdso15675ad.1 for ; Fri, 15 Mar 2024 14:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710538744; x=1711143544; darn=vger.kernel.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=F4UFAX4z3jJDBCRUy6WDZJz3SsJI5lq7JeGg/ZMI7/c=; b=jjcCyFg2v4nCmxyKMaX6thYg7uu94bxZEc3p1iB/Anzjry+XlZiHMIA+P/bgjWEi0/ LLdwd2kvdrlpfAx6peJzCPHDqmQoo2VN5aqMliQ3iY6UGwWzMbf5YemgfhfNjpfOmPCC l3dGNUy7eSl4JSiz6QP1/vh1bQ5QPJfuQdg0pu+L7toQaRaya70oqBs7khhxRIhOOnVy Z9hiRZx9WsomHjxCgiuP5/8gCLVwaxO4jXDKq02OGbJ3AED8gk0XIDn+nmw1vglUmC5H oE4XOI3UV1sZM5Ldodh/jl2zupgFC9O31hevAs+PAzyQVHCZJmfXRtiQ1BbvgidiauFj vHIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710538744; x=1711143544; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F4UFAX4z3jJDBCRUy6WDZJz3SsJI5lq7JeGg/ZMI7/c=; b=RCNy9/zQPSnevbOmRQvVMO6/1xcj78CdJtXX8YjoZQgDzaqcKhPN5KNJEPwvEsn1z8 FCX4lmDZMeyvHDsAXPLNINzOeyYHkeaMXEY68V/PfehqjtZ59jknCcU6OfVkAXYOModa AHdsMAU/sdTxIpCohMMKFwsWV3CPrEo72CdGY2mWVReN75c7sk6v7iYKHMrAtr3AGCcu EQW1JYyIOkRVm+ycYGa66n1m/v/SvEfsfoOrHcR+UiEYj5vPFoVGPhvC4rU+FkhqjzAh lpv5P7jqP7Q1qr80VL+0obSTKzOdNZrF4+OczuoqVcvvZYJ8CJGMEW9JbN7+qgPLXTY6 HyLA== X-Gm-Message-State: AOJu0YxZqsUXY1UzV7R7TcpaYWI9gofK854v7N70cIae5zr+jl/Kty83 xABE935u2ZsljT9pm0I6QqLGlQblHMVnKxzicov8UNYGW2X2Ao/ePbGYXB3vZw== X-Received: by 2002:a17:903:1c3:b0:1dd:b2f1:6e9 with SMTP id e3-20020a17090301c300b001ddb2f106e9mr314272plh.1.1710538744032; Fri, 15 Mar 2024 14:39:04 -0700 (PDT) Received: from [2620:0:1008:15:59e5:b9a4:a826:c419] ([2620:0:1008:15:59e5:b9a4:a826:c419]) by smtp.gmail.com with ESMTPSA id l9-20020a170902f68900b001dd90001b26sm4345543plg.159.2024.03.15.14.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 14:39:03 -0700 (PDT) Date: Fri, 15 Mar 2024 14:39:02 -0700 (PDT) From: David Rientjes To: Jiri Pirko cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, peterz@infradead.org, mingo@kernel.org, danielj@nvidia.com Subject: Re: [patch RFC] mm/slab: introduce KZALLOC_FREE() cleanup-ed allocation macro In-Reply-To: <20240315132249.2515468-1-jiri@resnulli.us> Message-ID: <171412ef-1a93-3e56-2b7b-3baf83233eb2@google.com> References: <20240315132249.2515468-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Fri, 15 Mar 2024, Jiri Pirko wrote: > 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. > Seems highly specialized especially for kzalloc specifically, so not sure this warrants its own macro. > 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) > + > /** > * kzalloc_node - allocate zeroed memory from a particular memory node. > * @size: how many bytes of memory are required. > -- > 2.44.0 > >