All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] char: misc: Make the code for allocating minor in misc_register more concise
Date: Tue, 9 Sep 2025 11:07:06 +0200	[thread overview]
Message-ID: <2025090910-tactile-devourer-1070@gregkh> (raw)
In-Reply-To: <20250909085835.2784-1-zhangjiao2@cmss.chinamobile.com>

On Tue, Sep 09, 2025 at 04:58:35PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> There is no need to check the registered misc dev in misc_list. 
> If misc_minor_alloc failed, it meens the minor is already alloced 
> and the misc dev is linked in misc_list.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>  drivers/char/misc.c | 32 +++++++-------------------------
>  1 file changed, 7 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index a0aae0fc7926..fc2f5e8b2f95 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -211,6 +211,7 @@ int misc_register(struct miscdevice *misc)
>  	dev_t dev;
>  	int err = 0;
>  	bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR);
> +	int minor = 0;
>  
>  	if (misc->minor > MISC_DYNAMIC_MINOR) {
>  		pr_err("Invalid fixed minor %d for miscdevice '%s'\n",
> @@ -221,32 +222,13 @@ int misc_register(struct miscdevice *misc)
>  	INIT_LIST_HEAD(&misc->list);
>  
>  	mutex_lock(&misc_mtx);
> -
> -	if (is_dynamic) {
> -		int i = misc_minor_alloc(misc->minor);
> -
> -		if (i < 0) {
> -			err = -EBUSY;
> -			goto out;
> -		}
> -		misc->minor = i;
> -	} else {
> -		struct miscdevice *c;
> -		int i;
> -
> -		list_for_each_entry(c, &misc_list, list) {
> -			if (c->minor == misc->minor) {
> -				err = -EBUSY;
> -				goto out;
> -			}
> -		}
> -
> -		i = misc_minor_alloc(misc->minor);
> -		if (i < 0) {
> -			err = -EBUSY;
> -			goto out;
> -		}
> +	minor = misc_minor_alloc(misc->minor);
> +	if (minor < 0) {
> +		err = -EBUSY;
> +		goto out;
>  	}
> +	if (is_dynamic)
> +		misc->minor = minor;
>  
>  	dev = MKDEV(MISC_MAJOR, misc->minor);
>  

Does this pass the new test suite for the misc code allocation logic
that we now have in the tree?  Or do we need to write a new test-case
for this codepath?

thanks,

greg k-h

  reply	other threads:[~2025-09-09  9:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09  8:58 [PATCH] char: misc: Make the code for allocating minor in misc_register more concise zhangjiao2
2025-09-09  9:07 ` Greg KH [this message]
2025-09-10  1:44   ` zhangjiao2
2025-10-07 12:45     ` Greg KH
2025-11-27  9:55     ` Greg KH

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=2025090910-tactile-devourer-1070@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhangjiao2@cmss.chinamobile.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.