From patchwork Fri Jun 16 09:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 693907 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 9E640EB64D7 for ; Fri, 16 Jun 2023 10:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241228AbjFPKHa (ORCPT ); Fri, 16 Jun 2023 06:07:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244917AbjFPKGz (ORCPT ); Fri, 16 Jun 2023 06:06:55 -0400 X-Greylist: delayed 502 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 16 Jun 2023 03:06:19 PDT Received: from 6.mo562.mail-out.ovh.net (6.mo562.mail-out.ovh.net [46.105.48.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E534422C for ; Fri, 16 Jun 2023 03:06:19 -0700 (PDT) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [51.68.80.175]) by mo562.mail-out.ovh.net (Postfix) with ESMTPS id 4F71323F51; Fri, 16 Jun 2023 09:57:55 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net. [127.0.0.1]) by director1.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Fri, 16 Jun 2023 09:57:55 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.108.20.117]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id E62A81FA43E; Fri, 16 Jun 2023 09:57:54 +0000 (UTC) Received: from traphandler.com (88.161.25.233) by DAG1EX1.emp2.local (172.16.2.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 16 Jun 2023 11:57:54 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v9 1/5] devres: provide devm_krealloc_array() Date: Fri, 16 Jun 2023 11:57:42 +0200 Message-ID: <20230616095746.872220-2-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230616095746.872220-1-jjhiblot@traphandler.com> References: <20230616095746.872220-1-jjhiblot@traphandler.com> MIME-Version: 1.0 X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: CAS3.emp2.local (172.16.1.3) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 3612731326956714375 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvgedgvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppedtrddtrddtrddtpdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopeguihhrvggtthhorhdurdguvghrphdrmhgrihhlqdhouhhtrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeivd Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Implement the managed variant of krealloc_array(). This internally uses devm_krealloc() and as such is usable with all memory allocated by devm_kmalloc() (or devres functions using it implicitly like devm_kmemdup(), devm_kstrdup() etc.). Managed realloc'ed chunks can be manually released with devm_kfree(). Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Andy Shevchenko --- include/linux/device.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 472dd24d4823..e45dc78068b7 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,19 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } +static inline void *devm_krealloc_array(struct device *dev, + void *p, + size_t new_n, + size_t new_size, + gfp_t flags) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) + return NULL; + + return devm_krealloc(dev, p, bytes, flags); +} void devm_kfree(struct device *dev, const void *p); char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);