From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753900AbcHRJCk (ORCPT ); Thu, 18 Aug 2016 05:02:40 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:15573 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753682AbcHRJCe (ORCPT ); Thu, 18 Aug 2016 05:02:34 -0400 X-IronPort-AV: E=Sophos;i="5.28,538,1464645600"; d="scan'208";a="232919672" Date: Thu, 18 Aug 2016 05:02:23 -0400 (EDT) From: Julia Lawall X-X-Sender: jll@hadrien To: walter harms cc: SF Markus Elfring , kvm@vger.kernel.org, linux-s390@vger.kernel.org, =?ISO-8859-15?Q?Christian_Borntr=E4ger?= , Cornelia Huck , David Hildenbrand , Heiko Carstens , Martin Schwidefsky , Paolo Bonzini , =?ISO-8859-2?Q?Radim_Kr=E8m=E1=F8?= , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Subject: Re: [PATCH 1/4] KVM-S390: Improve determination of sizes in kvm_s390_import_bp_data() In-Reply-To: <57B562F3.1080004@bfs.de> Message-ID: References: <82b84c9c-38a4-4d17-910f-312668dbae01@users.sourceforge.net> <033d8595-d051-1fa8-95b1-5d2056eb5667@users.sourceforge.net> <57B562F3.1080004@bfs.de> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 18 Aug 2016, walter harms wrote: > > > Am 17.08.2016 20:06, schrieb SF Markus Elfring: > > From: Markus Elfring > > Date: Wed, 17 Aug 2016 18:29:04 +0200 > > > > Replace the specification of data structures by pointer dereferences > > to make the corresponding size determination a bit safer according to > > the Linux coding style convention. > > > > Signed-off-by: Markus Elfring > > --- > > arch/s390/kvm/guestdbg.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/guestdbg.c > > index d1f8241..b68db4b 100644 > > --- a/arch/s390/kvm/guestdbg.c > > +++ b/arch/s390/kvm/guestdbg.c > > @@ -216,7 +216,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT) > > return -EINVAL; > > > > - size = dbg->arch.nr_hw_bp * sizeof(struct kvm_hw_breakpoint); > > + size = dbg->arch.nr_hw_bp * sizeof(*bp_data); > > bp_data = kmalloc(size, GFP_KERNEL); > > if (!bp_data) { > > ret = -ENOMEM; > > @@ -241,7 +241,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > } > > } > > > > - size = nr_wp * sizeof(struct kvm_hw_wp_info_arch); > > + size = nr_wp * sizeof(*wp_info); > > if (size > 0) { > > wp_info = kmalloc(size, GFP_KERNEL); > > if (!wp_info) { > > @@ -249,7 +249,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > goto error; > > } > > } > > - size = nr_bp * sizeof(struct kvm_hw_bp_info_arch); > > + size = nr_bp * sizeof(*bp_info); > > if (size > 0) { > > bp_info = kmalloc(size, GFP_KERNEL); > > if (!bp_info) { > > > IMHO the common pattern for kmalloc is > bp_info = kmalloc( nr_bp * sizeof(*bp_info), GFP_KERNEL); > > i can not remember code with a check for size < 0, i guess it is here > to avoid an overflow ? since kmalloc takes a size_t argument this would cause > a malloc failure an can be ignored. Shoudn't it be kcalloc? julia > > > just my 2 cents. > re, > wh > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julia Lawall Date: Thu, 18 Aug 2016 09:02:23 +0000 Subject: Re: [PATCH 1/4] KVM-S390: Improve determination of sizes in kvm_s390_import_bp_data() Message-Id: List-Id: References: <82b84c9c-38a4-4d17-910f-312668dbae01@users.sourceforge.net> <033d8595-d051-1fa8-95b1-5d2056eb5667@users.sourceforge.net> <57B562F3.1080004@bfs.de> In-Reply-To: <57B562F3.1080004@bfs.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: walter harms Cc: SF Markus Elfring , kvm@vger.kernel.org, linux-s390@vger.kernel.org, =?ISO-8859-15?Q?Christian_Borntr=E4ger?= , Cornelia Huck , David Hildenbrand , Heiko Carstens , Martin Schwidefsky , Paolo Bonzini , =?ISO-8859-2?Q?Radim_Kr=E8m=E1=F8?= , LKML , kernel-janitors@vger.kernel.org, Julia Lawall On Thu, 18 Aug 2016, walter harms wrote: > > > Am 17.08.2016 20:06, schrieb SF Markus Elfring: > > From: Markus Elfring > > Date: Wed, 17 Aug 2016 18:29:04 +0200 > > > > Replace the specification of data structures by pointer dereferences > > to make the corresponding size determination a bit safer according to > > the Linux coding style convention. > > > > Signed-off-by: Markus Elfring > > --- > > arch/s390/kvm/guestdbg.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/guestdbg.c > > index d1f8241..b68db4b 100644 > > --- a/arch/s390/kvm/guestdbg.c > > +++ b/arch/s390/kvm/guestdbg.c > > @@ -216,7 +216,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT) > > return -EINVAL; > > > > - size = dbg->arch.nr_hw_bp * sizeof(struct kvm_hw_breakpoint); > > + size = dbg->arch.nr_hw_bp * sizeof(*bp_data); > > bp_data = kmalloc(size, GFP_KERNEL); > > if (!bp_data) { > > ret = -ENOMEM; > > @@ -241,7 +241,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > } > > } > > > > - size = nr_wp * sizeof(struct kvm_hw_wp_info_arch); > > + size = nr_wp * sizeof(*wp_info); > > if (size > 0) { > > wp_info = kmalloc(size, GFP_KERNEL); > > if (!wp_info) { > > @@ -249,7 +249,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, > > goto error; > > } > > } > > - size = nr_bp * sizeof(struct kvm_hw_bp_info_arch); > > + size = nr_bp * sizeof(*bp_info); > > if (size > 0) { > > bp_info = kmalloc(size, GFP_KERNEL); > > if (!bp_info) { > > > IMHO the common pattern for kmalloc is > bp_info = kmalloc( nr_bp * sizeof(*bp_info), GFP_KERNEL); > > i can not remember code with a check for size < 0, i guess it is here > to avoid an overflow ? since kmalloc takes a size_t argument this would cause > a malloc failure an can be ignored. Shoudn't it be kcalloc? julia > > > just my 2 cents. > re, > wh >