Skip to content

Commit 535a54c

Browse files
author
Fox Snowpatch
committed
1 parent 4f37907 commit 535a54c

32 files changed

Lines changed: 88 additions & 488 deletions

File tree

drivers/amba/bus.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,6 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
8282
}
8383

8484

85-
static ssize_t driver_override_show(struct device *_dev,
86-
struct device_attribute *attr, char *buf)
87-
{
88-
struct amba_device *dev = to_amba_device(_dev);
89-
ssize_t len;
90-
91-
device_lock(_dev);
92-
len = sprintf(buf, "%s\n", dev->driver_override);
93-
device_unlock(_dev);
94-
return len;
95-
}
96-
97-
static ssize_t driver_override_store(struct device *_dev,
98-
struct device_attribute *attr,
99-
const char *buf, size_t count)
100-
{
101-
struct amba_device *dev = to_amba_device(_dev);
102-
int ret;
103-
104-
ret = driver_set_override(_dev, &dev->driver_override, buf, count);
105-
if (ret)
106-
return ret;
107-
108-
return count;
109-
}
110-
static DEVICE_ATTR_RW(driver_override);
111-
11285
#define amba_attr_func(name,fmt,arg...) \
11386
static ssize_t name##_show(struct device *_dev, \
11487
struct device_attribute *attr, char *buf) \
@@ -126,7 +99,6 @@ amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n",
12699
static struct attribute *amba_dev_attrs[] = {
127100
&dev_attr_id.attr,
128101
&dev_attr_resource.attr,
129-
&dev_attr_driver_override.attr,
130102
NULL,
131103
};
132104
ATTRIBUTE_GROUPS(amba_dev);
@@ -209,10 +181,11 @@ static int amba_match(struct device *dev, const struct device_driver *drv)
209181
{
210182
struct amba_device *pcdev = to_amba_device(dev);
211183
const struct amba_driver *pcdrv = to_amba_driver(drv);
184+
int ret;
212185

213186
mutex_lock(&pcdev->periphid_lock);
214187
if (!pcdev->periphid) {
215-
int ret = amba_read_periphid(pcdev);
188+
ret = amba_read_periphid(pcdev);
216189

217190
/*
218191
* Returning any error other than -EPROBE_DEFER from bus match
@@ -230,8 +203,9 @@ static int amba_match(struct device *dev, const struct device_driver *drv)
230203
mutex_unlock(&pcdev->periphid_lock);
231204

232205
/* When driver_override is set, only bind to the matching driver */
233-
if (pcdev->driver_override)
234-
return !strcmp(pcdev->driver_override, drv->name);
206+
ret = device_match_driver_override(dev, drv);
207+
if (ret >= 0)
208+
return ret;
235209

236210
return amba_lookup(pcdrv->id_table, pcdev) != NULL;
237211
}
@@ -436,6 +410,7 @@ static const struct dev_pm_ops amba_pm = {
436410
const struct bus_type amba_bustype = {
437411
.name = "amba",
438412
.dev_groups = amba_dev_groups,
413+
.driver_override = true,
439414
.match = amba_match,
440415
.uevent = amba_uevent,
441416
.probe = amba_probe,

drivers/base/driver.c

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,81 +30,6 @@ static struct device *next_device(struct klist_iter *i)
3030
return dev;
3131
}
3232

33-
/**
34-
* driver_set_override() - Helper to set or clear driver override.
35-
* @dev: Device to change
36-
* @override: Address of string to change (e.g. &device->driver_override);
37-
* The contents will be freed and hold newly allocated override.
38-
* @s: NUL-terminated string, new driver name to force a match, pass empty
39-
* string to clear it ("" or "\n", where the latter is only for sysfs
40-
* interface).
41-
* @len: length of @s
42-
*
43-
* Helper to set or clear driver override in a device, intended for the cases
44-
* when the driver_override field is allocated by driver/bus code.
45-
*
46-
* Returns: 0 on success or a negative error code on failure.
47-
*/
48-
int driver_set_override(struct device *dev, const char **override,
49-
const char *s, size_t len)
50-
{
51-
const char *new, *old;
52-
char *cp;
53-
54-
if (!override || !s)
55-
return -EINVAL;
56-
57-
/*
58-
* The stored value will be used in sysfs show callback (sysfs_emit()),
59-
* which has a length limit of PAGE_SIZE and adds a trailing newline.
60-
* Thus we can store one character less to avoid truncation during sysfs
61-
* show.
62-
*/
63-
if (len >= (PAGE_SIZE - 1))
64-
return -EINVAL;
65-
66-
/*
67-
* Compute the real length of the string in case userspace sends us a
68-
* bunch of \0 characters like python likes to do.
69-
*/
70-
len = strlen(s);
71-
72-
if (!len) {
73-
/* Empty string passed - clear override */
74-
device_lock(dev);
75-
old = *override;
76-
*override = NULL;
77-
device_unlock(dev);
78-
kfree(old);
79-
80-
return 0;
81-
}
82-
83-
cp = strnchr(s, len, '\n');
84-
if (cp)
85-
len = cp - s;
86-
87-
new = kstrndup(s, len, GFP_KERNEL);
88-
if (!new)
89-
return -ENOMEM;
90-
91-
device_lock(dev);
92-
old = *override;
93-
if (cp != s) {
94-
*override = new;
95-
} else {
96-
/* "\n" passed - clear override */
97-
kfree(new);
98-
*override = NULL;
99-
}
100-
device_unlock(dev);
101-
102-
kfree(old);
103-
104-
return 0;
105-
}
106-
EXPORT_SYMBOL_GPL(driver_set_override);
107-
10833
/**
10934
* driver_for_each_device - Iterator for devices bound to a driver.
11035
* @drv: Driver we're iterating.

drivers/bus/fsl-mc/fsl-mc-bus.c

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ static int fsl_mc_bus_match(struct device *dev, const struct device_driver *drv)
8686
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
8787
const struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
8888
bool found = false;
89+
int ret;
8990

9091
/* When driver_override is set, only bind to the matching driver */
91-
if (mc_dev->driver_override) {
92-
found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
92+
ret = device_match_driver_override(dev, drv);
93+
if (ret > 0) {
94+
found = true;
9395
goto out;
9496
}
97+
if (ret == 0)
98+
goto out;
9599

96100
if (!mc_drv->match_id_table)
97101
goto out;
@@ -210,39 +214,8 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
210214
}
211215
static DEVICE_ATTR_RO(modalias);
212216

213-
static ssize_t driver_override_store(struct device *dev,
214-
struct device_attribute *attr,
215-
const char *buf, size_t count)
216-
{
217-
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
218-
int ret;
219-
220-
if (WARN_ON(dev->bus != &fsl_mc_bus_type))
221-
return -EINVAL;
222-
223-
ret = driver_set_override(dev, &mc_dev->driver_override, buf, count);
224-
if (ret)
225-
return ret;
226-
227-
return count;
228-
}
229-
230-
static ssize_t driver_override_show(struct device *dev,
231-
struct device_attribute *attr, char *buf)
232-
{
233-
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
234-
ssize_t len;
235-
236-
device_lock(dev);
237-
len = sysfs_emit(buf, "%s\n", mc_dev->driver_override);
238-
device_unlock(dev);
239-
return len;
240-
}
241-
static DEVICE_ATTR_RW(driver_override);
242-
243217
static struct attribute *fsl_mc_dev_attrs[] = {
244218
&dev_attr_modalias.attr,
245-
&dev_attr_driver_override.attr,
246219
NULL,
247220
};
248221

@@ -345,6 +318,7 @@ ATTRIBUTE_GROUPS(fsl_mc_bus);
345318

346319
const struct bus_type fsl_mc_bus_type = {
347320
.name = "fsl-mc",
321+
.driver_override = true,
348322
.match = fsl_mc_bus_match,
349323
.uevent = fsl_mc_bus_uevent,
350324
.probe = fsl_mc_probe,
@@ -910,9 +884,6 @@ static struct notifier_block fsl_mc_nb;
910884
*/
911885
void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
912886
{
913-
kfree(mc_dev->driver_override);
914-
mc_dev->driver_override = NULL;
915-
916887
/*
917888
* The device-specific remove callback will get invoked by device_del()
918889
*/

drivers/cdx/cdx.c

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ static int cdx_unregister_device(struct device *dev,
156156
} else {
157157
cdx_destroy_res_attr(cdx_dev, MAX_CDX_DEV_RESOURCES);
158158
debugfs_remove_recursive(cdx_dev->debugfs_dir);
159-
kfree(cdx_dev->driver_override);
160-
cdx_dev->driver_override = NULL;
161159
}
162160

163161
/*
@@ -268,14 +266,16 @@ static int cdx_bus_match(struct device *dev, const struct device_driver *drv)
268266
const struct cdx_driver *cdx_drv = to_cdx_driver(drv);
269267
const struct cdx_device_id *found_id = NULL;
270268
const struct cdx_device_id *ids;
269+
int ret;
271270

272271
if (cdx_dev->is_bus)
273272
return false;
274273

275274
ids = cdx_drv->match_id_table;
276275

277276
/* When driver_override is set, only bind to the matching driver */
278-
if (cdx_dev->driver_override && strcmp(cdx_dev->driver_override, drv->name))
277+
ret = device_match_driver_override(dev, drv);
278+
if (ret == 0)
279279
return false;
280280

281281
found_id = cdx_match_id(ids, cdx_dev);
@@ -289,7 +289,7 @@ static int cdx_bus_match(struct device *dev, const struct device_driver *drv)
289289
*/
290290
if (!found_id->override_only)
291291
return true;
292-
if (cdx_dev->driver_override)
292+
if (ret > 0)
293293
return true;
294294

295295
ids = found_id + 1;
@@ -453,36 +453,6 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
453453
}
454454
static DEVICE_ATTR_RO(modalias);
455455

456-
static ssize_t driver_override_store(struct device *dev,
457-
struct device_attribute *attr,
458-
const char *buf, size_t count)
459-
{
460-
struct cdx_device *cdx_dev = to_cdx_device(dev);
461-
int ret;
462-
463-
if (WARN_ON(dev->bus != &cdx_bus_type))
464-
return -EINVAL;
465-
466-
ret = driver_set_override(dev, &cdx_dev->driver_override, buf, count);
467-
if (ret)
468-
return ret;
469-
470-
return count;
471-
}
472-
473-
static ssize_t driver_override_show(struct device *dev,
474-
struct device_attribute *attr, char *buf)
475-
{
476-
struct cdx_device *cdx_dev = to_cdx_device(dev);
477-
ssize_t len;
478-
479-
device_lock(dev);
480-
len = sysfs_emit(buf, "%s\n", cdx_dev->driver_override);
481-
device_unlock(dev);
482-
return len;
483-
}
484-
static DEVICE_ATTR_RW(driver_override);
485-
486456
static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
487457
const char *buf, size_t count)
488458
{
@@ -552,7 +522,6 @@ static struct attribute *cdx_dev_attrs[] = {
552522
&dev_attr_class.attr,
553523
&dev_attr_revision.attr,
554524
&dev_attr_modalias.attr,
555-
&dev_attr_driver_override.attr,
556525
NULL,
557526
};
558527

@@ -646,6 +615,7 @@ ATTRIBUTE_GROUPS(cdx_bus);
646615

647616
const struct bus_type cdx_bus_type = {
648617
.name = "cdx",
618+
.driver_override = true,
649619
.match = cdx_bus_match,
650620
.probe = cdx_probe,
651621
.remove = cdx_remove,

drivers/hv/vmbus_drv.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -541,34 +541,6 @@ static ssize_t device_show(struct device *dev,
541541
}
542542
static DEVICE_ATTR_RO(device);
543543

544-
static ssize_t driver_override_store(struct device *dev,
545-
struct device_attribute *attr,
546-
const char *buf, size_t count)
547-
{
548-
struct hv_device *hv_dev = device_to_hv_device(dev);
549-
int ret;
550-
551-
ret = driver_set_override(dev, &hv_dev->driver_override, buf, count);
552-
if (ret)
553-
return ret;
554-
555-
return count;
556-
}
557-
558-
static ssize_t driver_override_show(struct device *dev,
559-
struct device_attribute *attr, char *buf)
560-
{
561-
struct hv_device *hv_dev = device_to_hv_device(dev);
562-
ssize_t len;
563-
564-
device_lock(dev);
565-
len = sysfs_emit(buf, "%s\n", hv_dev->driver_override);
566-
device_unlock(dev);
567-
568-
return len;
569-
}
570-
static DEVICE_ATTR_RW(driver_override);
571-
572544
/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
573545
static struct attribute *vmbus_dev_attrs[] = {
574546
&dev_attr_id.attr,
@@ -599,7 +571,6 @@ static struct attribute *vmbus_dev_attrs[] = {
599571
&dev_attr_channel_vp_mapping.attr,
600572
&dev_attr_vendor.attr,
601573
&dev_attr_device.attr,
602-
&dev_attr_driver_override.attr,
603574
NULL,
604575
};
605576

@@ -711,9 +682,11 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_id(const struct hv_driver *
711682
{
712683
const guid_t *guid = &dev->dev_type;
713684
const struct hv_vmbus_device_id *id;
685+
int ret;
714686

715687
/* When driver_override is set, only bind to the matching driver */
716-
if (dev->driver_override && strcmp(dev->driver_override, drv->name))
688+
ret = device_match_driver_override(&dev->device, &drv->driver);
689+
if (ret == 0)
717690
return NULL;
718691

719692
/* Look at the dynamic ids first, before the static ones */
@@ -722,7 +695,7 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_id(const struct hv_driver *
722695
id = hv_vmbus_dev_match(drv->id_table, guid);
723696

724697
/* driver_override will always match, send a dummy id */
725-
if (!id && dev->driver_override)
698+
if (!id && ret > 0)
726699
id = &vmbus_device_null;
727700

728701
return id;
@@ -1024,6 +997,7 @@ static const struct dev_pm_ops vmbus_pm = {
1024997
/* The one and only one */
1025998
static const struct bus_type hv_bus = {
1026999
.name = "vmbus",
1000+
.driver_override = true,
10271001
.match = vmbus_match,
10281002
.shutdown = vmbus_shutdown,
10291003
.remove = vmbus_remove,

0 commit comments

Comments
 (0)