From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD7BBC63699 for ; Wed, 28 Oct 2020 22:21:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88A41206E3 for ; Wed, 28 Oct 2020 22:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603923677; bh=QEXxMmSUj2Vd+E59vReAFx2mSILQlDhT0GF7L4nT79k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=sROtWWCdD7cDe8R42NxEp8w7dFsUtZ04pNIlLrlxscYhf10Dp940IL02QsOHRbwo4 HMgqFN+hZFr+lN+xqp9uvY/2JG/tQeLEAJrLKx2bLDZwFjKBg/2skUky0tqd3uBQMO /yIWJhBgAUrD3xsFUqBo6PP5j/vrQ3CGrlcJISc0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732482AbgJ1WVA (ORCPT ); Wed, 28 Oct 2020 18:21:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:60504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731664AbgJ1WRk (ORCPT ); Wed, 28 Oct 2020 18:17:40 -0400 Received: from kernel.org (unknown [87.70.96.83]) (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 50EBD2465E; Wed, 28 Oct 2020 08:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603874836; bh=QEXxMmSUj2Vd+E59vReAFx2mSILQlDhT0GF7L4nT79k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qaRJrHspISAML2s3M6ow+As8fnofPQBijjHMbHMdR+I3658FQOTlnTwjnXNz0MlyX aAw8A460MACJ1IDHW1x+02Uv9Atn0b3fP/Jb97ArZSIbrkmzQ92h9/ls1ePhoOhjJH 6jiwMskK6vWDnhTMrSRMXIc62N90Wg6wJ7a8TvRg= Date: Wed, 28 Oct 2020 10:47:03 +0200 From: Mike Rapoport To: Bartosz Golaszewski Cc: Andy Shevchenko , Sumit Semwal , Gustavo Padovan , Christian =?iso-8859-1?Q?K=F6nig?= , Mauro Carvalho Chehab , Borislav Petkov , Tony Luck , James Morse , Robert Richter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Alexander Shishkin , Linus Walleij , "Michael S . Tsirkin" , Jason Wang , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Jaroslav Kysela , Takashi Iwai , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-gpio@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-mm@kvack.org, alsa-devel@alsa-project.org, Bartosz Golaszewski Subject: Re: [PATCH 1/8] mm: slab: provide krealloc_array() Message-ID: <20201028084703.GC1428094@kernel.org> References: <20201027121725.24660-1-brgl@bgdev.pl> <20201027121725.24660-2-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201027121725.24660-2-brgl@bgdev.pl> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 27, 2020 at 01:17:18PM +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: kmalloc_array(). > > There's no krealloc_array() counterpart but there are many users who use > regular krealloc() to reallocate arrays. Let's provide an actual > krealloc_array() implementation. > > Signed-off-by: Bartosz Golaszewski > --- > include/linux/slab.h | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index dd6897f62010..0e6683affee7 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -592,6 +592,17 @@ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) > return __kmalloc(bytes, flags); > } > Can you please add kernel-doc here and a word or two about this function to Documentation/core-api/memory-allocation.rst? > +static __must_check inline void * > +krealloc_array(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 krealloc(p, bytes, flags); > +} > + > /** > * kcalloc - allocate memory for an array. The memory is set to zero. > * @n: number of elements. > -- > 2.29.1 > > -- Sincerely yours, Mike.