From patchwork Wed Aug 31 17:05:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 9307645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04055607D2 for ; Wed, 31 Aug 2016 17:08:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E45B828FD6 for ; Wed, 31 Aug 2016 17:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8D4428FE3; Wed, 31 Aug 2016 17:08:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B55828FE2 for ; Wed, 31 Aug 2016 17:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965246AbcHaRFv (ORCPT ); Wed, 31 Aug 2016 13:05:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51656 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964922AbcHaRFu (ORCPT ); Wed, 31 Aug 2016 13:05:50 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D258DC05678C; Wed, 31 Aug 2016 17:05:49 +0000 (UTC) Received: from localhost (ovpn-116-169.phx2.redhat.com [10.3.116.169]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7VH5nkl030481; Wed, 31 Aug 2016 13:05:49 -0400 From: Luiz Capitulino To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mtosatti@redhat.com Subject: [PATCH 2/4] kvm: kvm_create_vm_debugfs(): cleanup on error Date: Wed, 31 Aug 2016 13:05:43 -0400 Message-Id: <1472663145-1835-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1472663145-1835-1-git-send-email-lcapitulino@redhat.com> References: <1472663145-1835-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 31 Aug 2016 17:05:49 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Memory and debugfs entries are leaked on error. Fix it. Signed-off-by: Luiz Capitulino Reviewed-by: Paolo Bonzini --- virt/kvm/kvm_main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c1dc45e..9293285 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -585,12 +585,12 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) sizeof(*kvm->debugfs_stat_data), GFP_KERNEL); if (!kvm->debugfs_stat_data) - return -ENOMEM; + goto out_err; for (p = debugfs_entries; p->name; p++) { stat_data = kzalloc(sizeof(*stat_data), GFP_KERNEL); if (!stat_data) - return -ENOMEM; + goto out_err; stat_data->kvm = kvm; stat_data->offset = p->offset; @@ -599,9 +599,13 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) kvm->debugfs_dentry, stat_data, stat_fops_per_vm[p->kind])) - return -ENOMEM; + goto out_err; } return 0; + +out_err: + kvm_destroy_vm_debugfs(kvm); + return -ENOMEM; } static struct kvm *kvm_create_vm(unsigned long type)