Message ID | 20240502040255.655957-3-weifeng.liu.z@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | Defer probing of SAM if serdev device is not ready | expand |
On Thu, May 02, 2024 at 12:02:46PM +0800, Weifeng Liu wrote: > This is an attempt to alleviate race conditions in the SAM driver where > essential resources like serial device and GPIO pins are not ready at > the time ssam_serial_hub_probe() is called. Instead of giving up > probing, a better way would be to defer the probing by returning > -EPROBE_DEFER, allowing the kernel try again later. > > However, there is no way of identifying all such cases from other real > errors in a few days. So let's take a gradual approach identify and > address these cases as they arise. This commit marks the initial step > in this process. ... > + /* The following step can fail when it's called too early before the > + * underlying uart device is ready (in this case -ENXIO is returned). UART > + * Instead of simply giving up and losing everything, we can defer > + * the probing by returning -EPROBE_DEFER so that the kernel would be > + * able to retry later. */ /* * Use correct style for the comments. * Here is the example. */ > status = serdev_device_open(serdev); > - if (status) > + if (status == -ENXIO) > + status = -EPROBE_DEFER; > + if (status) { > + dev_err_probe(&serdev->dev, status, > + "failed to open serdev device\n"); > goto err_devopen; > + } ... Hans, not sure if it helps, but we added similar into I²C and SPI code. 2dea645ffc21 ("i2c: acpi: Return error pointers from i2c_acpi_new_device()") 9c22ec4ac27b ("spi: Return deferred probe error when controller isn't yet available")
diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c index 9591a28bc38a..72a521dd729c 100644 --- a/drivers/platform/surface/aggregator/core.c +++ b/drivers/platform/surface/aggregator/core.c @@ -645,9 +645,20 @@ static int ssam_serial_hub_probe(struct serdev_device *serdev) /* Set up serdev device. */ serdev_device_set_drvdata(serdev, ctrl); serdev_device_set_client_ops(serdev, &ssam_serdev_ops); + + /* The following step can fail when it's called too early before the + * underlying uart device is ready (in this case -ENXIO is returned). + * Instead of simply giving up and losing everything, we can defer + * the probing by returning -EPROBE_DEFER so that the kernel would be + * able to retry later. */ status = serdev_device_open(serdev); - if (status) + if (status == -ENXIO) + status = -EPROBE_DEFER; + if (status) { + dev_err_probe(&serdev->dev, status, + "failed to open serdev device\n"); goto err_devopen; + } astatus = ssam_serdev_setup_via_acpi(ssh->handle, serdev); if (ACPI_FAILURE(astatus)) {
This is an attempt to alleviate race conditions in the SAM driver where essential resources like serial device and GPIO pins are not ready at the time ssam_serial_hub_probe() is called. Instead of giving up probing, a better way would be to defer the probing by returning -EPROBE_DEFER, allowing the kernel try again later. However, there is no way of identifying all such cases from other real errors in a few days. So let's take a gradual approach identify and address these cases as they arise. This commit marks the initial step in this process. Suggested-by: Maximilian Luz <luzmaximilian@gmail.com> Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com> --- drivers/platform/surface/aggregator/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)