lkml.org 
[lkml]   [2024]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: [PATCH] regmap: kunit: Fix memory leaks in gen_regmap() and gen_raw_regmap()
From

> - kfree() the buf and *data buffers on the error paths.


Will development interests grow for scope-based resource management?



+++ b/drivers/base/regmap/regmap-kunit.c
@@ -145,9 +145,9 @@ static struct regmap *gen_regmap(struct kunit *test,

- struct regmap *ret;
+ struct regmap *ret = ERR_PTR(-ENOMEM);


How do you think about to use the statement “return ERR_PTR(-ENOMEM);” at the end
instead of the extra variable initialisation?



@@ -172,15 +172,17 @@ static struct regmap *gen_regmap(struct kunit *test,

*data = kzalloc(sizeof(**data), GFP_KERNEL);
if (!(*data))
- return ERR_PTR(-ENOMEM);
+ goto out_free;


I suggest to reconsider the label selection.

Regards,
Markus

\
 
 \ /
  Last update: 2024-05-27 16:35    [W:0.033 / U:2.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site