Re: [PATCH 3/8] char: misc: Introduce misc_sync_register()
From: Jason Gunthorpe
Date: Tue Apr 28 2026 - 12:28:54 EST
On Mon, Apr 27, 2026 at 09:46:54PM +0800, Tzung-Bi Shih wrote:
> Introduce misc_sync_register() to support synchronous file operations
> for misc devices. This aims to prevent Use-After-Free errors when a
> device is deregistered while file operations are still in progress or
> files are open.
>
> It creates a synchronization context that wraps supported file
> operations and ensures the device is still registered before invoking
> the file operations.
>
> The minor number is deferred from being freed immediately on
> deregistration and is used as a primary key to search for the
> synchronization context in `misc_sync_ctx_list` after the device is
> unregistered.
>
> Performance impact:
> - All file operations are serialized by a global lock.
> - All file operations perform a linear search to find the corresponding
> miscdevice.
This doesn't seem like a serious proposal, this is too much
performance cost.
Jason