From patchwork Thu Sep 22 17:33:51 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: 9345887 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 45B356077A for ; Thu, 22 Sep 2016 17:34:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E11B2ABF6 for ; Thu, 22 Sep 2016 17:34:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32B6C2ABFC; Thu, 22 Sep 2016 17:34:00 +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 278F82ABF6 for ; Thu, 22 Sep 2016 17:33:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 30B906E3AE; Thu, 22 Sep 2016 17:33:58 +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.17.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 944BB6E3AE for ; Thu, 22 Sep 2016 17:33:56 +0000 (UTC) Received: from [192.168.1.2] ([77.182.99.72]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0Lpw2l-1bIAWF0i3j-00fkAK; Thu, 22 Sep 2016 19:33:52 +0200 Subject: [PATCH 01/14] GPU-DRM-TTM: Use kmalloc_array() in two 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: <3fb3509e-fd3f-010e-9736-529ba42e506b@users.sourceforge.net> Date: Thu, 22 Sep 2016 19:33:51 +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:Ayb7LalxBeZIXtuYIeqcvM27anDi6lHKKatnSVnXQCBWpck9mnc PdIrgpqy3o0x3mXNqAQHb1GTt1nMXmmYEZYx7DNIBI5cjx8e0J1wDw5cMZS3ApHBNLidwnL 2ico0Yrws1JD26O5+7sZYCKBWndP8QvQxW0PrhGE9CzFrEK9a0etSZqs3FNTXAHjXBDd8FT 7TBEnF5z1YyQjCq24EhbA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Rep82u3KGRE=:JeWD6p8ioRc5r3A8zhwmR4 1UnC3GoGq5J8NVS9nHe2JVZzSwiysJ2uesrwEWoytn28NNSTBvSvjyu8ILbN1o5+mdiKQ/e86 zn8e+c/TwXccvFTvbiVKNwG7NDWjJ4JUfgW5o/bZ+Zsx4dfiQyGAxqII0oArWRBU1BNLH/gkL vxSW2Ybzt2XhGlLpEqcSLh+ny3iheBgB4m3d47YrjDb5SN4ogCA6NUGQhYZegMUL61gipoSDn 11WZI12QZlU4QsKKcf7cZOB3DKTXuCUWIGqazYreJezzCfWeZOIVjUv2g2PQyc7YkyZzaEIlU JcybMTCOv8gpaSnG/oSo500IDvPh0BEYyt4oalDxSlGWKGCjdsCWK/m72+e6AAAHNw6sQigg2 j4PLImSofN2lbaC46pZGZZ2T7M39zFif1Sl0lH/9RdJMt7SNN3ibPCQ70ijMhB+CN1jH1wSni e7L7a5KsXMH0r+41jqKzgVsXOiTSsIBFZaJ//iWUmzMZjdHNpV4qS23BcW41riTZEPw0gdKux 5pKjRBQZdiI99b62s+Dz3nWTMDRjng/jmMvBWicOzrdHCNPCRdbfmR/MZAjB98aqCv0vFX48d tZVcwkGxx5tBax6UJvsm4lG/E+PdBnKNpbwcnkZrZbl2lr1osboUOT1IxGYZwDV5SAPmdCdI2 m/RkuAIqnIqEyBxPRu/EerghlRM7jH9yPy944fQ29L9D4cp50YLWzf5qEmWLhg6Sh7sj1jZZn uZceK+U8LJonzzXJB5IGlIl6dZp/KhtfqEQklRm5kWElOA0IZz7ZeirTtjkwxUDLqy/jRj3Yf OMucD3x 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:00:31 +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.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index a37de5d..bfc51cb 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -315,8 +315,9 @@ static int ttm_page_pool_free(struct ttm_page_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("Failed to allocate memory for pool free operation\n"); return 0; @@ -501,8 +502,9 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags, (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("Unable to allocate table for new pages\n"); return -ENOMEM;