在 2025/1/28 17:39, Amit Shah 写道:
On Tue, 2025-01-28 at 13:52 +0800, oushixiong1...@163.com wrote:
From: Shixiong Ou <oushixi...@kylinos.cn>
Convert to devm_* funcs so that no need to manual free in error path.
Signed-off-by: Shixiong Ou <oushixi...@kylinos.cn>
---
drivers/char/virtio_console.c | 43 ++++++++++++++-------------------
--
1 file changed, 17 insertions(+), 26 deletions(-)
[...]
- goto free;
+ return err;
[...]
-
-free:
- kfree(portdev->out_vqs);
- kfree(portdev->in_vqs);
- kfree(vqs_info);
- kfree(vqs);
-
- return err;
}
Hm, I'm not entirely sure about this - the devm_ interface is better,
but to me that just says that it's an extra safety net that avoids
memleaks when we forget to kfree, and not that we deliberately do not
free and get lax about managing allocated memory.
So I'd prefer a patch that keeps all current frees as they are, but
with the added advantage of using the devm interfaces.
Amit
Hi, I don't think driver need to call kfree() by manual if driver use
the devm_ interface
in the probe() phase. This can simplifies the code.
This is similar to the commit "55dd7378ba94 (fbdev: imxfb: Convert to
devm_kmalloc_array())"
Thanks!
Shixiong Ou