The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Carlos Llamas <cmllamas@google.com>
To: Chao Huang <958028483@qq.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	linux-kernel@vger.kernel.org, "Chao Huang" <huangchao@kylinos.cn>
Subject: Re: [PATCH v3] binderfs: free minor on binder-control creation failure
Date: Tue, 11 Aug 2026 02:52:24 +0000	[thread overview]
Message-ID: <anqOaOfvnfpE88aM@google.com> (raw)
In-Reply-To: <tencent_8D7B76C623DA3A29EE73D38217ACB08AFB09@qq.com>

On Tue, Aug 11, 2026 at 09:05:34AM +0800, Chao Huang wrote:
> From: Chao Huang <huangchao@kylinos.cn>
> 
> Both binderfs_binder_ctl_create() implementations allocate a minor before
> creating the binder-control dentry. If d_alloc_name() fails, the error path
> frees the device and drops the inode, but leaves the minor allocated in
> binderfs_minors. Repeated failures can therefore exhaust the global minor
> IDA.
> 
> Release the minor from a dedicated error path after a successful allocation
> in both implementations.
> 
> Signed-off-by: Chao Huang <huangchao@kylinos.cn>
> ---
> Changes in v3:
> - Use a dedicated out_with_minor error path instead of an -ENOSPC sentinel.
> 
>  drivers/android/binder/rust_binderfs.c | 7 ++++++-
>  drivers/android/binderfs.c             | 7 ++++++-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/android/binder/rust_binderfs.c b/drivers/android/binder/rust_binderfs.c
> index ade1c4d92499..0763e3db54bd 100644
> --- a/drivers/android/binder/rust_binderfs.c
> +++ b/drivers/android/binder/rust_binderfs.c
> @@ -421,7 +421,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>  
>  	dentry = d_alloc_name(root, "binder-control");
>  	if (!dentry)
> -		goto out;
> +		goto out_with_minor;
>  
>  	inode->i_private = device;
>  	info->control_dentry = dentry;
> @@ -430,6 +430,11 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>  
>  	return 0;
>  
> +out_with_minor:
> +	mutex_lock(&binderfs_minors_mutex);
> +	ida_free(&binderfs_minors, minor);
> +	mutex_unlock(&binderfs_minors_mutex);
> +
>  out:
>  	kfree(device);
>  	iput(inode);
> diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
> index 361d69f756f5..0e96146ecf69 100644
> --- a/drivers/android/binderfs.c
> +++ b/drivers/android/binderfs.c
> @@ -431,7 +431,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>  
>  	dentry = d_alloc_name(root, "binder-control");
>  	if (!dentry)
> -		goto out;
> +		goto out_with_minor;
>  
>  	inode->i_private = device;
>  	info->control_dentry = dentry;
> @@ -440,6 +440,11 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>  
>  	return 0;
>  
> +out_with_minor:
> +	mutex_lock(&binderfs_minors_mutex);
> +	ida_free(&binderfs_minors, minor);
> +	mutex_unlock(&binderfs_minors_mutex);
> +
>  out:
>  	kfree(device);
>  	iput(inode);
> 
> base-commit: c21bb4193868a8de71fc4693fa741e195fdf5d86
> -- 
> 2.25.1
> 

LGTM,

Acked-by: Carlos Llamas <cmllamas@google.com>

      reply	other threads:[~2026-08-11  2:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 11:23 [PATCH] binderfs: free minor on binder-control creation failure Chao Huang
2026-08-08 13:34 ` Alice Ryhl
2026-08-10  9:32   ` [PATCH v2] " Chao Huang
2026-08-10 20:16     ` Carlos Llamas
2026-08-11  1:05       ` [PATCH v3] " Chao Huang
2026-08-11  2:52         ` Carlos Llamas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anqOaOfvnfpE88aM@google.com \
    --to=cmllamas@google.com \
    --cc=958028483@qq.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=huangchao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tkjos@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox