Re: [PATCH v3] regmap: debugfs: Fix name collision without atomic operations
From: Greg KH
Date: Wed Mar 05 2025 - 09:24:28 EST
On Wed, Mar 05, 2025 at 09:32:52PM +0800, Zxyan Zhu wrote:
> Thanks for the feedback! I think using atomic_t is a better fit here
> than idr because:
> 1. It's lighter and simpler for our basic indexing needs.
No, idr, and ida (don't remember which is which for this use case, but
one of them is the right one) was explicitly written for this exact type
of functionality.
> 2. No extra resource management is needed. If we use idr, we'd have to
> handle resource cleanup and add locks for debugfs_init/debugfs_exit
> concurrency.
The idr has a lock in it, right? Use that.
> 3. As Mark mentioned, id continuity isn't a hard requirement, so we
> can even skip the atomic_dec on kasprintf failure.
Again, use the data structure designed for this very thing. To ignore
that feels very odd.
Drivers should almost NEVER use atomic values, as there are other apis
to use instead that are correct. If you find yourself using one, always
verify that you really should be doing that.
thanks,
greg k-h