Skip to contentSkip to conversation

regmap: debugfs: Use __free(kfree) for regmap_reg_ranges_read_file

PATCH In review Peng Fan (OSS) 2 participants 2 messages Oct 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: debugfs: Use __free(kfree) for regmap_reg_ranges_read_file

From: Peng Fan <[email protected]>

Convert buf and entry in regmap_reg_ranges_read_file() from manual kfree() to __free(kfree) scope-based cleanup. This eliminates the goto error path and the manual kfree(buf) on entry allocation failure, simplifying the function to use straight-line returns.

---
 drivers/base/regmap/regmap-debugfs.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/base/regmap/regmap-debugfs.c +6 -14
index b2ae52a21331..b62a5dce027b 100644
@@ -358,8 +358,6 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file,
 	struct regmap_debugfs_off_cache *c;
 	loff_t p = 0;
 	size_t buf_pos = 0;
-	char *buf;
-	char *entry;
 	int ret;
 	unsigned int entry_len;
 
@@ -369,15 +367,13 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file,
 	if (count > (PAGE_SIZE << MAX_PAGE_ORDER))
 		count = PAGE_SIZE << MAX_PAGE_ORDER;
 
-	buf = kmalloc(count, GFP_KERNEL);
+	char *buf __free(kfree) = kmalloc(count, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
-	entry = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!entry) {
-		kfree(buf);
+	char *entry __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!entry)
 		return -ENOMEM;
-	}
 
 	/* While we are at it, build the register dump cache
 	 * now so the read() operation on the `registers' file
@@ -404,17 +400,13 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file,
 		}
 	}
 
-	kfree(entry);
 	ret = buf_pos;
 
-	if (copy_to_user(user_buf, buf, buf_pos)) {
-		ret = -EFAULT;
-		goto out_buf;
-	}
+	if (copy_to_user(user_buf, buf, buf_pos))
+		return -EFAULT;
 
 	*ppos += buf_pos;
-out_buf:
-	kfree(buf);
+
 	return ret;
 }
 

---
base-commit: 5ff1a5ca9f58681f870501ac58c4293306fdce0e
change-id: 20261008-regmap-debugfs-fix-26aaa0027aa1

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
maintainer
#1 lore raw
Quoted 1 line · Peng Fan (OSS)

regmap: debugfs: Use __free(kfree) for regmap_reg_ranges_read_file

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-7.4

Thanks!

[1/1] regmap: debugfs: Use __free(kfree) for regmap_reg_ranges_read_file

      https://git.kernel.org/broonie/regmap/c/f52260f49b10

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark