public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Gavin Chang <gavin.chang1380@gmail.com>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org
Subject: Re: Bug in chardev checking of overlapping ranges(send again as TEXT/PLAIN)
Date: Fri, 27 May 2016 11:29:21 -0700	[thread overview]
Message-ID: <20160527182921.GA22809@vader> (raw)
In-Reply-To: <CAPvpz1hJoXtYDanLjCwGd6oSqsaBH-G2c7C95mwf2-_xASMemA@mail.gmail.com>

On Wed, May 25, 2016 at 10:53:36PM +0800, Gavin Chang wrote:
> Hi,
> 
> I'm a new person to learn Linux kernel.
> 
> In fs/char_dev.c function __register_chrdev_region(), there is the
> following code:
> 
> for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
> if ((*cp)->major > major ||
>     ((*cp)->major == major &&
>      (((*cp)->baseminor >= baseminor) ||
>       ((*cp)->baseminor + (*cp)->minorct > baseminor))))
> break;
> 
> /* Check for overlapping minor ranges.  */
> if (*cp && (*cp)->major == major) {
> int old_min = (*cp)->baseminor;
> int old_max = (*cp)->baseminor + (*cp)->minorct - 1;
> int new_min = baseminor;
> int new_max = baseminor + minorct - 1;
> 
> /* New driver overlaps from the left.  */
> if (new_max >= old_min && new_max <= old_max) {
> ret = -EBUSY;
> goto out;
> }
> 
> /* New driver overlaps from the right.  */
> if (new_min <= old_max && new_min >= old_min) {
> ret = -EBUSY;
> goto out;
> }
> }
> 
> I think there is a bug in checking of overlapping ranges.
> For example, driver X has registered with major=x and minor=1-3, and
> __register_chrdev_region() will allow driver Y to register with
> major=x and minor=0-4.
> The minor of driver Y will not meet the two if statements:
> if (new_max >= old_min && new_max <= old_max)  and if (new_min <=
> old_max && new_min >= old_min)
> 
> The attached is my patch to repair this problem.
> And there is a related commit 01d553d0fe9f90a132c5ff494872be8d4126be1e
> for reference.

> diff --git a/fs/char_dev.c b/fs/char_dev.c
> index 24b1425..d65765e 100644
> --- a/fs/char_dev.c
> +++ b/fs/char_dev.c
> @@ -107,29 +107,14 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
>  
>  	for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
>  		if ((*cp)->major > major ||
> -		    ((*cp)->major == major &&
> -		     (((*cp)->baseminor >= baseminor) ||
> -		      ((*cp)->baseminor + (*cp)->minorct > baseminor))))
> +		    ((*cp)->major == major && ((*cp)->baseminor + (*cp)->minorct > baseminor)))
>  			break;
>  
>  	/* Check for overlapping minor ranges.  */
> -	if (*cp && (*cp)->major == major) {
> -		int old_min = (*cp)->baseminor;
> -		int old_max = (*cp)->baseminor + (*cp)->minorct - 1;
> -		int new_min = baseminor;
> -		int new_max = baseminor + minorct - 1;
> -
> -		/* New driver overlaps from the left.  */
> -		if (new_max >= old_min && new_max <= old_max) {
> -			ret = -EBUSY;
> -			goto out;
> -		}
> -
> -		/* New driver overlaps from the right.  */
> -		if (new_min <= old_max && new_min >= old_min) {
> -			ret = -EBUSY;
> -			goto out;
> -		}
> +	if (*cp && (*cp)->major == major &&
> +	    (*cp)->baseminor < baseminor + minorct) {
> +               ret = -EBUSY;
> +               goto out;
>  	}
>  
>  	cd->next = *cp;

Gavin,

You're going to want to read Documentation/SubmittingPatches. Basically,
you want to use git commit -s, git format-patch, and git send-email
rather than attachments.

Thanks,
-- 
Omar

      reply	other threads:[~2016-05-27 18:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-25 14:53 Bug in chardev checking of overlapping ranges(send again as TEXT/PLAIN) Gavin Chang
2016-05-27 18:29 ` Omar Sandoval [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=20160527182921.GA22809@vader \
    --to=osandov@osandov.com \
    --cc=gavin.chang1380@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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