Skip to content

Commit cef0967

Browse files
Dan Carpentergregkh
authored andcommitted
serial: core: fix -EPROBE_DEFER handling in init
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: 5399142 ("serial: core: Fix probing serial_base_bus devices") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Tony Lindgren <tony@atomide.com> Message-ID: <18318adb-ab2c-4dcc-9f96-498a13d16b80@moroto.mountain> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 20a41a6 commit cef0967

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/tty/serial/serial_base_bus.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ static int serial_base_device_init(struct uart_port *port,
5050
void (*release)(struct device *dev),
5151
int id)
5252
{
53-
if (!serial_base_initialized) {
54-
dev_err(port->dev, "uart_add_one_port() called before arch_initcall()?\n");
55-
return -EPROBE_DEFER;
56-
}
57-
5853
device_initialize(dev);
5954
dev->type = type;
6055
dev->parent = parent_dev;
6156
dev->bus = &serial_base_bus_type;
6257
dev->release = release;
6358

59+
if (!serial_base_initialized) {
60+
dev_dbg(port->dev, "uart_add_one_port() called before arch_initcall()?\n");
61+
return -EPROBE_DEFER;
62+
}
63+
6464
return dev_set_name(dev, "%s.%s.%d", type->name, dev_name(port->dev), id);
6565
}
6666

0 commit comments

Comments
 (0)