Re: [PATCH v2] regmap: debugfs: Fix name collision without atomic operations

From: Mark Brown
Date: Tue Mar 04 2025 - 09:43:54 EST


On Tue, Mar 04, 2025 at 10:24:52PM +0800, Zxyan Zhu wrote:

> Changes since v1:
> - Replaced atomic_read + atomic_inc with atomic_inc_return.
> - Added atomic_dec in the error path to maintain index consistency.
> - Updated the commit message to clarify the fix.
>
> Signed-off-by: Zxyan Zhu <zxyan20@xxxxxxx>
> ---

As covered in submitting-patches.rst the inter-version changelog should
be after the ---.

> - map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d",
> - dummy_index);
> - if (!map->debugfs_name)
> + index = atomic_inc_return(&dummy_index);
> + map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d", index);
> + if (!map->debugfs_name) {
> + atomic_dec(&dummy_index);

Adding the decrement seems racy, we could increment again between
getting index and kasprintf() failing so might not get back to the
starting point. It'd be a little messy to skip a number but it doesn't
really matter, and if we're under that much memory pressure probably
nobody's even going to look, so I don't see any reason to decrement.

Attachment: signature.asc
Description: PGP signature