Re: [PATCH 1/2] driver: core: Allow drivers to opt out of driver_override
From: Greg Kroah-Hartman
Date: Tue Sep 22 2026 - 08:27:19 EST
On Tue, Sep 22, 2026 at 01:38:28PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@xxxxxxxxxx>
>
> Some drivers rely on device data obtained through device ID matching and
> will not work otherwise. Some such drivers don't check for the validity
> of the device data because it is never NULL when the device is matched
> against the device ID table.
>
> However, Uwe recently pointed out that drivers always need to check this
> device data because any device can be forced to bind against a driver if
> their driver_override sysfs attribute is set and the driver rebound. Any
> such device will now not have device data from a device ID match table
> and may crash.
>
> Add a flag that allows drivers to opt out of the override mechanism when
> it doesn't make sense. This allows us to deal with these situations in
> the core rather than sprinkle checks throughout all of these drivers to
> check for validity of the device data.
>
> Cc: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx>
> Signed-off-by: Thierry Reding <treding@xxxxxxxxxx>
> ---
> include/linux/device.h | 12 +++++++++---
> include/linux/device/driver.h | 12 ++++++++++++
> 2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 90cdd77458bb..45c23cc5efa8 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -899,14 +899,20 @@ static inline bool device_has_driver_override(struct device *dev)
> *
> * Returns > 0 if a driver override is set and matches the given driver, 0 if a
> * driver override is set but does not match, or < 0 if a driver override is not
> - * set at all.
> + * set at all or the driver opts out of the override mechanism.
What's wrong with just not allowing bind/unbind at all? Why would you
want that, but NOT the driver_override file?
thanks,
greg k-h