Skip to content

Commit 664525b

Browse files
committed
device-dax: Auto-bind device after successful new_id
The typical 'new_id' attribute behavior is to immediately attach a device to its driver after a new device-id is added. Implement this behavior for the dax bus. Reported-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Reported-by: Brice Goglin <Brice.Goglin@inria.fr> Cc: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 8fc5c73 commit 664525b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

drivers/dax/bus.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ static int dax_match_id(struct dax_device_driver *dax_drv, struct device *dev)
5757
return match;
5858
}
5959

60+
enum id_action {
61+
ID_REMOVE,
62+
ID_ADD,
63+
};
64+
6065
static 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)
6267
{
6368
struct dax_device_driver *dax_drv = to_dax_drv(drv);
6469
unsigned int region_id, id;
@@ -77,7 +82,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
7782
mutex_lock(&dax_bus_lock);
7883
dax_id = __dax_match_id(dax_drv, buf);
7984
if (!dax_id) {
80-
if (add) {
85+
if (action == ID_ADD) {
8186
dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
8287
if (dax_id) {
8388
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,
8691
rc = -ENOMEM;
8792
} else
8893
/* nothing to remove */;
89-
} else if (!add) {
94+
} else if (action == ID_REMOVE) {
9095
list_del(&dax_id->list);
9196
kfree(dax_id);
9297
} else
9398
/* dax_id already added */;
9499
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;
96108
}
97109

98110
static ssize_t new_id_store(struct device_driver *drv, const char *buf,
99111
size_t count)
100112
{
101-
return do_id_store(drv, buf, count, true);
113+
return do_id_store(drv, buf, count, ID_ADD);
102114
}
103115
static DRIVER_ATTR_WO(new_id);
104116

105117
static ssize_t remove_id_store(struct device_driver *drv, const char *buf,
106118
size_t count)
107119
{
108-
return do_id_store(drv, buf, count, false);
120+
return do_id_store(drv, buf, count, ID_REMOVE);
109121
}
110122
static DRIVER_ATTR_WO(remove_id);
111123

0 commit comments

Comments
 (0)