Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15068643rwd; Sun, 25 Jun 2023 09:29:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5UEJs/NYSup7Py7iSnPGMfCPazlFsKSZeA6TGR2df6nu3nNvM/IYEfedpvyE1e0m6jpJJD X-Received: by 2002:a17:906:58d2:b0:988:8a11:ab88 with SMTP id e18-20020a17090658d200b009888a11ab88mr19306907ejs.33.1687710588235; Sun, 25 Jun 2023 09:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687710588; cv=none; d=google.com; s=arc-20160816; b=QFo4iQ8gAWtVq1qvCZWaQXoSZZ47de3p7dj/A37pta3hzBfSrKIec0TjGEBCBkcX6W qd4nEie27+078AaOo5iMX1fSgxD+19pgAfUsKirrEYafjnw4nkrDg/82pPpnLOglk0T6 s+jLdx2Iz/gDXl8FnjvnJuFm6stRxo+SxzVQIOapS+ZiOQyVBJpEWRcPzxjCNdO0ucWB pAZTwUpyRCRkItax9BFHaK1lMIv+5uOvv1Kr5s/Yq6HxiCZKwAnNGZm3euhHIhk5sNZ+ Biz8A6crEPoU9M66ER4zQPQr0pzQqHeTb6qvmt7G+hCB++YXYDIp6jumNd5O27izZKxE qkJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JFLugxsktEUk30I/si+Vh7SSN9mbnWpk0wcoJLvWRbg=; fh=yEGWyCm3rNNkDJqgMAInqhKgwhGWgFNh5E/D3lnNpFg=; b=VRkYQrwZ1y6M99+snSWJPlIqnMz5zmchL6jKkAa7WiLcwUhWvOuYJE0drtH4y3qtIH M/uDZUOxBf+okDN68+w1MMq+RXUSbQRzDrMrNmuZlzMhoY9TU3Vze3oSvuOs5IVLJa/s UkWQtEq6WQnA2afGDw7u7oUGm18cR+MnDdRAjxeYzx/+BEPG537C42cmg/RmDyZwp8X2 Bm7xn3SsLDgxKJOsF4bBQc9KLiHp4o/xtApSMTGernx6mGRKShFLAORZvDklD/E8DbTr UIcW5LfHGzc+695FSQTAEoXm9oo9vt5Wq+dKaZDzol7qBRzjoX0CaZ6aDQZ/4m1rOaic kH0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=o+gQCD0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a170906260900b00991bdc48797si138326ejc.95.2023.06.25.09.29.24; Sun, 25 Jun 2023 09:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=o+gQCD0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbjFYQQg (ORCPT + 99 others); Sun, 25 Jun 2023 12:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbjFYQQf (ORCPT ); Sun, 25 Jun 2023 12:16:35 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDEF193 for ; Sun, 25 Jun 2023 09:16:33 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-666ecf9a0ceso1090569b3a.2 for ; Sun, 25 Jun 2023 09:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687709793; x=1690301793; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JFLugxsktEUk30I/si+Vh7SSN9mbnWpk0wcoJLvWRbg=; b=o+gQCD0IFZimetDkGfUumIUgvjQDJeczwryuDzZTdLj/cEc2wchP6dFeh7DcUtX8og 9KTP/LUIXHhy6G22l1GDA4S+omumyn4ZXjN3aXru8ors3Mo79yrEPtyG5UPT/Y3bA3U3 vZD1m3ktvPrFixuzM3M5vLu4XvrVMndO655xO/t5pe/VoklkmDTLZwtN8kUCOZhjfmQD +sgPH7CEarLJzQKQS38Lqs0+yyyXmsqJIxbHi78SsNcks2nmq6GNu+1Pg3AusemPoC3B CLHC5eLtiIfgvtbqbKOSOwuVvnQTr5Z68f3p3dlvulOJRfC51rUndELnT0axw2Mtyo93 K26Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687709793; x=1690301793; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JFLugxsktEUk30I/si+Vh7SSN9mbnWpk0wcoJLvWRbg=; b=jbiyxCbAID6Qwx5zTgIQm9aeex5EOQNmnOFETpXcGaRTWRAIyd/InHVJnqmXwVqotK wU2b1ewCA1Ae4vck6uUVnMcEKSa32BwQrkwzN9pplJgaEeihplCDcQsQ9XGb7KLiPHpY 5QHVwwm6A260ZpnDCt0Kzs7Qz5OTql6MFzFG67zesM2K1VLkR9GLlrAuVrOfwKe1F/ww AhFOaL6l4rB+AuoZ/YbZuHuVMwznNuUh9Er0CTD5No/EamyT1y5x6J/1ltkWFfyJ3fKU rWUn+WMcuIkb2chhgBSuPWdhO/HHKfVCLISxADLBPFO6jiWANzWmdF3SSax4vLDfxeuv +XPw== X-Gm-Message-State: AC+VfDx4Rq0NgO5cbIkKhKmf9jXIybO0DSybAkjvIMVsQ3PgDHy8Y9ZT ljPId7LSLtXhFG1fOAqBGlKoog== X-Received: by 2002:a05:6a00:3a10:b0:668:8596:7524 with SMTP id fj16-20020a056a003a1000b0066885967524mr17673313pfb.20.1687709793248; Sun, 25 Jun 2023 09:16:33 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id f4-20020aa78b04000000b0066884d4efdbsm2503440pfd.12.2023.06.25.09.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jun 2023 09:16:32 -0700 (PDT) Date: Sun, 25 Jun 2023 16:16:28 +0000 From: Carlos Llamas To: Qi Zheng Cc: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, brauner@kernel.org, surenb@google.com, linux-kernel@vger.kernel.org, Qi Zheng Subject: Re: [PATCH] binder: fix memory leak in binder_init() Message-ID: References: <20230625154937.64316-1-qi.zheng@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230625154937.64316-1-qi.zheng@linux.dev> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 25, 2023 at 03:49:37PM +0000, Qi Zheng wrote: > From: Qi Zheng > > In binder_init(), the destruction of binder_alloc_shrinker_init() is not > performed in the wrong path, which will cause memory leaks. So this commit > introduces binder_alloc_shrinker_exit() and calls it in the wrong path to > fix that. > > Signed-off-by: Qi Zheng > --- > drivers/android/binder.c | 1 + > drivers/android/binder_alloc.c | 6 ++++++ > drivers/android/binder_alloc.h | 1 + > 3 files changed, 8 insertions(+) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 486c8271cab7..d720f93d8b19 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -6617,6 +6617,7 @@ static int __init binder_init(void) > > err_alloc_device_names_failed: > debugfs_remove_recursive(binder_debugfs_dir_entry_root); > + binder_alloc_shrinker_exit(); > > return ret; > } > diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c > index 662a2a2e2e84..e3db8297095a 100644 > --- a/drivers/android/binder_alloc.c > +++ b/drivers/android/binder_alloc.c > @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) > return ret; > } > > +void binder_alloc_shrinker_exit(void) > +{ > + unregister_shrinker(&binder_shrinker); > + list_lru_destroy(&binder_alloc_lru); > +} > + > /** > * check_buffer() - verify that buffer/offset is safe to access > * @alloc: binder_alloc for this proc > diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h > index 138d1d5af9ce..dc1e2b01dd64 100644 > --- a/drivers/android/binder_alloc.h > +++ b/drivers/android/binder_alloc.h > @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, > int pid); > extern void binder_alloc_init(struct binder_alloc *alloc); > extern int binder_alloc_shrinker_init(void); > +extern void binder_alloc_shrinker_exit(void); > extern void binder_alloc_vma_close(struct binder_alloc *alloc); > extern struct binder_buffer * > binder_alloc_prepare_to_free(struct binder_alloc *alloc, > -- > 2.30.2 > Thanks for the fix Qi Zheng. Acked-by: Carlos Llamas