From: Paolo Bonzini <pbonzini@redhat.com>
To: Ingo Molnar <mingo@kernel.org>, Nicholas Krause <xerofoify@gmail.com>
Cc: gleb@kernel.org, x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kvm:Return -ENOMEM directly for the function, kvm_create_lapic
Date: Thu, 21 May 2015 14:22:12 +0200 [thread overview]
Message-ID: <555DCDF4.3000005@redhat.com> (raw)
In-Reply-To: <20150521060940.GB5615@gmail.com>
On 21/05/2015 08:09, Ingo Molnar wrote:
>
> * Nicholas Krause <xerofoify@gmail.com> wrote:
>
>> In order to make code paths easier to read in the function,
>> kvm_create_lapic we return -ENOMEM when unable to allocate
>> memory for a kvm_lapic structure pointer directly. This
>> makes the code easier to read and cleaner then jumping
>> to a goto label at the end of the function's body for
>> returning just the error code, -ENOMEM.
>>
>> Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
>> ---
>> arch/x86/kvm/lapic.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
>> index 629af0f..88d0cce 100644
>> --- a/arch/x86/kvm/lapic.c
>> +++ b/arch/x86/kvm/lapic.c
>> @@ -1687,7 +1687,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
>>
>> apic = kzalloc(sizeof(*apic), GFP_KERNEL);
>> if (!apic)
>> - goto nomem;
>> + return -ENOMEM;
>>
>> vcpu->arch.apic = apic;
>>
>> @@ -1718,7 +1718,6 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
>> return 0;
>> nomem_free_apic:
>> kfree(apic);
>> -nomem:
>> return -ENOMEM;
>> }
>
> NAK!
>
> You just half destroyed the nice error handling cascade of labels.
Right.
What could be done, is always going through kfree(apic), because it is
okay to free NULL. So the nomem label moves up, and the nomem_free_apic
label is not necessary anymore.
Paolo
prev parent reply other threads:[~2015-05-21 12:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1432169486-31846-1-git-send-email-xerofoify@gmail.com>
2015-05-21 6:09 ` [PATCH] kvm:Return -ENOMEM directly for the function, kvm_create_lapic Ingo Molnar
2015-05-21 12:22 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555DCDF4.3000005@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=x86@kernel.org \
--cc=xerofoify@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).