device-dax: Prevent registering drivers without probe callback

The bus probe function dax_bus_probe() calls the probe callback without
checking it to be non-NULL. Prevent a NULL pointer exception if a driver
without a probe function is registered by refusing to register this
driver.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Link: https://lore.kernel.org/r/20210205222842.34896-2-uwe@kleine-koenig.org
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
Uwe Kleine-König 2021-02-05 23:28:38 +01:00 committed by Dan Williams
parent 7323fb22f0
commit 5b8e64f1ad
1 changed files with 7 additions and 0 deletions

View File

@ -1392,6 +1392,13 @@ int __dax_driver_register(struct dax_device_driver *dax_drv,
struct device_driver *drv = &dax_drv->drv;
int rc = 0;
/*
* dax_bus_probe() calls dax_drv->probe() unconditionally.
* So better be safe than sorry and ensure it is provided.
*/
if (!dax_drv->probe)
return -EINVAL;
INIT_LIST_HEAD(&dax_drv->ids);
drv->owner = module;
drv->name = mod_name;