Linux-Fsdevel Archive on
 help / color / Atom feed
* Device "minor overflow" behavior differences in register_chrdev_region vs alloc_chrdev_region
@ 2020-07-31 20:18 César DH
  0 siblings, 0 replies; only message in thread
From: César DH @ 2020-07-31 20:18 UTC (permalink / raw)
  To: linux-fsdevel


I tried my best to be concise. It's my first time reaching out to a
maintainer so if this is not the proper channel for this type of thing
please correct me.

I'm trying to learn about device drivers from, and  I read that a large-enough
requested minor range might spill over to the next major number when
using register_chrdev_region (chapter 3 page 45)

I decided to verify this claim on a toy module (basic c sample module
and makefile):

The code requests 2 devices starting from the last available minor,
which overflows by one.
The module will use alloc_chrdev_region or register_chrdev_region
depending on whether 'alloc' was #defined.

register_chrdev_region just works, and I can see two major entries in
/proc/devices for "mydevice" (with the code above, that would be
majors 400 and 401 if available). The unregister code cleanly removes
those two entries as well.

alloc_chrdev_region, however, fails on my recent (5.4) kernel with:
CHRDEV "mydevice" minor range requested (1048575-1048576) is out of
range of maximum range (0-1048575) for a single major

Which led me to this patch from just last year:

If I'm reading this correctly, the patch claims that
register_chrdev_region was already doing such a check, so it would
make sense to add the same check to alloc_chrdev_region via

But register_chrdev_region seems to handle this cleanly, as the book
I'm reading suggests. I don't understand why alloc_chrdev_region was
modified to fail then.

I tried on an earlier kernel (4.19) that I believe doesn't have this
patch, and the same call to alloc_chrdev_region succeeded. However, I
did notice only one major appears on /proc/devices and that
unregistering does not seem to make the entry go away. So perhaps that
was already broken in another way?

Are these differences in behavior intentional? It almost seems like
the above patch introduced a bug (or partially fixed an older bug) but
I suppose it's likely that I just misunderstand something. I also
suppose nobody's exercising the overflowing behavior so it's likely
nobody has cared even if it was a real bug. At least the current
behavior fails which seems cleaner than passing and not letting me
unregister later. But register_chrdev_region just works everywhere, so
this felt like a bug. I wasn't able to find any reports about this


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 20:18 Device "minor overflow" behavior differences in register_chrdev_region vs alloc_chrdev_region César DH

Linux-Fsdevel Archive on

Archives are clonable:
	git clone --mirror linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ \
	public-inbox-index linux-fsdevel

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone