From patchwork Thu Sep 29 09:07:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9357739 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C87DD600C8 for ; Fri, 30 Sep 2016 08:04:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BADD229E8F for ; Fri, 30 Sep 2016 08:04:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF74129EAC; Fri, 30 Sep 2016 08:04:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2177129EA4 for ; Fri, 30 Sep 2016 08:04:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u8U82HpN010009; Fri, 30 Sep 2016 04:02:18 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u8T984tr007812 for ; Thu, 29 Sep 2016 05:08:04 -0400 Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8T983g8027268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 29 Sep 2016 05:08:03 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90768A0631; Thu, 29 Sep 2016 09:08:02 +0000 (UTC) Received: from [192.168.1.2] ([78.49.118.68]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0LxfKp-1asleu1hkp-017EPF; Thu, 29 Sep 2016 11:07:59 +0200 To: dm-devel@redhat.com, linux-raid@vger.kernel.org, Alasdair Kergon , Mike Snitzer , Shaohua Li References: <566ABCD9.1060404@users.sourceforge.net> <080668d9-1e1e-e208-f9ea-ff718e8070e5@users.sourceforge.net> From: SF Markus Elfring Message-ID: <3861d349-48fd-162b-a749-83e007f70b41@users.sourceforge.net> Date: Thu, 29 Sep 2016 11:07:47 +0200 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: <080668d9-1e1e-e208-f9ea-ff718e8070e5@users.sourceforge.net> X-Provags-ID: V03:K0:LQDkYF88h1hpBD6/XXpwNkQKe6dWskuEt71iEAQ72/rF28fKTdZ hh1jAfenU5ksnHmVLncLA8EPRWrDO6/vb278s6XTnM2fndnwGhFcB4WVBkqInPvANFJbNAl 1+iXDvAAWwTiQpo3zkg9Ve1cIt/MYGPHuZXZXGCr5psdz0wyQZ2Jr407+0bo7r1auKoSPgd bZb+brX9HcO5ecqQ3VFLg== X-UI-Out-Filterresults: notjunk:1; V01:K0:c0SQxHWo4Uo=:2PzBtoNyPYy9ouOoc4EdWV D6w75aLUARTGesX6zYQXZ9twt7GewwvdkMSWHIayugss+F+OPjcogOAJMW18IsROlK8kJaLQq xkHeswKUZIiCKfK6GjonsclsHTdLXbD0riQt9KwjrzOpGipiFf7XGuyHkL3nxDW+73o4z7H8m jSRfFoMbMPnyirJHKZsheg9TMHSaUDclnoAHSuIMieoUN2IRue07JxPaBNw/jC/hlUOOQ/mD6 BQdgSwzoCbdwKGtyF/Y87VjCBm+e+E2sXeK0YDdbKYI2N/pnyU5U4wJVb1o7fMTvNyXRLhKIi 94Ro/TV5mhBIBn4UtYECOj7kcZ25WWkrEBYqO9JA76BFdFi0LYLBa2vgTbYLJaMakgns7vMcx OvA6SOA03nBV+QoTcsyOtFILVMwILViF31f4FA27EW1ZwAypTe9Qj7SuE1SoZR2ipax7ODXBH RiQ/SMArPcBxez6wY/PBjpzaod83vB7lW9w3ELcKEEntAsAMDkL9063aUZPRLRAEiy7ncd6Ph xUfAU0Mssofea0bmo3ot9eVWSGkOjjKtTUDSvyAHR66TYbWnhQnn+dMmjjOCwfbPJwzgpyfWp hOkhRK2M68Z6rkqqzZVj/nu7/LUOedecO7dSzpOk1D03gCFHyBHEDGnRaoQQ9bmjnGtzQcBUC GvMGxaQ2bfuRkCzdQc+bvQ6zFScWqYw+9KI3wXmB07rRrDH43kuIvkzFKIpXKsmj/AzrvsZ6T D4ud3G4Tm6CrxR+r5FYjgUrLW6x4tWAJqHHZPtU4EqPhmgxgnKDzjHyGzDJeqaFU/hVKEhdO7 kTunNYG X-Greylist: Sender IP whitelisted by DNSRBL, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Sep 2016 09:08:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Sep 2016 09:08:03 +0000 (UTC) for IP:'212.227.17.11' DOMAIN:'mout.web.de' HELO:'mout.web.de' FROM:'elfring@users.sourceforge.net' RCPT:'' X-RedHat-Spam-Score: 0.079 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 212.227.17.11 mout.web.de 212.227.17.11 mout.web.de X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 30 Sep 2016 04:02:16 -0400 Cc: Julia Lawall , kernel-janitors@vger.kernel.org, LKML Subject: [dm-devel] [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 28 Sep 2016 22:20:08 +0200 * 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 structures 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/md/dm-snap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index c65feea..f262f7e 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -326,8 +326,9 @@ static int init_origin_hash(void) { int i; - _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head), - GFP_KERNEL); + _origins = kmalloc_array(ORIGIN_HASH_SIZE, + sizeof(*_origins), + GFP_KERNEL); if (!_origins) { DMERR("unable to allocate memory for _origins"); return -ENOMEM; @@ -335,8 +336,9 @@ static int init_origin_hash(void) for (i = 0; i < ORIGIN_HASH_SIZE; i++) INIT_LIST_HEAD(_origins + i); - _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head), - GFP_KERNEL); + _dm_origins = kmalloc_array(ORIGIN_HASH_SIZE, + sizeof(*_dm_origins), + GFP_KERNEL); if (!_dm_origins) { DMERR("unable to allocate memory for _dm_origins"); kfree(_origins);