Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5532442rwr; Tue, 9 May 2023 02:53:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FI16uQFqhKyT/sd01fQFY3rZtyKBHHdQO0MgSV2H4XMQqLbegJ1F/uhbI8fJHn6efUh+Z X-Received: by 2002:a17:902:c945:b0:1a1:d54b:71df with SMTP id i5-20020a170902c94500b001a1d54b71dfmr15432929pla.0.1683626030794; Tue, 09 May 2023 02:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683626030; cv=none; d=google.com; s=arc-20160816; b=M44yXE9KUYCwMJ75EWAvzK3iy5kO4xi7H3gwN5D2iYZIPmBqpvOWCdERVCyRYd/uyH pSTsRbjCMdhi5XGexQx02x/KXZEHfJ/BLrCr1/p3uPOrEpD7xdvGizAuRkuEP2rWkzYm 1Ce9TBYihOfUj8IQK4c/U7USDKtMhrlhAMfgmYTaaJAXz0T5w+idpfZJo8JG91/sVQCD /GoNCedTRsARD3iPwb3IiCpboNYbgp8f9N7dmTYLaDuryOv0M39nBHLjsdc6AHF4Xajh kC+yrTxkFaY3QY4oNKPl008OKdGlbKtjea+c5a+z+mPRU3GUb06KDNUTFnZmRZKZOGsd y1xA== 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=4FsE+Rb/ym31wkpFwMb5KEQqfbhCZiGmU415i27HVg0=; b=UDV3EGhk8obXYC6nLAATYNT2O4MHzqhP6J0FD/YfHM86WV4TdW8Y7Vw1Rv6Vsdx4is iEBZsilHSFLvPDVn5p5Nv3Dxgvq+F+XxMhhR1mTfRHexq/spK7ScFSsiBP6IURGP6Pxi 6aH+nLjuGTZ1xpGN5ibARG80BcaWj8ZEISBfTAjfDWOnxO8VzNtXXsJuGsOBLWYEEkpC iFvOuKiH0+WU/sPBPdCfcZQEQ+Ze4XQKkGMNQUef/22tTJgRzg1gTWz2uRm4Y2UbNxJR FdKkG/8594j48YtFExUBvqRok3FmXmzrC8PBXKcEWjTHEH7QINmxRC+eB+pBESKcyEbQ UVpA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a170902f68800b001ab08e28e01si1137610plg.361.2023.05.09.02.53.39; Tue, 09 May 2023 02:53:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234821AbjEIJuh (ORCPT + 99 others); Tue, 9 May 2023 05:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233867AbjEIJuB (ORCPT ); Tue, 9 May 2023 05:50:01 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7997AD9; Tue, 9 May 2023 02:50:00 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A8220106F; Tue, 9 May 2023 02:50:44 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.83.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D40323F67D; Tue, 9 May 2023 02:49:55 -0700 (PDT) From: James Clark To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: linux@roeck-us.net, michal.simek@amd.com, Jonathan.Cameron@huawei.com, James Clark , Jonathan Corbet , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Andy Gross , Bjorn Andersson , Konrad Dybcio , Jiri Slaby , linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v4 1/4] devres: Provide krealloc_array Date: Tue, 9 May 2023 10:49:38 +0100 Message-Id: <20230509094942.396150-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230509094942.396150-1-james.clark@arm.com> References: <20230509094942.396150-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 There is no krealloc_array equivalent in devres. Users would have to do their own multiplication overflow check so provide one. Reviewed-by: Jonathan Cameron Signed-off-by: James Clark --- Documentation/driver-api/driver-model/devres.rst | 1 + include/linux/device.h | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 4249eb4239e0..8be086b3f829 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -364,6 +364,7 @@ MEM devm_kmalloc_array() devm_kmemdup() devm_krealloc() + devm_krealloc_array() devm_kstrdup() devm_kstrdup_const() devm_kvasprintf() diff --git a/include/linux/device.h b/include/linux/device.h index 472dd24d4823..58f4f5948edb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,17 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } +static inline __realloc_size(3, 4) void * __must_check +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