Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: Fix driver_deferred_probe_check_state() logic

driver_deferred_probe_check_state() has some uninituitive behavior.

* From boot to late_initcall, it returns -EPROBE_DEFER

* From late_initcall to the deferred_probe_timeout (if set)
it returns -ENODEV

* If the deferred_probe_timeout it set, after it fires, it
returns -ETIMEDOUT

This is a bit confusing, as its useful to have the function
return -EPROBE_DEFER while the timeout is still running. This
behavior has resulted in the somwhat duplicative
driver_deferred_probe_check_state_continue() function being
added.

Thus this patch tries to improve the logic, so that it behaves
as such:

* If late_initcall has passed, and modules are not enabled
it returns -ENODEV

* If modules are enabled and deferred_probe_timeout is set,
it returns -EPROBE_DEFER until the timeout, afterwhich it
returns -ETIMEDOUT.

* In all other cases, it returns -EPROBE_DEFER

This will make the deferred_probe_timeout value much more
functional, and will allow us to consolidate the
driver_deferred_probe_check_state() and
driver_deferred_probe_check_state_continue() logic in a later
patch.

Cc: linux-pm@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Saravana Kannan <saravanak@google.com>
Cc: Todd Kjos <tkjos@google.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Link: https://lore.kernel.org/r/20200225050828.56458-2-john.stultz@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

John Stultz and committed by
Greg Kroah-Hartman
c8c43cee e94f62b7

+10 -8
+10 -8
drivers/base/dd.c
··· 237 237 238 238 static int __driver_deferred_probe_check_state(struct device *dev) 239 239 { 240 - if (!initcalls_done) 241 - return -EPROBE_DEFER; 240 + if (!IS_ENABLED(CONFIG_MODULES) && initcalls_done) 241 + return -ENODEV; 242 242 243 243 if (!deferred_probe_timeout) { 244 244 dev_WARN(dev, "deferred probe timeout, ignoring dependency"); 245 245 return -ETIMEDOUT; 246 246 } 247 247 248 - return 0; 248 + return -EPROBE_DEFER; 249 249 } 250 250 251 251 /** 252 252 * driver_deferred_probe_check_state() - Check deferred probe state 253 253 * @dev: device to check 254 254 * 255 - * Returns -ENODEV if init is done and all built-in drivers have had a chance 256 - * to probe (i.e. initcalls are done), -ETIMEDOUT if deferred probe debug 257 - * timeout has expired, or -EPROBE_DEFER if none of those conditions are met. 255 + * Return: 256 + * -ENODEV if initcalls have completed and modules are disabled. 257 + * -ETIMEDOUT if the deferred probe timeout was set and has expired 258 + * and modules are enabled. 259 + * -EPROBE_DEFER in other cases. 258 260 * 259 261 * Drivers or subsystems can opt-in to calling this function instead of directly 260 262 * returning -EPROBE_DEFER. ··· 266 264 int ret; 267 265 268 266 ret = __driver_deferred_probe_check_state(dev); 269 - if (ret < 0) 267 + if (ret != -ENODEV) 270 268 return ret; 271 269 272 270 dev_warn(dev, "ignoring dependency for device, assuming no driver"); ··· 294 292 int ret; 295 293 296 294 ret = __driver_deferred_probe_check_state(dev); 297 - if (ret < 0) 295 + if (ret != -ENODEV) 298 296 return ret; 299 297 300 298 return -EPROBE_DEFER;