From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966951AbcIVT3O (ORCPT ); Thu, 22 Sep 2016 15:29:14 -0400 Received: from mout.web.de ([212.227.17.12]:50805 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934155AbcIVRd7 (ORCPT ); Thu, 22 Sep 2016 13:33:59 -0400 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> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall 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> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.10.0