Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3339491pxx; Mon, 2 Nov 2020 06:28:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWRWA6TFM5OuyNbE/NYIzQzsdi/QT95CN/OV/v4WZNHIkGVMUO66ILmPz56lzBuJzqFB0T X-Received: by 2002:a05:6402:1c8e:: with SMTP id cy14mr10680848edb.39.1604327336005; Mon, 02 Nov 2020 06:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604327335; cv=none; d=google.com; s=arc-20160816; b=jWELLans1feqGqL4MW3qIzRiJkxL6v3H00UXYvaINhEsyxKUKxhVzp6Pj2jmbsBDGm OUINCfk1fAtbmOp0cFf+HhdPa0rnPAaE3DFfTbiXJ4xtDAZ26Ktbv729348ue8Wis4kH ME2fMR+qgGxAVHCPNHdtnFhGbpkXMi+GSq/0jW1KGXrSpmkp7kddY5HtfmEq+j7mhjBV K6TnzSCDgGf/ChYfsPXLUZB+T/TNS6jdppUQ5vyU5QTCM4oeIqHKH20NfOZqq6fNQ3LI Gt07MNLgh1h+/FsecFK4YRlCa87I15+CU56gpV6Bwyd7dIHYDnImr2s5bfnamIETDYdw W5Hg== 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 :dkim-signature; bh=Jw3oq9QTE7nFTaO8GB8D/I4qCpQ+Kq8IawJXBfxGxQ8=; b=ps6kISOcI4xqFUojS6EnERh8jVW2mnNxFQRB2hkn3LHIMcrIsyh7DOJj2zrdU5BwID JJzjNBn8hpRWyo9O9HcPowWR2KjWTgiGhJa34Oeg0yHOzAsVjh4UtdbJT7H+bFWqQw+C cq8M/NOMhxjjSERwNo3sSfkyX/ladF8QX6IP9oFJnnQOsozJHbtmBq9kmAsCes9zY94P x0XRVtJG9yh1cAmSCD7tgdXFNAXp0AjrWn+Y/GhMZtIMXrR0RA4FQ3Bfv46FiGQpX40T rSMvZ6hiZsk8BBJrxdksTltJVXxo/p4rs11jeWMyNRJcPw/ZQMBTeFR9/AZjgcIjNuhx 5jZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=htAF5Ujg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x7si3871866edr.509.2020.11.02.06.28.33; Mon, 02 Nov 2020 06:28:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=htAF5Ujg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726167AbgKBO0V (ORCPT + 99 others); Mon, 2 Nov 2020 09:26:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbgKBOWf (ORCPT ); Mon, 2 Nov 2020 09:22:35 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE28AC061A47 for ; Mon, 2 Nov 2020 06:22:34 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id x7so14840710wrl.3 for ; Mon, 02 Nov 2020 06:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jw3oq9QTE7nFTaO8GB8D/I4qCpQ+Kq8IawJXBfxGxQ8=; b=htAF5Ujg6yCl9eqYEVMVTYCl4kGp3ZTnkUV9UbXU9g8dU+97BuZIfMHctZHTz0z0iw 3eeHUCRmY8CY6eXn1cDdvLdt+IN29epMqgLCrzN+vh79zTaxv2xPgxDqSO0vH5XTJUcT uUZiGkBOEP+VgLPnP9/BvaBT0yvVKQWomOnkUC7OZJUyWRpMj8ozdkZdC++M0csjtDhg G+hSVlYLvT3l0jnZaioFiFNdMmwIUzI/gRoZgrDigurfpQRk25DlBetOiCQtEgLwlH1I EBRWmy2aF7gaNgRBK0IcpKqT8Seoyx0RZc5wln1sAOFpvOfIYtdWwsU+GUDBNT8syjpt S6UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jw3oq9QTE7nFTaO8GB8D/I4qCpQ+Kq8IawJXBfxGxQ8=; b=tooDTr9QXmmzi3avpKsxwWfYtqJwp9DNJFSkfJdm3pKMIl+l0oVyTP2mgcBDUCuuSO 0Q69LAgxHyzy+CIciPoehMcMiNw0sWggH1asDpd3qNQzjDy+TwQ8VqYR/edwm0u+C1eD ETVLGiBo7aBXUO614uiLTA+40E2xIIheU9kPnXElT2Ax7axZkFv5h3L3sIuU2pizZypQ RisZYBouecZieG+6b5E7fE43yHywnMRHVoi2Kzoa13woJO/XP7ueLu/N6YZVjgqXhKjE jQUK5zjxuABNGQZD+i3N0zq6JYfy4lLP5QA5udtrd42FmLgnut22v5Haup6zUG8RyM2A /7Dg== X-Gm-Message-State: AOAM533eEwRg+CJkYgeKwxgTS6NyC+vfDZeL1soq/HkyNTg2MQxekcgb HBKIDvOmtKOfuxLL2X8n7//wQg== X-Received: by 2002:a05:6000:142:: with SMTP id r2mr14427807wrx.155.1604326953520; Mon, 02 Nov 2020 06:22:33 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id 3sm16182987wmd.19.2020.11.02.06.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 06:22:32 -0800 (PST) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 1/4] device: provide devm_krealloc_array() Date: Mon, 2 Nov 2020 15:22:25 +0100 Message-Id: <20201102142228.14949-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201102142228.14949-1-brgl@bgdev.pl> References: <20201102142228.14949-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski When allocating an array of elements, users should check for multiplication overflow or preferably use one of the provided helpers like: devm_kmalloc_array(). This provides devm_krealloc_array() for users who want to reallocate managed arrays. Signed-off-by: Bartosz Golaszewski --- include/linux/device.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 5ed101be7b2e..e77203faea55 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -226,6 +226,17 @@ static inline void *devm_kmalloc_array(struct device *dev, return devm_kmalloc(dev, bytes, flags); } +static inline void * +devm_krealloc_array(struct device *dev, void *ptr, size_t new_n, + size_t new_size, gfp_t gfp) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) + return NULL; + + return devm_krealloc(dev, ptr, bytes, gfp); +} static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags) { -- 2.29.1