* [PATCH v2] s390: raw3270: Handle allocation failures
@ 2026-08-18 7:32 Triet Hoang
2026-08-19 5:45 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Triet Hoang @ 2026-08-18 7:32 UTC (permalink / raw)
To: hca
Cc: gor, agordeev, borntraeger, svens, linux-s390, linux-kernel, Triet Hoang
Check the return values of kzalloc_obj() and kzalloc() before using the
allocated memory. Free the allocated resources on subsequent initialization
failures to avoid leaking memory.
Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com>
---
Changes in v2:
- Destroy the console device on allocation failure.
- Do not free rp after raw3270_setup_device() success.
---
drivers/s390/char/raw3270.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index aa9c4d81225c..ff397396b440 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -814,10 +814,23 @@ struct raw3270 __init *raw3270_setup_console(void)
return ERR_CAST(cdev);
rp = kzalloc_obj(*rp, GFP_KERNEL | GFP_DMA);
+ if (!rp) {
+ ccw_device_destroy_console(cdev);
+ return ERR_PTR(-ENOMEM);
+ }
ascebc = kzalloc(256, GFP_KERNEL);
+ if (!ascebc) {
+ ccw_device_destroy_console(cdev);
+ kfree(rp);
+ return ERR_PTR(-ENOMEM);
+ }
rc = raw3270_setup_device(cdev, rp, ascebc);
- if (rc)
+ if (rc) {
+ ccw_device_destroy_console(cdev);
+ kfree(rp->ascebc);
+ kfree(rp);
return ERR_PTR(rc);
+ }
set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
rc = ccw_device_enable_console(cdev);
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] s390: raw3270: Handle allocation failures
2026-08-18 7:32 [PATCH v2] s390: raw3270: Handle allocation failures Triet Hoang
@ 2026-08-19 5:45 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2026-08-19 5:45 UTC (permalink / raw)
To: Triet Hoang, linux-s390, Alexander Gordeev,
Christian Bornträger, Heiko Carstens, Sven Schnelle,
Vasily Gorbik
Cc: LKML, kernel-janitors, Kees Cook
> Check the return values of kzalloc_obj() and kzalloc() before using the
> allocated memory. Free the allocated resources on subsequent initialization
> failures to avoid leaking memory.
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2#n145
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v7.2#n34
* Please avoid duplicate source code also for an improved implementation of
the function “raw3270_setup_console”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.2#n526
https://elixir.bootlin.com/linux/v7.2/source/drivers/s390/char/raw3270.c#L802-L839
* How do you think about to increase the application of scope-based resource management?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-19 5:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18 7:32 [PATCH v2] s390: raw3270: Handle allocation failures Triet Hoang
2026-08-19 5:45 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®