Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753160AbdF0NkQ (ORCPT ); Tue, 27 Jun 2017 09:40:16 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36072 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752753AbdF0NkH (ORCPT ); Tue, 27 Jun 2017 09:40:07 -0400 Subject: Re: [PATCH v1 1/1] KVM: add missing kvm_put_kvm in case of failure To: Al Viro , Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com References: <1498564636-20259-1-git-send-email-imbrenda@linux.vnet.ibm.com> <20170627133443.GF10672@ZenIV.linux.org.uk> From: Paolo Bonzini Message-ID: <8f059d14-b77b-9d33-2607-1f8aade40a68@redhat.com> Date: Tue, 27 Jun 2017 15:40:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170627133443.GF10672@ZenIV.linux.org.uk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1052 Lines: 26 On 27/06/2017 15:34, Al Viro wrote: > 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. Better add a comment, I'll reuse your wording. Thanks. Paolo