Re: [PATCH v2 2/4] docs: driver-model: document driver_override

From: Frank Li

Date: Tue Mar 03 2026 - 16:07:04 EST


From: Frank Li (AI-BOT) <frank.li@xxxxxxx>

AI bot review and may be useless.

> +Driver Override
> +~~~~~~~~~~~~~~~
> +
> +Userspace may override the standard matching by writing a driver name to
> +a device's ``driver_override`` sysfs attribute. When set, only a driver
> +whose name matches the override will be considered during binding. This
> +bypasses all bus-specific matching (OF, ACPI, ID tables, etc.).
> +
> +The override may be cleared by writing an empty string, which returns
> +the device to standard matching rules. Writing to ``driver_override``
> +does not automatically unbind the device from its current driver or
> +make any attempt to load the specified driver.
> +
> +Buses opt into this mechanism by setting the ``driver_override`` flag in
> +their ``struct bus_type``::
> +
> + const struct bus_type example_bus_type = {
> + ...
> + .driver_override = true,
> + };
> +
> +When the flag is set, the driver core automatically creates the
> +``driver_override`` sysfs attribute for every device on that bus.
> +
> +The bus's ``match()`` callback should check the override before performing
> +its own matching, using ``device_match_driver_override()``::
> +
> + static int example_match(struct device *dev, const struct device_driver *drv)
> + {
> + int ret;
> +
> + ret = device_match_driver_override(dev, drv);
> + if (ret >= 0)
> + return ret;
> +
> + /* Fall through to bus-specific matching... */
> + }
> +
> +``device_match_driver_override()`` returns > 0 if the override matches
> +the given driver, 0 if the override is set but does not match, or < 0 if
> +no override is set at all.
> +
> +Additional helpers are available:
> +
> +- ``device_set_driver_override()`` - set or clear the override from kernel code.
> +- ``device_has_driver_override()`` - check whether an override is set.

Minor: Consider adding a note that the override persists across unbind/rebind
cycles, or clarify the lifetime semantics. The current text doesn't explicitly
state whether the override survives device removal or driver unload.

Also, the example code comment "Fall through to bus-specific matching..." is
slightly misleading—there's no actual fallthrough; the function returns. Consider
rewording to "Continue with bus-specific matching logic" for clarity.