From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934306AbcIAVaj (ORCPT ); Thu, 1 Sep 2016 17:30:39 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49372 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934274AbcIAVab (ORCPT ); Thu, 1 Sep 2016 17:30:31 -0400 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: holzheu@linux.vnet.ibm.com X-IBM-RcptTo: kernel-janitors@vger.kernel.org;linux-kernel@vger.kernel.org;linux-s390@vger.kernel.org Date: Thu, 1 Sep 2016 18:53:25 +0200 From: Michael Holzheu To: Paolo Bonzini Cc: Heiko Carstens , SF Markus Elfring , linux-s390@vger.kernel.org, Martin Schwidefsky , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Subject: Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store() In-Reply-To: References: <5fd5f9ef-923f-4655-54f0-874114dc9428@users.sourceforge.net> <20160901103245.GA3624@osiris> Organization: IBM X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16090116-0040-0000-0000-000002CA8FF8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16090116-0041-0000-0000-00001CCBAB96 Message-Id: <20160901185325.5155a5e9@TP-holzheu> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-09-01_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1609010191 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Thu, 1 Sep 2016 17:39:02 +0200 schrieb Paolo Bonzini : > > > On 01/09/2016 12:32, Heiko Carstens wrote: > > On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote: > >> From: Markus Elfring > >> Date: Thu, 1 Sep 2016 11:30:58 +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. > >> > >> Signed-off-by: Markus Elfring > >> --- > >> arch/s390/hypfs/hypfs_diag0c.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/arch/s390/hypfs/hypfs_diag0c.c > >> b/arch/s390/hypfs/hypfs_diag0c.c index 0f1927c..61418a8 100644 > >> --- a/arch/s390/hypfs/hypfs_diag0c.c > >> +++ b/arch/s390/hypfs/hypfs_diag0c.c > >> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count) > >> > >> get_online_cpus(); > >> cpu_count = num_online_cpus(); > >> - cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), > >> GFP_KERNEL); > >> + cpu_vec = kmalloc_array(num_possible_cpus(), > >> + sizeof(*cpu_vec), > >> + GFP_KERNEL); > > > > How does this improve the situation? For any real life scenario > > this can't overflow, but it does add an extra (pointless) runtime > > check, since num_possible_cpus() is not a compile time constant. > > > > So, why is this an "issue"? > > It's not an issue but I for one still prefer consistent use of > kmalloc_array and kcalloc. Hello Paolo, I will keep this in mind for future code, but would prefer not changing this now. Michael From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Holzheu Date: Thu, 01 Sep 2016 16:53:25 +0000 Subject: Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store() Message-Id: <20160901185325.5155a5e9@TP-holzheu> List-Id: References: <5fd5f9ef-923f-4655-54f0-874114dc9428@users.sourceforge.net> <20160901103245.GA3624@osiris> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Paolo Bonzini Cc: Heiko Carstens , SF Markus Elfring , linux-s390@vger.kernel.org, Martin Schwidefsky , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Am Thu, 1 Sep 2016 17:39:02 +0200 schrieb Paolo Bonzini : > > > On 01/09/2016 12:32, Heiko Carstens wrote: > > On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote: > >> From: Markus Elfring > >> Date: Thu, 1 Sep 2016 11:30:58 +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. > >> > >> Signed-off-by: Markus Elfring > >> --- > >> arch/s390/hypfs/hypfs_diag0c.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/arch/s390/hypfs/hypfs_diag0c.c > >> b/arch/s390/hypfs/hypfs_diag0c.c index 0f1927c..61418a8 100644 > >> --- a/arch/s390/hypfs/hypfs_diag0c.c > >> +++ b/arch/s390/hypfs/hypfs_diag0c.c > >> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count) > >> > >> get_online_cpus(); > >> cpu_count = num_online_cpus(); > >> - cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), > >> GFP_KERNEL); > >> + cpu_vec = kmalloc_array(num_possible_cpus(), > >> + sizeof(*cpu_vec), > >> + GFP_KERNEL); > > > > How does this improve the situation? For any real life scenario > > this can't overflow, but it does add an extra (pointless) runtime > > check, since num_possible_cpus() is not a compile time constant. > > > > So, why is this an "issue"? > > It's not an issue but I for one still prefer consistent use of > kmalloc_array and kcalloc. Hello Paolo, I will keep this in mind for future code, but would prefer not changing this now. Michael