Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966044AbcJFJYs (ORCPT ); Thu, 6 Oct 2016 05:24:48 -0400 Received: from mout.web.de ([212.227.15.4]:50922 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965585AbcJFJYp (ORCPT ); Thu, 6 Oct 2016 05:24:45 -0400 Subject: [PATCH 25/54] md/raid5: Use kcalloc() in three functions To: linux-raid@vger.kernel.org, Christoph Hellwig , Guoqing Jiang , Jens Axboe , Mike Christie , Neil Brown , Shaohua Li , Tomasz Majchrzak References: <566ABCD9.1060404@users.sourceforge.net> <786843ef-4b6f-eb04-7326-2f6f5b408826@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <820e039e-c1bc-5586-f4f8-cf3d0ca71604@users.sourceforge.net> Date: Thu, 6 Oct 2016 11:23:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <786843ef-4b6f-eb04-7326-2f6f5b408826@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:cuf5z/WhJY5ykTLv4hZNhyoITl09+qi4Rykm437NQHCxbzE50hR Ld0mssx5GAKLXAeern37CKQ63hVIzccZT5pqbZoE13S9fZkZp/6N4+TfSYAvpnrOyMpKml5 8fxQ2+5OKmJ1spClDv4hYscfNAhcqxnTD2roatKNIKIq1Fl0I6eTZFKrjyp3Dty9sc7xSh/ X9c9TZKT88Lt5iLvqZkxA== X-UI-Out-Filterresults: notjunk:1;V01:K0:KEZGaNZSo5k=:gnP6rpjwRtpCt0XCkMdSXq R9l5v4UdE0JDNweFsPuU2DUBBkbec9NR67WYqA3SptLJdGsLRTPIsJzuQObY/OFoSrgtQEn/Z g7+M8+x5IpyMLvlVmCWXHhHAaZOh0grKD/tueSCsnM4+SgvctclRn4t+SdFFreXVthImWlaj8 Ph87GOdZEZ4gF4oYZ3QyM0qt+716GRh2zuFXil3NS8IIamoQL3Zy6AaUiYCegQkpdPMX20cOm YE3lAXt6Dr5idB7C2uXfhM6NnTRuQb41WOdaYhZn0A4zVnCDawzTsZmUZ8z53gFC6q0IUBDD+ 1wv5mJcQnNJhbDsnHvrJM7wwLoXOa99f+5J1v1/+RKsA665JbauIwN+WHJSrvGgn9h29g6gWx VHj0ceJhCf55ItPPJSWhML3713HL7uUKYlJMhK/+UFbso4wrzuWOocoC7JIoknxa5YMFSVL+p unnhvpRfghghyiIA+n6hWFj5p5tA5CvnuYGfPPPfgteApoiD9crAbVAdWPFFmU7StD8HBeyy1 D2PfuHKO70kycgCvr/FOIZtEoxA4iyfD0ZSV2pNZtVysGkFyMvc3Q2JXr72X54es2Dzu5ZfIl EMNNE7AWlieQlrSDPqsnp+gIbBZRFOLEBaWv5ujfJK3wWM4AfGSosORmVoef3J4B3qdpsO6gh I81eWdmHnasgnoNF1OfOOxcqfwpOzcriCm0b/E7NZDwFeNJHZ0b/5ggFkgge/vQG5+gheutZd HV/q77MOPBBHtop4tQj+Zv4PDaQGN/MyNyvDqBzqgQffaFQITIHaa2TiozlOTu+AjnoSbApfW x0ds9rQ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2471 Lines: 68 From: Markus Elfring Date: Tue, 4 Oct 2016 22:30:12 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc". 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. * Delete the local variable "size" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/md/raid5.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 92ac251..9a43006 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2243,7 +2243,7 @@ static int resize_stripes(struct r5conf *conf, int newsize) * is completely stalled, so now is a good time to resize * conf->disks and the scribble region */ - ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); + ndisks = kcalloc(newsize, sizeof(*ndisks), GFP_NOIO); if (ndisks) { for (i=0; iraid_disks; i++) ndisks[i] = conf->disks[i]; @@ -6255,7 +6255,6 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt, struct r5worker_group **worker_groups) { int i, j, k; - ssize_t size; struct r5worker *workers; *worker_cnt_per_group = cnt; @@ -6265,10 +6264,8 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt, return 0; } *group_cnt = num_possible_nodes(); - size = sizeof(struct r5worker) * cnt; - workers = kzalloc(size * *group_cnt, GFP_NOIO); - *worker_groups = kzalloc(sizeof(struct r5worker_group) * - *group_cnt, GFP_NOIO); + workers = kcalloc(cnt * *group_cnt, sizeof(*workers), GFP_NOIO); + *worker_groups = kcalloc(*group_cnt, sizeof(**worker_groups), GFP_NOIO); if (!*worker_groups || !workers) { kfree(workers); kfree(*worker_groups); @@ -6519,9 +6516,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) else conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; max_disks = max(conf->raid_disks, conf->previous_raid_disks); - - conf->disks = kzalloc(max_disks * sizeof(struct disk_info), - GFP_KERNEL); + conf->disks = kcalloc(max_disks, sizeof(*conf->disks), GFP_KERNEL); if (!conf->disks) goto abort; -- 2.10.1