diff mbox series

[2/3] dax-device: Fix error path in dax_driver_register

Message ID 20210127230124.109522-2-uwe@kleine-koenig.org (mailing list archive)
State New
Headers show
Series [1/3] device-dax: Prevent registering drivers without probe or remove callback | expand

Commit Message

Uwe Kleine-König Jan. 27, 2021, 11:01 p.m. UTC
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 mbox series

Patch

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);