From patchwork Thu Nov 19 12:40:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 7656961 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1CE22BF90C for ; Thu, 19 Nov 2015 12:41:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5982720668 for ; Thu, 19 Nov 2015 12:41:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B34020658 for ; Thu, 19 Nov 2015 12:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758114AbbKSMk7 (ORCPT ); Thu, 19 Nov 2015 07:40:59 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51111 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750775AbbKSMk6 (ORCPT ); Thu, 19 Nov 2015 07:40:58 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tAJCepsv002369 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 Nov 2015 12:40:51 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tAJCeopg028872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 19 Nov 2015 12:40:51 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id tAJCeodb004023; Thu, 19 Nov 2015 12:40:50 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Nov 2015 04:40:49 -0800 Date: Thu, 19 Nov 2015 15:40:40 +0300 From: Dan Carpenter To: Gleb Natapov , Janosch Frank Cc: Paolo Bonzini , kvm@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch 1/2] KVM: fix error handling in kvm_create_vm_debugfs() Message-ID: <20151119124040.GA2638@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The "goto out_err" is buggy because we forgot to set the return code. The other issue is that if the kmalloc() fails, we should remove the debugfs directory before returning. Fixes: 7805f53a85ec ('KVM: Create debugfs dir and stat files for each VM') Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1ee2f73..f62621f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -571,12 +571,14 @@ static int kvm_create_vm_debugfs(struct kvm *kvm) snprintf(dir_name, sizeof(dir_name), "%d", current->pid); kvm->debugfs_dentry = debugfs_create_dir(dir_name, kvm_debugfs_dir); if (!kvm->debugfs_dentry) - goto out_err; + return -ENOMEM; kvm->debugfs_data = kmalloc(sizeof(*kvm->debugfs_data) * kvm_debugfs_num_entries, GFP_KERNEL); - if (!kvm->debugfs_data) - return -ENOMEM; + if (!kvm->debugfs_data) { + r = -ENOMEM; + goto err_remove_dir; + } for (p = debugfs_entries; p->name; p++, i++) { stat_data = kzalloc(sizeof(*stat_data), GFP_KERNEL); @@ -600,13 +602,15 @@ static int kvm_create_vm_debugfs(struct kvm *kvm) return r; out_err_clean: - debugfs_remove_recursive(kvm->debugfs_dentry); kfree(stat_data); for (i--; i >= 0; i--) kfree(kvm->debugfs_data[i]); kfree(kvm->debugfs_data); -out_err: + +err_remove_dir: + debugfs_remove_recursive(kvm->debugfs_dentry); + return r; }