Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13544153rwd; Sat, 24 Jun 2023 02:09:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ceczMq6rJ7nkV4wDznY2gaUtiC+YWxT1v2tsfKz4nWDNSf9XqFWDWZHJFuI/zKNF6SdY9 X-Received: by 2002:a05:6808:1390:b0:3a0:5772:e204 with SMTP id c16-20020a056808139000b003a05772e204mr10253225oiw.35.1687597762609; Sat, 24 Jun 2023 02:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687597762; cv=none; d=google.com; s=arc-20160816; b=KEG0jxMnOdwOwzFw/Qw/Z+mZOvOo9YFT8Ji+YfgtnEgjOxVDciWq+fJHny4xzzwnBO 2TRatjubR5EbgDod3MQKKaIqvWPgPoI0ezn9/cLQoaQFpcaxbieZiJQ1mYfvQUKLLz4a 2W1qRJipzMgqLles3mvgq7xkUElhurULmGqoAc7MOJUUdPDyyt8DeoeLw7WI1GdNXS0Q RkeVLGGox+Bg0QHXJCUekp9asUeNLFgenXMcUI/vWHHTWwg6l0eC6e6k44hxNfkRR8ny YytZOXKd2ADxPsIugQ8KVNQq9TONZCKTAEATD+mRa/BbWpcgeIMVObLKDoBpD8TlK4yF nlTA== 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=Nth8QeOoSsYrDungiTCJAFNyO964yBoXQVDGwhneIeA=; b=IRW3oc0PFD5a1kXPxNEZe8zOEQ0IU9HMP4EcR2dm9YrCanG//4taoCBECmw1mEXmLQ R4q2d8RVdT0EVpNRty+ZhY1+bvZmK7I3egnuziW07E/0AblaqnQCsytttJGrZexyNURH wMceoqL7hBdj9a7z6QpMrOFDge6oZlp+MgFxFTPR3d4OrcefqPTFbm6dF9+Vh5ciW+3h K0onuuBJ7feqbynTMVq1rJNbzTVwPl0mUVjywIBx4DstlJc3BLVelqka4ef5+Tge8orz dQpNbXTeAf929lkVEFIuelqB/TEqtqYkEdvaymyKJZkytX3ZODSVU+GXZydIibCrnW+E T04Q== 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 s13-20020a170902ea0d00b001b506f5c284si996811plg.425.2023.06.24.02.09.10; Sat, 24 Jun 2023 02:09:22 -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 S232037AbjFXIml (ORCPT + 99 others); Sat, 24 Jun 2023 04:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjFXImj (ORCPT ); Sat, 24 Jun 2023 04:42:39 -0400 X-Greylist: delayed 139001 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 24 Jun 2023 01:42:36 PDT Received: from 10.mo563.mail-out.ovh.net (10.mo563.mail-out.ovh.net [46.105.78.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79253E41 for ; Sat, 24 Jun 2023 01:42:36 -0700 (PDT) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [51.68.80.175]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id 2B96422EDB; Sat, 24 Jun 2023 08:42:34 +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 ; Sat, 24 Jun 2023 08:42:33 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.143.168]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id B8D842011E7; Sat, 24 Jun 2023 08:42:33 +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; Sat, 24 Jun 2023 10:42:33 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v10 1/5] devres: provide devm_krealloc_array() Date: Sat, 24 Jun 2023 10:42:13 +0200 Message-ID: <20230624084217.3079205-2-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230624084217.3079205-1-jjhiblot@traphandler.com> References: <20230624084217.3079205-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: DAG2EX1.emp2.local (172.16.2.11) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 12427964647960492423 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrgeegjedgtdejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppedtrddtrddtrddtpdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopeguihhrvggtthhorhdurdguvghrphdrmhgrihhlqdhouhhtrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeife X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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