linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init()
@ 2021-01-05 11:42 Dan Carpenter
  2021-01-05 16:07 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-01-05 11:42 UTC (permalink / raw)
  To: Mark Brown, Xiaolei Wang
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel, kernel-janitors

This code will leak "map->debugfs_name" because the if statement is
reversed so it only frees NULL pointers instead of non-NULL.  In
fact the if statement is not required and should just be removed
because kfree() accepts NULL pointers.

Fixes: cffa4b2122f5 ("regmap: debugfs: Fix a memory leak when calling regmap_attach_dev")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/base/regmap/regmap-debugfs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index bf03cd343be2..ff2ee87987c7 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -594,9 +594,7 @@ void regmap_debugfs_init(struct regmap *map)
 	}
 
 	if (!strcmp(name, "dummy")) {
-		if (!map->debugfs_name)
-			kfree(map->debugfs_name);
-
+		kfree(map->debugfs_name);
 		map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d",
 						dummy_index);
 		if (!map->debugfs_name)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init()
  2021-01-05 11:42 [PATCH] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init() Dan Carpenter
@ 2021-01-05 16:07 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2021-01-05 16:07 UTC (permalink / raw)
  To: Xiaolei Wang, Dan Carpenter
  Cc: linux-kernel, Greg Kroah-Hartman, kernel-janitors, Rafael J. Wysocki

On Tue, 5 Jan 2021 14:42:29 +0300, Dan Carpenter wrote:
> This code will leak "map->debugfs_name" because the if statement is
> reversed so it only frees NULL pointers instead of non-NULL.  In
> fact the if statement is not required and should just be removed
> because kfree() accepts NULL pointers.

Applied to

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

Thanks!

[1/1] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init()
      commit: f6bcb4c7f366905b66ce8ffca7190118244bb642

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-05 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 11:42 [PATCH] regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init() Dan Carpenter
2021-01-05 16:07 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).