From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935134AbcIVQz6 (ORCPT ); Thu, 22 Sep 2016 12:55:58 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:41111 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935051AbcIVQzz (ORCPT ); Thu, 22 Sep 2016 12:55:55 -0400 Subject: Re: [PATCH 1/4] GPU-DRM-TILCDC: Use kmalloc_array() in kfree_table_init() To: SF Markus Elfring , , David Airlie , Tomi Valkeinen References: <566ABCD9.1060404@users.sourceforge.net> <2f3f7ad7-16a0-1dfb-d073-0d993cd767ee@users.sourceforge.net> <7c0f291e-e05b-1fbe-05a4-54c104829942@users.sourceforge.net> CC: LKML , , Julia Lawall From: Jyri Sarha Message-ID: Date: Thu, 22 Sep 2016 19:55:36 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <7c0f291e-e05b-1fbe-05a4-54c104829942@users.sourceforge.net> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/22/16 11:31, SF Markus Elfring wrote: > From: Markus Elfring > Date: Thu, 22 Sep 2016 09:05:14 +0200 > > A multiplication for the size determination of a memory allocation > indicated that an array data structure should be processed. > Thus use the corresponding function "kmalloc_array". > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring > --- > drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c b/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c > index f9c79da..8faa28f 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c > @@ -32,8 +32,7 @@ static int __init kfree_table_init(struct kfree_table *kft) > { > kft->total = 32; > kft->num = 0; > - kft->table = kmalloc(kft->total * sizeof(*kft->table), > - GFP_KERNEL); > + kft->table = kmalloc_array(kft->total, sizeof(*kft->table), GFP_KERNEL); I was not sure if it is Ok to call kremalloc() for a pointer that was previously allocated with kmalloc_array(). And at least it felt pointless. But if you can confirm that it is ok, then sure I can take the patch. Thanks, Jyri > if (!kft->table) > return -ENOMEM; > >