Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753188AbdF0New (ORCPT ); Tue, 27 Jun 2017 09:34:52 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40210 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753124AbdF0Nep (ORCPT ); Tue, 27 Jun 2017 09:34:45 -0400 Date: Tue, 27 Jun 2017 14:34:43 +0100 From: Al Viro To: Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, pbonzini@redhat.com Subject: Re: [PATCH v1 1/1] KVM: add missing kvm_put_kvm in case of failure Message-ID: <20170627133443.GF10672@ZenIV.linux.org.uk> References: <1498564636-20259-1-git-send-email-imbrenda@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1498564636-20259-1-git-send-email-imbrenda@linux.vnet.ibm.com> User-Agent: Mutt/1.8.0 (2017-02-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 926 Lines: 19 On Tue, Jun 27, 2017 at 01:57:16PM +0200, Claudio Imbrenda wrote: > If I'm not missing anything, in case kvm_create_vm_debugfs fails, we > will have a memory leak due to not freeing the kvm object. > > A call to kvm_put_kvm was accidentally removed from an error handling in > commit 506cfba9e726 ("KVM: don't use anon_inode_getfd() before possible failures") > > This patch simply restores the call to kvm_put_kvm, so that the kvm > object is destroyed before returning an error. > > Signed-off-by: Claudio Imbrenda > Fixes: 506cfba9e726 ("KVM: don't use anon_inode_getfd() before possible failures") What you are missing is that by that point we have file->f_op already set, with ->release() being kvm_vm_release(). It will be called by final fput(), and that's what will do your "missing" kvm_put_kvm(). IOW, NAK - removal was not accidental and you've just introduced double-put there.