Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6585336rwp; Tue, 18 Jul 2023 02:47:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlEtfA3G2MOI3UixpAsDjb+kN2em0oXIUTRCimLE/CVd4jk+KxcSSdlY1HAxJlW7PSGbTBy+ X-Received: by 2002:a05:6a00:2411:b0:681:4726:2975 with SMTP id z17-20020a056a00241100b0068147262975mr14305223pfh.7.1689673670162; Tue, 18 Jul 2023 02:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689673670; cv=none; d=google.com; s=arc-20160816; b=izQ/6UBRIBB+geqzp7bS9ujAWoYkwep6lbFQvyZ+CluVaz7HLirZ82sYGlnnvInPEB 6JCNvTuqQdyFbe23za2hZZrPJuTSF3MO5u+o9Ty8jHDdb6U44a638agZF6urhg5fgHzM 1hZAUBCikvQqRo+m0U40h8JBd6W2HqkkYF+JOjm8wjyp/uyG/cnOWYZnU6vZisNQHI7O Kq0r1NCarhnuCypU5FZx9djeNxfWU38wyybfXKXkQ/r9eRXpPl9cQOuC/e66Qzwcf779 Vt7xEkUlzdxC5uvMuFBsne/+4Ah8B4iE+D64Ld0ZOBBokYLDLr1aTwmAUKS86bN+RSqu LT+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wMPZm18GVVIibQKQ6xh29CFwbcIj8kHzRGjqF9oTRCc=; fh=EGRoNRtgaiBqdPqwJCj3M9D7jnCUDmzfReXXTqOmf+A=; b=bCOn0NDWg7H/Adxmft1J/c96NLeDSy/S+gCuIaVLKWxFSndS4VY1aDzAw8rjqsPa6g +ayoDFMLWPI29C6GhlLDQZ1kUc7wwPfDbTve3zF7UjMzSwKQu+Y2MA6iPHnJ14Zhu4AK UmHHRwFAkVlpMUlM6AKGlcT2JycxGBIoAEcjrfB5CJXMYovfWBlzTlrrZKBDfbWBiVx5 hVUHhur3CWgg+HlfksfVQBGpIahnh8vaStwPFvZHnUPYnkq76EQ0IUqL5loolOT78J9z mg51S22toUXTZQP3291doaBXQmG1GGocMidvByeN9fxUPqwTgI5UmYxTBEzAr4+hAXYz Nulw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a63ea54000000b0055799d9b4basi1311931pgk.893.2023.07.18.02.47.37; Tue, 18 Jul 2023 02:47:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbjGRJZy (ORCPT + 99 others); Tue, 18 Jul 2023 05:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232211AbjGRJZo (ORCPT ); Tue, 18 Jul 2023 05:25:44 -0400 Received: from 7.mo562.mail-out.ovh.net (7.mo562.mail-out.ovh.net [46.105.55.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD73E5F for ; Tue, 18 Jul 2023 02:25:41 -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 5D96D23012; Tue, 18 Jul 2023 09:25:39 +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 ; Tue, 18 Jul 2023 09:25:39 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.11]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id E9E952011DD; Tue, 18 Jul 2023 09:25:38 +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; Tue, 18 Jul 2023 11:25:38 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v11 1/5] devres: provide devm_krealloc_array() Date: Tue, 18 Jul 2023 11:25:23 +0200 Message-ID: <20230718092527.37516-2-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230718092527.37516-1-jjhiblot@traphandler.com> References: <20230718092527.37516-1-jjhiblot@traphandler.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: DAG1EX1.emp2.local (172.16.2.1) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 6526560288548993415 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhruddruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehiedv X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.34.1