[PATCH v2 6/7] regmap: debugfs: Use __free(kfree) in regmap_name_read_file()
From: Peng Fan (OSS)
Date: Fri Oct 02 2026 - 09:22:58 EST
From: Peng Fan <peng.fan@xxxxxxx>
Use the __free(kfree) cleanup helper for the temporary buffer allocated
by regmap_name_read_file().
Remove the explicit kfree() calls from the error and success paths.
No functional change.
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/base/regmap/regmap-debugfs.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index ec207548a6bb..0a9c27426f15 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -38,10 +38,9 @@ static ssize_t regmap_name_read_file(struct file *file,
{
struct regmap *map = file->private_data;
const char *name = "nodev";
+ char *buf __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
int ret;
- char *buf;
- buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -49,14 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file,
name = map->dev->driver->name;
ret = snprintf(buf, PAGE_SIZE, "%s\n", name);
- if (ret >= PAGE_SIZE) {
- kfree(buf);
+ if (ret >= PAGE_SIZE)
return ret;
- }
- ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
- kfree(buf);
- return ret;
+ return simple_read_from_buffer(user_buf, count, ppos, buf, ret);
}
static const struct file_operations regmap_name_fops = {
--
2.51.0