From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754774AbbEUGJu (ORCPT ); Thu, 21 May 2015 02:09:50 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:36740 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751518AbbEUGJp (ORCPT ); Thu, 21 May 2015 02:09:45 -0400 Date: Thu, 21 May 2015 08:09:40 +0200 From: Ingo Molnar To: Nicholas Krause Cc: gleb@kernel.org, pbonzini@redhat.com, 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 Message-ID: <20150521060940.GB5615@gmail.com> References: <1432169486-31846-1-git-send-email-xerofoify@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432169486-31846-1-git-send-email-xerofoify@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Nicholas Krause 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 > --- > 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. Thanks, Ingo