Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1951882pxb; Sat, 14 Nov 2020 07:50:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXgH2ODDuQklXhpaOiovDAHzUoN/dYymOoYXlmW8t1Sbp316kDwk+yC70yqjhxNVABfcPY X-Received: by 2002:a17:906:14d:: with SMTP id 13mr7052217ejh.516.1605369042788; Sat, 14 Nov 2020 07:50:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605369042; cv=none; d=google.com; s=arc-20160816; b=e778Qvfp4eFPdxHHEaMNdntP8DYgq47JuZBmZJdKVdbskyZym6oQI91bJumob2iWd+ ldpyAvRPF6LqWffwApwktcj0zKy/AMnTxL/fPvTJRmZhH4apCMBUiuQVsVUr1rFM36bK Uu0Jqbu5kpI4oJ3AdG/axvoL4REz03icD7nsWZXl3womSF4TriMTm80T/bjqSN8Mb7US b4MKSoeDT5ipxXSPW2VCXMfBDekMoG8exqdEtCB7KORxVMF1W2XqiU/QPRA+GJJUKir+ kg1qFh7lmnV2+I7lXa9WaRVMvzMZZrcTd/pracLoFKg+CCtI7RAEG7c0LR/FRCwpyPld pYoA== 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:subject:cc:to:from:date :dkim-signature; bh=r/0uERQAPwUWid8zMxgaAlwUYBGTStt9PeI4aZCFsq8=; b=BA26MmFE0X1EP9IcKeAjwzqDDOW554f5/Tf4cC1KRyaRadShNJvk5XmhZ+epGvbvqo ioI2pq0w4aGe6i9Ffkr40Pw0oty9oHgBU+rddWrgW57U6US8vOKyj8u/CleoLCfxAJqQ myXhWRK5wcf6nWY6dnAyot7sZXgsKQJsLhxAYj9SLrWKR7mXulOu4DTlc+UPU/3iSm42 ZAiJj4PZM/oH/wyRgdMAm2NGVD6cQVsDJIWQlv6QxxP2lMYSuKWXcR9dL+cT1v21/B8T 4Z3TljQal9/sFanK3sDl9KYbTV6p5EyJW4HCSvLh9evNa8UrV7fLkLXuWj5d1YABPRcI O7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TwG4XwTi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si8195551ejv.717.2020.11.14.07.50.18; Sat, 14 Nov 2020 07:50:42 -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=@kernel.org header.s=default header.b=TwG4XwTi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbgKNPqr (ORCPT + 99 others); Sat, 14 Nov 2020 10:46:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:50858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgKNPqq (ORCPT ); Sat, 14 Nov 2020 10:46:46 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69B4522254; Sat, 14 Nov 2020 15:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605368806; bh=goHaolbjw30a+EKdHtSQX6pyt5XC1BydKi65tudi8MU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TwG4XwTitBBCcrpR8+kmM/0aTv9tvgTIRPnygVP4/I5RGNYKJKN0Tf+yP5idzt2aR HqYVW1XDcVYksnkogG7/mUPcwya8GXjbPxTQ/hhe6GnekdZ/Y0LTpaXZob8uiLnWrr 1TYS+w1rkbhw/yDwc3O3iZjxCHLspQQVYarqU250= Date: Sat, 14 Nov 2020 15:46:41 +0000 From: Jonathan Cameron To: Bartosz Golaszewski Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , gregkh@linuxfoundation.org Subject: Re: [PATCH v2 1/4] device: provide devm_krealloc_array() Message-ID: <20201114154641.0258f4ee@archlinux> In-Reply-To: <20201102142228.14949-2-brgl@bgdev.pl> References: <20201102142228.14949-1-brgl@bgdev.pl> <20201102142228.14949-2-brgl@bgdev.pl> X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2 Nov 2020 15:22:25 +0100 Bartosz Golaszewski wrote: > 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 +CC Greg KH. As this is going into a very generic place I'd like a relevant ack. That file is a bit of a wild west for acks, but Greg seems most appropriate person. So Greg, any comments on this one? Thanks, Jonathan > --- > 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) > {