* [PATCH] serial: core: fix -EPROBE_DEFER handling in init
@ 2023-06-14 6:36 Dan Carpenter
2023-06-14 6:46 ` Tony Lindgren
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2023-06-14 6:36 UTC (permalink / raw)
To: Tony Lindgren
Cc: Greg Kroah-Hartman, Jiri Slaby, linux-serial, kernel-janitors
The -EPROBE_DEFER error path in serial_base_device_init() is a bit
awkward. Before the call to device_initialize(dev) then we need to
manually release all the device resources. And after the call then we
need to call put_device() to release the resources. Doing either one
wrong will result in a leak or a use after free.
So let's wait to return -EPROBE_DEFER until after the call to
device_initialize(dev) so that way callers do not have to handle
-EPROBE_DEFER as a special case. Now callers can just use put_device()
for clean up.
The second issue with the -EPROBE_DEFER path is that deferring is not
supposed to be a fatal error, but instead it's normal part of the
init process and the kernel recovers from it automatically. That means
we should not print an error message but just a debug message on this
path.
Fixes: 539914240a01 ("serial: core: Fix probing serial_base_bus devices")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/tty/serial/serial_base_bus.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c
index 9de9f6fa6481..6ff59c89d867 100644
--- a/drivers/tty/serial/serial_base_bus.c
+++ b/drivers/tty/serial/serial_base_bus.c
@@ -50,17 +50,17 @@ static int serial_base_device_init(struct uart_port *port,
void (*release)(struct device *dev),
int id)
{
- if (!serial_base_initialized) {
- dev_err(port->dev, "uart_add_one_port() called before arch_initcall()?\n");
- return -EPROBE_DEFER;
- }
-
device_initialize(dev);
dev->type = type;
dev->parent = parent_dev;
dev->bus = &serial_base_bus_type;
dev->release = release;
+ if (!serial_base_initialized) {
+ dev_dbg(port->dev, "uart_add_one_port() called before arch_initcall()?\n");
+ return -EPROBE_DEFER;
+ }
+
return dev_set_name(dev, "%s.%s.%d", type->name, dev_name(port->dev), id);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] serial: core: fix -EPROBE_DEFER handling in init
2023-06-14 6:36 [PATCH] serial: core: fix -EPROBE_DEFER handling in init Dan Carpenter
@ 2023-06-14 6:46 ` Tony Lindgren
0 siblings, 0 replies; 2+ messages in thread
From: Tony Lindgren @ 2023-06-14 6:46 UTC (permalink / raw)
To: Dan Carpenter
Cc: Greg Kroah-Hartman, Jiri Slaby, linux-serial, kernel-janitors
* Dan Carpenter <dan.carpenter@linaro.org> [230614 06:36]:
> The -EPROBE_DEFER error path in serial_base_device_init() is a bit
> awkward. Before the call to device_initialize(dev) then we need to
> manually release all the device resources. And after the call then we
> need to call put_device() to release the resources. Doing either one
> wrong will result in a leak or a use after free.
>
> So let's wait to return -EPROBE_DEFER until after the call to
> device_initialize(dev) so that way callers do not have to handle
> -EPROBE_DEFER as a special case. Now callers can just use put_device()
> for clean up.
>
> The second issue with the -EPROBE_DEFER path is that deferring is not
> supposed to be a fatal error, but instead it's normal part of the
> init process and the kernel recovers from it automatically. That means
> we should not print an error message but just a debug message on this
> path.
>
> Fixes: 539914240a01 ("serial: core: Fix probing serial_base_bus devices")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Thanks for fixing these issues:
Reviewed-by: Tony Lindgren <tony@atomide.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-14 6:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 6:36 [PATCH] serial: core: fix -EPROBE_DEFER handling in init Dan Carpenter
2023-06-14 6:46 ` Tony Lindgren
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).