aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/dax/bus.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index c620ad52d7e5..a410154d75fb 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -57,8 +57,13 @@ static int dax_match_id(struct dax_device_driver *dax_drv, struct device *dev)
57 return match; 57 return match;
58} 58}
59 59
60enum id_action {
61 ID_REMOVE,
62 ID_ADD,
63};
64
60static ssize_t do_id_store(struct device_driver *drv, const char *buf, 65static ssize_t do_id_store(struct device_driver *drv, const char *buf,
61 size_t count, bool add) 66 size_t count, enum id_action action)
62{ 67{
63 struct dax_device_driver *dax_drv = to_dax_drv(drv); 68 struct dax_device_driver *dax_drv = to_dax_drv(drv);
64 unsigned int region_id, id; 69 unsigned int region_id, id;
@@ -77,7 +82,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
77 mutex_lock(&dax_bus_lock); 82 mutex_lock(&dax_bus_lock);
78 dax_id = __dax_match_id(dax_drv, buf); 83 dax_id = __dax_match_id(dax_drv, buf);
79 if (!dax_id) { 84 if (!dax_id) {
80 if (add) { 85 if (action == ID_ADD) {
81 dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL); 86 dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
82 if (dax_id) { 87 if (dax_id) {
83 strncpy(dax_id->dev_name, buf, DAX_NAME_LEN); 88 strncpy(dax_id->dev_name, buf, DAX_NAME_LEN);
@@ -86,26 +91,33 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
86 rc = -ENOMEM; 91 rc = -ENOMEM;
87 } else 92 } else
88 /* nothing to remove */; 93 /* nothing to remove */;
89 } else if (!add) { 94 } else if (action == ID_REMOVE) {
90 list_del(&dax_id->list); 95 list_del(&dax_id->list);
91 kfree(dax_id); 96 kfree(dax_id);
92 } else 97 } else
93 /* dax_id already added */; 98 /* dax_id already added */;
94 mutex_unlock(&dax_bus_lock); 99 mutex_unlock(&dax_bus_lock);
95 return rc; 100
101 if (rc < 0)
102 return rc;
103 if (action == ID_ADD)
104 rc = driver_attach(drv);
105 if (rc)
106 return rc;
107 return count;
96} 108}
97 109
98static ssize_t new_id_store(struct device_driver *drv, const char *buf, 110static ssize_t new_id_store(struct device_driver *drv, const char *buf,
99 size_t count) 111 size_t count)
100{ 112{
101 return do_id_store(drv, buf, count, true); 113 return do_id_store(drv, buf, count, ID_ADD);
102} 114}
103static DRIVER_ATTR_WO(new_id); 115static DRIVER_ATTR_WO(new_id);
104 116
105static ssize_t remove_id_store(struct device_driver *drv, const char *buf, 117static ssize_t remove_id_store(struct device_driver *drv, const char *buf,
106 size_t count) 118 size_t count)
107{ 119{
108 return do_id_store(drv, buf, count, false); 120 return do_id_store(drv, buf, count, ID_REMOVE);
109} 121}
110static DRIVER_ATTR_WO(remove_id); 122static DRIVER_ATTR_WO(remove_id);
111 123