From patchwork Thu Sep 22 17:37:37 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: 9345941 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 346A2607D0 for ; Thu, 22 Sep 2016 17:37:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27C3E2AAB7 for ; Thu, 22 Sep 2016 17:37:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BBD82ABFE; Thu, 22 Sep 2016 17:37:45 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91D8B2AAB7 for ; Thu, 22 Sep 2016 17:37:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBEAC6E3B9; Thu, 22 Sep 2016 17:37:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.web.de (mout.web.de [212.227.15.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E7916E3B9 for ; Thu, 22 Sep 2016 17:37:42 +0000 (UTC) Received: from [192.168.1.2] ([77.182.99.72]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0Le4PE-1bAmul12mS-00pthB; Thu, 22 Sep 2016 19:37:39 +0200 Subject: [PATCH 05/14] GPU-DRM-TTM: Use kmalloc_array() in two more functions To: dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie , Emil Velikov References: <566ABCD9.1060404@users.sourceforge.net> <4d34446f-05ad-c3ce-5d33-8fb4f25af25c@users.sourceforge.net> From: SF Markus Elfring Message-ID: <050b05d3-60ad-3768-8519-3ea37c34b188@users.sourceforge.net> Date: Thu, 22 Sep 2016 19:37:37 +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: <4d34446f-05ad-c3ce-5d33-8fb4f25af25c@users.sourceforge.net> X-Provags-ID: V03:K0:JPgIMTcGsJNMewG2YE/WCklLWYCVvnaeH1wrcIMCwDymANoYir8 LLT0X0fYnwBNXfgXlGeG/BDAKZLGxxRtepbWxDjOcf2Ekv7qtPa9bZ1PfUrdzQh56T4vZDM Wlzeo/n1yIa4PSbwKgIrzUackJC88ws5KrvWle/88E5/ab0UwMKeCXrtdTFXqyScaZTiMBn AIzhwUWWFXjFJhPxY4qqg== X-UI-Out-Filterresults: notjunk:1; V01:K0:nGwTdl3Iydc=:pt7p7kg6eCrU4KfUy7OURY YBByuVH0UKhmcjDdX3FaQhCyarprFFgfcSaJljEgNAtobw5Fw1UN4ttb8gaSalXLP/ECT+tbH cJlx33w3kOLTcpgAB6dAHZV2o/cV5U7w676g0EUuQq5/ajl2K8gxHDdtflBpe56xNMvTGs9M2 LM7GRh/HzgHl3JHe0n+FgqQIsjlj6B0g0efeq/zmzrSDvXGYqavC6MfQMAPgqvd0Qn2ij9FfH S5nGok5oplrJQD//1OSLQUkqI3Do0OvOFLVh7DFII2UvMMNtmYFo6Y/gIX2udH86IwLg3kq3l kFWbyZvRyFU1MkKP/DIOAJHb/saJEbS83Yqrp26OT6V5tQrczysYsPNp0hgpMubaJPLBVQ6Vn QY08igq/DmP6dTcHqgRAEJdRMIffJB0Or/DYRhtHbmPn3xNzGFJ7x58NLdXJrd9CnGVUcSVCk HjS+UIutk3Meom5VH0kgUV9cH69w/oemFx8jYRe6wCwj42F1SNpGOY2V3oiSAeH+D5Y5Fp+U5 NeQC4SC6R68uCJNOODqxtjyLOtcfhLZI3voQ0IMTqWa40bIHuQRN7tYCBvsmrNJjYdIFs2tJ2 6Wf7B0P3SRvVueuhoORsNeXQLW9m0JXcC9K5YkQgzjxfkqtwyU7/KEjnuQnqx8EquUs/lrCo5 KMN+S2Hy1qPqqg9kWwTzwI9i0H+w1+r/tk/pNYuGmQdKXw6emtlNzQdNdezHAaUXAf/Bgbr+g CUoFC/jz56Q6yas5tm9ckQ1cO8RfRLKWSYZcmGoelATtCjXsLPUYtT3vXE+0rFPkVxc6MuDYT GDolv8a Cc: Julia Lawall , kernel-janitors@vger.kernel.org, LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Thu, 22 Sep 2016 14:48:39 +0200 * Multiplications for the size determination of memory allocations indicated that array data structure 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/gpu/drm/ttm/ttm_page_alloc_dma.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index bef9f6f..194818d 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -439,8 +439,9 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free, if (use_static) pages_to_free = static_buf; else - pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), - GFP_KERNEL); + pages_to_free = kmalloc_array(npages_to_free, + sizeof(*pages_to_free), + GFP_KERNEL); if (!pages_to_free) { pr_err("%s: Failed to allocate memory for pool free operation\n", @@ -726,8 +727,9 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool, (unsigned)(PAGE_SIZE/sizeof(struct page *))); /* allocate array for page caching change */ - caching_array = kmalloc(max_cpages*sizeof(struct page *), GFP_KERNEL); - + caching_array = kmalloc_array(max_cpages, + sizeof(*caching_array), + GFP_KERNEL); if (!caching_array) { pr_err("%s: Unable to allocate table for new pages\n", pool->dev_name);