From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755256AbcIEINO (ORCPT ); Mon, 5 Sep 2016 04:13:14 -0400 Received: from mout.web.de ([212.227.15.3]:60873 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752644AbcIEINM (ORCPT ); Mon, 5 Sep 2016 04:13:12 -0400 Subject: [PATCH 1/4] x86/smpboot: Use kmalloc_array() in smp_init_package_map() To: x86@kernel.org, Andi Kleen , Boris Ostrovsky , Borislav Petkov , "H. Peter Anvin" , Ingo Molnar , Jiri Olsa , =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= , Len Brown , Peter Zijlstra , Thomas Gleixner References: <6dacb257-d15c-8ea1-9dd4-0440a5ecfd1d@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Paolo Bonzini From: SF Markus Elfring Message-ID: <190dbaf0-e4ef-859a-346b-eb5ae5dfe583@users.sourceforge.net> Date: Mon, 5 Sep 2016 10:10:09 +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: <6dacb257-d15c-8ea1-9dd4-0440a5ecfd1d@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:2/ikCsBhbx13GC1Zomh1wRUJ3LuWESMp+jbrPe24E22YkbWGyWz mTnAlAuVRW3ju92VzBWOsZYvsk/4bZsByOlQ+4pWiAz3+UFStrSJoq6EBX5ziljEkSDPhuH sWlRc2Us/BNIrc0ry82VisKoy3i2sDeZyybNtpFNht9h92lAAhvRDpxH8wjOUkVs+D4ksQ/ afHfzPwUfgcSIFdjLnJHA== X-UI-Out-Filterresults: notjunk:1;V01:K0:FTBEZlAJJh0=:WhC+rbtERLOYF4FDROoAHX f7hOtkGHeHmKo4id0T+ZXKfXSG01fEaCFF4R9pmr+lFkDBP+w239cBl/9SIJhXcK+b5DJLkm0 K4n8g1Fmjo8tHNTqWkfXIzRo54TOhprmDLX/TANjM15EBsdE+ENSnQ3O3LRpKhryIA27jq+s1 JvJ1+FuJjwmhi576j2arNfA1tycDo684xvv6E1QqV953bzJXkvudtWY8Of0rQD4nMCGor7Re8 6eRfBSVTAbWzSmrbRPs7SOMHbZClFsFqK/M3MgEhsJpXsO+wRFYgGYkQdzU+cLPbev1IHvNna 6nLk+ljIEkHtpeNHSdFW4qvHKISHqzRM+y+ykQemmVJ3tiubtdmXYr2mLgT4XYwHROZjFLpJR 6CNIAAxXx4bJejJzRmnkCSqcKbKpWi/zBqGFRGwL3Zy5jPI74L+2ijRFlzH5fh9lGi8UOyMwT WksDChtPYMIFd2YWHOFp6l2hWdGZjU1xKPG3ENVzj5hNLDFzeGwpnOYPpAFWSj5N9yW+IHagn 60Gp9nFDu/mPwREmc4Z3zivGDkXggwRPZDaWecRmGhnTsK4QJ5MXmd1RJ9q0FWyV+XOm9t0tP 7bHc+S1nflBD0aUcOIDmVulLgjh1nPvesJvBHuVzd4REs9Di7hsuCdM62qlyZs+zXDOCg/Rau PHxfOC3J3ynVunigQuwTcMS6wMFljVvtuGo5Z5d2xS42ODKHVI3S8zbgUo9mjIQztsb1avV+t k4aCHoS8C+ICahNIBFnq8+DLVnokWgbXd0mkJ0toq1WjQ8pjd8bugRhoVE3FgJRKOMwlhauD9 9ZfXIRK Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Mon, 5 Sep 2016 08:30:20 +0200 * A multiplication for the size determination of a memory allocation indicated that an 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 a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. * Move a calculation for one function call. Signed-off-by: Markus Elfring --- arch/x86/kernel/smpboot.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 3878725..36cf27e 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -349,9 +349,12 @@ static void __init smp_init_package_map(void) * package can be smaller than the actual used apic ids. */ max_physical_pkg_id = DIV_ROUND_UP(MAX_LOCAL_APIC, ncpus); - size = max_physical_pkg_id * sizeof(unsigned int); - physical_to_logical_pkg = kmalloc(size, GFP_KERNEL); - memset(physical_to_logical_pkg, 0xff, size); + physical_to_logical_pkg = kmalloc_array(max_physical_pkg_id, + sizeof(*physical_to_logical_pkg), + GFP_KERNEL); + memset(physical_to_logical_pkg, + 0xff, + sizeof(*physical_to_logical_pkg) * max_physical_pkg_id); size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); physical_package_map = kzalloc(size, GFP_KERNEL); -- 2.9.3