Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4844375yba; Mon, 13 May 2019 00:12:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+EKBvOnCRKL+q9PxiQW+3/ypq6WHEieN5QSmzTZ1hf/2vKa1Q3Yc6IwyP5Q1xFvY/PyQU X-Received: by 2002:a63:d016:: with SMTP id z22mr29688519pgf.116.1557731568983; Mon, 13 May 2019 00:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557731568; cv=none; d=google.com; s=arc-20160816; b=lZDznPVpLBote8quImoxIZO4t75tkYLZuRZbNaHHvXna4qdmOzkYrw3dFi//6BL7zi /zYoFgJfxsiTS9XzxFLkHgkRQdEmfCELtS4bHddlts7vFGkmo/EnnEWHG2JzYgHGRXAL ULOFgrppDiXGYw6vngbMuo82IKUfLyQ9JSv7nJm9DdVk4608uiOAoHTpzz6MAi03Mlis 6I5WskL8+6Jatp26uCUT72NbNfSGUJXwXAfslXnbMDLkBXsAKBvP8TfHpbJ7LGkT5jis ZnpqcboNkZWAdm75puFjkt34R3ZkG2vkoCzWi7Kz0SQDG5FvtQBJ8v2vlg4c5h+qcOFi p/KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=i04w62mHkkU7SbeJYJwwlNHmwqieCJwuRwi27h7qWzE=; b=jVYQYBiFhvPLncYeWX56KAADGpNHX8g8GDGayNxQQokfhm8M3tFfqF/mHxozklUWsd 0qKiQvd+lcAoYBCdFHTFfq1utO/2Vekk5/cvxw6Nb4V+8Qwe40GG3wI+16sg6LhcW7m9 k7rBokZrDKRnm/BemC0OaLiLKX6NICGkkqfFR0i0lGAeV5djFUoVmh0Exnpy6lE4sm1l D/YizZ/0QHwsiQP2qKPZoTI/d/v8IHrIxPN6ItX8sQerarmQR+hFX3vTvLSYGwIXw1Ip dDqVMMU5HdlaJLpO1mZpXPUSZ/4MXUD/kbZO/N7bu5YAIs7g+9zctcjWMuh4mu7YotQt o0lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OsTFJpxD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7si15549682pgg.235.2019.05.13.00.12.32; Mon, 13 May 2019 00:12:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OsTFJpxD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727797AbfEMHLg (ORCPT + 99 others); Mon, 13 May 2019 03:11:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:60782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbfEMHLe (ORCPT ); Mon, 13 May 2019 03:11:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 309E720C01; Mon, 13 May 2019 07:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557731493; bh=JHz55aj1jOXjRyLpFMa6q/x5TIErYcVd6rB/qLKbI+Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OsTFJpxDlRqld1mSKmfzxVPckOCDOPWTXySJxIYWS6hTv9/JjQvr4L0fksi5bW8Y1 6G9WCmHtvK8cRkL08gZ1WGb0DVRxpo+8/w22X+TTk1iI7meSibIGfRfHrvm1ibV4XE OvyfWlKygzA4OSX2WW8YMUMmKjVzxirK5J5ufKYE= Date: Mon, 13 May 2019 09:11:31 +0200 From: Greg Kroah-Hartman To: Nikolay Borisov Cc: "Tobin C. Harding" , Chris Mason , Josef Bacik , David Sterba , "Rafael J. Wysocki" , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] fs: btrfs: Fix error path kobject memory leak Message-ID: <20190513071131.GD2868@kroah.com> References: <20190513033912.3436-1-tobin@kernel.org> <20190513033912.3436-2-tobin@kernel.org> <132a9723-98c4-24ea-c04d-ec41124aa5f9@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <132a9723-98c4-24ea-c04d-ec41124aa5f9@suse.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 13, 2019 at 08:59:56AM +0300, Nikolay Borisov wrote: > > > On 13.05.19 г. 6:39 ч., Tobin C. Harding wrote: > > If a call to kobject_init_and_add() fails we must call kobject_put() > > otherwise we leak memory. > > > > Calling kobject_put() when kobject_init_and_add() fails drops the > > refcount back to 0 and calls the ktype release method. > > > > Add call to kobject_put() in the error path of call to > > kobject_init_and_add(). > > > > Signed-off-by: Tobin C. Harding > > --- > > fs/btrfs/extent-tree.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > > index c5880329ae37..5e40c8f1e97a 100644 > > --- a/fs/btrfs/extent-tree.c > > +++ b/fs/btrfs/extent-tree.c > > @@ -3981,8 +3981,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) > > info->space_info_kobj, "%s", > > alloc_name(space_info->flags)); > > if (ret) { > > - percpu_counter_destroy(&space_info->total_bytes_pinned); > > - kfree(space_info); > > + kobject_put(&space_info->kobj); > > If you are only fixing kobject-related code then why do you delete > correct code as well? percpu_counter_Destroy is needed to dispose of the > percpu state which might have been allocated in percpu_counter_init > based on whether CONFIG_SMP is enabled or not? Also, the call to kfree > is required. Both of those will happen in space_info_release() when the kobject is properly disposed of with this last put to the kobject reference. Reviewed-by: Greg Kroah-Hartman