From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751546AbdALKhd (ORCPT ); Thu, 12 Jan 2017 05:37:33 -0500 Received: from mout.web.de ([212.227.15.14]:50939 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751978AbdALKhH (ORCPT ); Thu, 12 Jan 2017 05:37:07 -0500 Subject: [PATCH 1/3] mtd/ftl: Use kmalloc_array() in build_maps() To: linux-mtd@lists.infradead.org, Boris Brezillon , Brian Norris , Cyrille Pitchen , David Woodhouse , Marek Vasut , Richard Weinberger References: <4a5a265e-96c8-5fe6-487a-92a0d47a91da@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Thu, 12 Jan 2017 11:35:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <4a5a265e-96c8-5fe6-487a-92a0d47a91da@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:GaZvcy/sH5sRBK4DC4gWaKRm2uM+IoFnBae1AkmUsWiDgscehLU lN9/mx0vlttPTjKwPhklWFYMqflWHuMBjWsjTS+f/KoViprDuPJOU8WUc6bfHARZqbM/Lrn iN9BAyBrv+qOmh6uaBwHNXQX0c+0LPIaRlDKi7jgRaGu5GeYymxl21tb/s96FHV0PODmmms sLJU4T6iwEkapsHUc2DvA== X-UI-Out-Filterresults: notjunk:1;V01:K0:zyfb8uXGbXM=:oKlWBb4SXgf/iIo5QoQ9wx GsF65vfdDaai5R27QbeDDS/K+8jHSZeRFXMZWY5BVerdVU2OTLN749NT4+eSlcoICk1Zsy9Ac wJL7L6F2KkqjUusrLHn8EATH1fO7Hho8ZIeBUu2hHedrU4lY67S5c61vfmeaeUz7QxGHTUv9l K2fAlR8RBLuZTQPtMzCyKWDMqrLMHZnjP134S57hLwQgA64sLcSAHg31G2qL61PBQ+BBVDTZg G9LshDfnZQyPcAuCW/tqGfNm2f+mIYAQBe59eQKBYeayPSeVx3k/5TEGLBtgfqTkHN4b8SteB CGByFbYKoVsaMYGsSdyGaVFycNTsHQcrBLd+eTo/REw+jNH85p0dmqQKGuCLXyuwEH3tHDITX 2GW9OsUfD8664NcAtmWjebobQ/4JUvNBBJW/+YRW6R7bICu8fodHCqY+8MpQsecPRGJL9dj8Z /PovZu9WWM+rZPcl8GCD+P23xfJgE+JX9ZbvTVmQkqsPyfahkcWREl7yQ5L4ILJs51Vp/9o/V re5lOhTH6RjDMRHAd+DVx4vAp2MFZLZHtIBCplHJU6JEcnz8oWjgQIuABo/VK9Gn8g8LmMCnM ee5CYCe+j3dng7Sr2VcwiN68mtv5R1HFrag7VgWH4ZNgBbDNDp1UxHySIwJqXMtt3mSxBebju mlr7uG43CGz3i3GiefKBgMhyuHdrRxzzLrNYsj1ksorayugmGvOv1NtiW0BtgSp3wE3WFVIy7 ZfNCLR05Np197BCMaZa9bcEf7iIiqESPfZ1Qy33yftXXgWjx+Ab/RQODVLDR+JfLFct6DNiqe Xe9w5DE Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Thu, 12 Jan 2017 10:42:25 +0100 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/mtd/ftl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index 9fb3b0dcdac2..ef2f38b6a837 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -207,15 +207,14 @@ static int build_maps(partition_t *part) /* Set up erase unit maps */ part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) - part->header.NumTransferUnits; - part->EUNInfo = kmalloc(part->DataUnits * sizeof(struct eun_info_t), - GFP_KERNEL); + part->EUNInfo = kmalloc_array(part->DataUnits, sizeof(*part->EUNInfo), + GFP_KERNEL); if (!part->EUNInfo) goto out; for (i = 0; i < part->DataUnits; i++) part->EUNInfo[i].Offset = 0xffffffff; - part->XferInfo = - kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t), - GFP_KERNEL); + part->XferInfo = kmalloc_array(part->header.NumTransferUnits, + sizeof(*part->XferInfo), GFP_KERNEL); if (!part->XferInfo) goto out_EUNInfo; @@ -275,8 +274,8 @@ static int build_maps(partition_t *part) memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t)); part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize; - part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(uint32_t), - GFP_KERNEL); + part->bam_cache = kmalloc_array(part->BlocksPerUnit, + sizeof(*part->bam_cache), GFP_KERNEL); if (!part->bam_cache) goto out_VirtualBlockMap; -- 2.11.0