From patchwork Sun Apr 9 19:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9671753 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 2A13B600CB for ; Sun, 9 Apr 2017 19:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A37226E16 for ; Sun, 9 Apr 2017 19:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F07B82793A; Sun, 9 Apr 2017 19:46:48 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9558726E16 for ; Sun, 9 Apr 2017 19:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752440AbdDITqq (ORCPT ); Sun, 9 Apr 2017 15:46:46 -0400 Received: from mout.web.de ([212.227.17.12]:54091 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbdDITqp (ORCPT ); Sun, 9 Apr 2017 15:46:45 -0400 Received: from [192.168.1.2] ([77.181.114.244]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MGzba-1csOyq25Xm-00DoyU; Sun, 09 Apr 2017 21:46:38 +0200 Subject: [PATCH 1/5] target: Use kcalloc() in two functions From: SF Markus Elfring To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Bart Van Assche , "Nicholas A. Bellinger" Cc: LKML , kernel-janitors@vger.kernel.org References: <337dfdee-8a9f-9bb3-639a-ea47758966f1@users.sourceforge.net> Message-ID: <3754914e-5269-e034-0e61-aaa19aa21107@users.sourceforge.net> Date: Sun, 9 Apr 2017 21:46:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <337dfdee-8a9f-9bb3-639a-ea47758966f1@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:rkilnzy7Zg2s0y9R2w+ugjZhmfSGqxl+n7jG616ABK7IS3D67X+ hgMvMXMFdzhdG0jDdkTqd4veXAovP9fWWfpJ0BWu6ePvjMrmOsKfUPuIKsx83G/qhZiMMrl O5ZA8j/RGuu7HpOKDEkpWn+4pn6Pmi8F02AhVgfziucvHTCdiF1Fji324QT5IPMWE3ulZ/F O6kRJ0aI9eIJluBYTYIkQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:UhCEdacbyhQ=:743Hax8lIdXIFbTYJYdKQo gbMwLpKULOpfaWQcZ3NLzTt9nRqjhS0Pga0s6WNkAHiwjUkSY0F7DIR9yA8O9gKH6Si3EB3wi 3A5Uizb3AJLtxuBdPL4gI46XZrL2ssgMyZMA9lRHhS5nytGDYpKLI8xoaWdyWM09LCnUE1a/4 3Q1p+Ubbj0VnRGb/sFrcF9F0FwKsYZd9YB2G/y3V4/pkjy6YmTP/8NPZDiidRTgdizNgj1WRR BwPg/XsxTMNV058LZgsC/Jf2DNoxJDzR7k0kNmmSBAnu25jYo2QkTU25Rak9qPQiGorciqVAV dLyZo5yJmskIdrQnN6+01HoEdN0Mw7+GdNb4unyP5EAZAiDx33zjUaoi/MMIgjfQjXtJvpgiQ TrGBlRxlWHFScowdrSzKr1+cMLdnG7KYBNk3CmnQ8jVQIuboeEGv76Z0BJXcL52Tt9DL7gFlk IQTclBBZv3/R9FQJO5PJkD1/ZvJqkPZUIcqP3Kxj9VIGQ1XWL7GRM+nr82lmMgv6Q5LJEr0fo bStH/BQLGDJUPSug4/Xzp0mQ/vUQe1Huv0ldJCaBTDpncojIw0rwFcXY6ROUmoNxerCdTXQ8o 1KNrl/42hWiBsENApDOolg3MCYLVEbR5Y/QutBjRU8u2c6GI/xzzTJAkNmTuoS/RFrHFI0AfG LUE1K4DGcrHQK0aHZh40qy7k5nzUyaK8/goWGzs8O3KcxrG1tHVKz5XrG1zjVVRW7yXThdvsb I2EVnr2PQpyvCMFTrRZOpXEUjFAWHfv0xYaXuBcp6FTYdXOVqtYkwpnMuIwjOdeOEBA0adU8c ZhFKled Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 9 Apr 2017 19:02:38 +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. Signed-off-by: Markus Elfring --- drivers/target/target_core_rd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c index 5f23f341f8d3..026857861107 100644 --- a/drivers/target/target_core_rd.c +++ b/drivers/target/target_core_rd.c @@ -210,8 +210,7 @@ static int rd_build_device_space(struct rd_dev *rd_dev) total_sg_needed = rd_dev->rd_page_count; sg_tables = (total_sg_needed / max_sg_per_table) + 1; - - sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL); + sg_table = kcalloc(sg_tables, sizeof(*sg_table), GFP_KERNEL); if (!sg_table) { pr_err("Unable to allocate memory for Ramdisk" " scatterlist tables\n"); @@ -271,8 +270,7 @@ static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1; sg_tables = (total_sg_needed / max_sg_per_table) + 1; - - sg_table = kzalloc(sg_tables * sizeof(struct rd_dev_sg_table), GFP_KERNEL); + sg_table = kcalloc(sg_tables, sizeof(*sg_table), GFP_KERNEL); if (!sg_table) { pr_err("Unable to allocate memory for Ramdisk protection" " scatterlist tables\n");