Re: [PATCH RFC] char: misc: Enforce simple minor space division

From: Greg Kroah-Hartman
Date: Tue Jun 24 2025 - 11:51:27 EST


On Fri, Jun 20, 2025 at 10:53:32PM +0800, Zijun Hu wrote:
> From: Zijun Hu <zijun.hu@xxxxxxxxxxxxxxxx>
>
> Enforce simple minor space division related to macro MISC_DYNAMIC_MINOR
> defined as 255 currently:
>
> < 255 : Fixed minor codes
> == 255 : Indicator to request dynamic minor code
> > 255 : Dynamic minor codes requested

Is this the rule today? If so, does the now-added tests we have for
misc device properly test for this?

> This enforcing division also solves misc_register() reentry issue below:
>
> // Suppose both static @dev_A and @dev_B want to request dynamic minors.
> @dev_A.minor(255) @dev_B.minor(255)
>
> // Register @dev_A then de-register it.
> @dev_A.minor(255) -> registered -> @dev_A.minor(500) -> de-registered
> -> @dev_A.minor(500)
>
> // Register @dev_B
> @dev_B.minor(255) -> registered -> @dev_B.minor(500)
>
> // Register @dev_A again
> @dev_A.minor(500) -> encounter -EBUSY error since @dev_B has got 500.

Does this ever really happen?

And with the recent changes in the last dev cycle in this code area, is
it still an issue?

> Side effects:
> It will be refused to register device whose fixed minor > 255.

Do we have any in-kernel users that are > 255?

thanks,

greg k-h