* [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback @ 2021-01-27 23:01 ` Uwe Kleine-König 0 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The bus probe and remove functions (dax_bus_probe and dax_bus_remove respectively) call these functions without checking them to be non-NULL. Add a check to prevent a NULL pointer exception. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 737b207c9e30..618d462975ba 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1392,6 +1392,14 @@ 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 and + * dax_bus_remove() calls dax_drv->remove() unconditionally. So better + * be safe than sorry and ensure these are provided. + */ + if (!dax_drv->probe || !dax_drv->remove) + return -EINVAL; + INIT_LIST_HEAD(&dax_drv->ids); drv->owner = module; drv->name = mod_name; base-commit: 5c8fe583cce542aa0b84adc939ce85293de36e5e -- 2.29.2 _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback @ 2021-01-27 23:01 ` Uwe Kleine-König 0 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The bus probe and remove functions (dax_bus_probe and dax_bus_remove respectively) call these functions without checking them to be non-NULL. Add a check to prevent a NULL pointer exception. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 737b207c9e30..618d462975ba 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1392,6 +1392,14 @@ 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 and + * dax_bus_remove() calls dax_drv->remove() unconditionally. So better + * be safe than sorry and ensure these are provided. + */ + if (!dax_drv->probe || !dax_drv->remove) + return -EINVAL; + INIT_LIST_HEAD(&dax_drv->ids); drv->owner = module; drv->name = mod_name; base-commit: 5c8fe583cce542aa0b84adc939ce85293de36e5e -- 2.29.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] dax-device: Fix error path in dax_driver_register 2021-01-27 23:01 ` Uwe Kleine-König @ 2021-01-27 23:01 ` Uwe Kleine-König -1 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The static variable match_always_count is supposed to track if there is a driver registered that has .match_always set. If driver_register() fails, the previous increment must be undone. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 618d462975ba..498c60333d60 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1417,7 +1417,15 @@ int __dax_driver_register(struct dax_device_driver *dax_drv, mutex_unlock(&dax_bus_lock); if (rc) return rc; - return driver_register(drv); + + rc = driver_register(drv); + if (rc && dax_drv->match_always) { + mutex_lock(&dax_bus_lock); + match_always_count -= dax_drv->match_always; + mutex_unlock(&dax_bus_lock); + } + + return rc; } EXPORT_SYMBOL_GPL(__dax_driver_register); -- 2.29.2 _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] dax-device: Fix error path in dax_driver_register @ 2021-01-27 23:01 ` Uwe Kleine-König 0 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The static variable match_always_count is supposed to track if there is a driver registered that has .match_always set. If driver_register() fails, the previous increment must be undone. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 618d462975ba..498c60333d60 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1417,7 +1417,15 @@ int __dax_driver_register(struct dax_device_driver *dax_drv, mutex_unlock(&dax_bus_lock); if (rc) return rc; - return driver_register(drv); + + rc = driver_register(drv); + if (rc && dax_drv->match_always) { + mutex_lock(&dax_bus_lock); + match_always_count -= dax_drv->match_always; + mutex_unlock(&dax_bus_lock); + } + + return rc; } EXPORT_SYMBOL_GPL(__dax_driver_register); -- 2.29.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] dax-device: Make remove callback return void 2021-01-27 23:01 ` Uwe Kleine-König @ 2021-01-27 23:01 ` Uwe Kleine-König -1 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The driver core ignores the return value of struct bus_type::remove() because there is only little that can be done. To simplify the quest to make this function return void, let struct dax_device_driver::remove() return void, too. All users already unconditionally return 0, this commit makes it obvious that returning an error code is a bad idea and makes it obvious for future driver authors that returning an error code isn't intended. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 4 +++- drivers/dax/bus.h | 2 +- drivers/dax/device.c | 3 +-- drivers/dax/kmem.c | 7 ++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 498c60333d60..253f37a61371 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -179,7 +179,9 @@ static int dax_bus_remove(struct device *dev) struct dax_device_driver *dax_drv = to_dax_drv(dev->driver); struct dev_dax *dev_dax = to_dev_dax(dev); - return dax_drv->remove(dev_dax); + dax_drv->remove(dev_dax); + + return 0; } static struct bus_type dax_bus_type = { diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 72b92f95509f..1e946ad7780a 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -39,7 +39,7 @@ struct dax_device_driver { struct list_head ids; int match_always; int (*probe)(struct dev_dax *dev); - int (*remove)(struct dev_dax *dev); + void (*remove)(struct dev_dax *dev); }; int __dax_driver_register(struct dax_device_driver *dax_drv, diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 5da2980bb16b..d532c885f574 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -452,10 +452,9 @@ int dev_dax_probe(struct dev_dax *dev_dax) } EXPORT_SYMBOL_GPL(dev_dax_probe); -static int dev_dax_remove(struct dev_dax *dev_dax) +static void dev_dax_remove(struct dev_dax *dev_dax) { /* all probe actions are unwound by devm */ - return 0; } static struct dax_device_driver device_dax_driver = { diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 403ec42472d1..ac231cc36359 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -136,7 +136,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) } #ifdef CONFIG_MEMORY_HOTREMOVE -static int dev_dax_kmem_remove(struct dev_dax *dev_dax) +static void dev_dax_kmem_remove(struct dev_dax *dev_dax) { int i, success = 0; struct device *dev = &dev_dax->dev; @@ -176,11 +176,9 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) kfree(data); dev_set_drvdata(dev, NULL); } - - return 0; } #else -static int dev_dax_kmem_remove(struct dev_dax *dev_dax) +static void dev_dax_kmem_remove(struct dev_dax *dev_dax) { /* * Without hotremove purposely leak the request_mem_region() for the @@ -190,7 +188,6 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) * request_mem_region(). */ any_hotremove_failed = true; - return 0; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -- 2.29.2 _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] dax-device: Make remove callback return void @ 2021-01-27 23:01 ` Uwe Kleine-König 0 siblings, 0 replies; 6+ messages in thread From: Uwe Kleine-König @ 2021-01-27 23:01 UTC (permalink / raw) To: Dan Williams, Vishal Verma, Dave Jiang Cc: linux-nvdimm, linux-kernel, Greg Kroah-Hartman The driver core ignores the return value of struct bus_type::remove() because there is only little that can be done. To simplify the quest to make this function return void, let struct dax_device_driver::remove() return void, too. All users already unconditionally return 0, this commit makes it obvious that returning an error code is a bad idea and makes it obvious for future driver authors that returning an error code isn't intended. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/dax/bus.c | 4 +++- drivers/dax/bus.h | 2 +- drivers/dax/device.c | 3 +-- drivers/dax/kmem.c | 7 ++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 498c60333d60..253f37a61371 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -179,7 +179,9 @@ static int dax_bus_remove(struct device *dev) struct dax_device_driver *dax_drv = to_dax_drv(dev->driver); struct dev_dax *dev_dax = to_dev_dax(dev); - return dax_drv->remove(dev_dax); + dax_drv->remove(dev_dax); + + return 0; } static struct bus_type dax_bus_type = { diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 72b92f95509f..1e946ad7780a 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -39,7 +39,7 @@ struct dax_device_driver { struct list_head ids; int match_always; int (*probe)(struct dev_dax *dev); - int (*remove)(struct dev_dax *dev); + void (*remove)(struct dev_dax *dev); }; int __dax_driver_register(struct dax_device_driver *dax_drv, diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 5da2980bb16b..d532c885f574 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -452,10 +452,9 @@ int dev_dax_probe(struct dev_dax *dev_dax) } EXPORT_SYMBOL_GPL(dev_dax_probe); -static int dev_dax_remove(struct dev_dax *dev_dax) +static void dev_dax_remove(struct dev_dax *dev_dax) { /* all probe actions are unwound by devm */ - return 0; } static struct dax_device_driver device_dax_driver = { diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 403ec42472d1..ac231cc36359 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -136,7 +136,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) } #ifdef CONFIG_MEMORY_HOTREMOVE -static int dev_dax_kmem_remove(struct dev_dax *dev_dax) +static void dev_dax_kmem_remove(struct dev_dax *dev_dax) { int i, success = 0; struct device *dev = &dev_dax->dev; @@ -176,11 +176,9 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) kfree(data); dev_set_drvdata(dev, NULL); } - - return 0; } #else -static int dev_dax_kmem_remove(struct dev_dax *dev_dax) +static void dev_dax_kmem_remove(struct dev_dax *dev_dax) { /* * Without hotremove purposely leak the request_mem_region() for the @@ -190,7 +188,6 @@ static int dev_dax_kmem_remove(struct dev_dax *dev_dax) * request_mem_region(). */ any_hotremove_failed = true; - return 0; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -- 2.29.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-27 23:08 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-27 23:01 [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback Uwe Kleine-König 2021-01-27 23:01 ` Uwe Kleine-König 2021-01-27 23:01 ` [PATCH 2/3] dax-device: Fix error path in dax_driver_register Uwe Kleine-König 2021-01-27 23:01 ` Uwe Kleine-König 2021-01-27 23:01 ` [PATCH 3/3] dax-device: Make remove callback return void Uwe Kleine-König 2021-01-27 23:01 ` Uwe Kleine-König
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.