mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
KVM: s390: Improve determination of sizes in kvm_s390_import_bp_data()
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array". Suggested-by: Paolo Bonzini <pbonzini@redhat.com> This issue was detected also by using the Coccinelle software. * 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. * Delete the local variable "size" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Message-Id: <c3323f6b-4af2-0bfb-9399-e529952e378e@users.sourceforge.net> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
This commit is contained in:
parent
a6940674c3
commit
a1708a2ead
1 changed files with 15 additions and 10 deletions
|
@ -206,7 +206,7 @@ static int __import_wp_info(struct kvm_vcpu *vcpu,
|
||||||
int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
|
int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
|
||||||
struct kvm_guest_debug *dbg)
|
struct kvm_guest_debug *dbg)
|
||||||
{
|
{
|
||||||
int ret = 0, nr_wp = 0, nr_bp = 0, i, size;
|
int ret = 0, nr_wp = 0, nr_bp = 0, i;
|
||||||
struct kvm_hw_breakpoint *bp_data = NULL;
|
struct kvm_hw_breakpoint *bp_data = NULL;
|
||||||
struct kvm_hw_wp_info_arch *wp_info = NULL;
|
struct kvm_hw_wp_info_arch *wp_info = NULL;
|
||||||
struct kvm_hw_bp_info_arch *bp_info = NULL;
|
struct kvm_hw_bp_info_arch *bp_info = NULL;
|
||||||
|
@ -216,14 +216,17 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
|
||||||
else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT)
|
else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
size = dbg->arch.nr_hw_bp * sizeof(struct kvm_hw_breakpoint);
|
bp_data = kmalloc_array(dbg->arch.nr_hw_bp,
|
||||||
bp_data = kmalloc(size, GFP_KERNEL);
|
sizeof(*bp_data),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!bp_data) {
|
if (!bp_data) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_from_user(bp_data, dbg->arch.hw_bp, size)) {
|
if (copy_from_user(bp_data,
|
||||||
|
dbg->arch.hw_bp,
|
||||||
|
sizeof(*bp_data) * dbg->arch.nr_hw_bp)) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -241,17 +244,19 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size = nr_wp * sizeof(struct kvm_hw_wp_info_arch);
|
if (nr_wp > 0) {
|
||||||
if (size > 0) {
|
wp_info = kmalloc_array(nr_wp,
|
||||||
wp_info = kmalloc(size, GFP_KERNEL);
|
sizeof(*wp_info),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!wp_info) {
|
if (!wp_info) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size = nr_bp * sizeof(struct kvm_hw_bp_info_arch);
|
if (nr_bp > 0) {
|
||||||
if (size > 0) {
|
bp_info = kmalloc_array(nr_bp,
|
||||||
bp_info = kmalloc(size, GFP_KERNEL);
|
sizeof(*bp_info),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!bp_info) {
|
if (!bp_info) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in a new issue