Skip to content

Commit b07039b

Browse files
committed
Merge tag 'driver-core-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core updates from Greg KH: "Here is the "big" set of driver core patches for 4.21-rc1. It's not really big, just a number of small changes for some reported issues, some documentation updates to hopefully make it harder for people to abuse the driver model, and some other minor cleanups. All of these have been in linux-next for a while with no reported issues" * tag 'driver-core-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: mm, memory_hotplug: update a comment in unregister_memory() component: convert to DEFINE_SHOW_ATTRIBUTE sysfs: Disable lockdep for driver bind/unbind files driver core: Add missing dev->bus->need_parent_lock checks kobject: return error code if writing /sys/.../uevent fails driver core: Move async_synchronize_full call driver core: platform: Respect return code of platform_device_register_full() kref/kobject: Improve documentation drivers/base/memory.c: Use DEVICE_ATTR_RO and friends driver core: Replace simple_strto{l,ul} by kstrtou{l,ul} kernfs: Improve kernfs_notify() poll notification latency kobject: Fix warnings in lib/kobject_uevent.c kobject: drop unnecessary cast "%llu" for u64 driver core: fix comments for device_block_probing() driver core: Replace simple_strtol by kstrtoint
2 parents 0206118 + 16df145 commit b07039b

12 files changed

Lines changed: 113 additions & 104 deletions

File tree

‎Documentation/kobject.txt‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,14 @@ such a method has a form like::
279279
One important point cannot be overstated: every kobject must have a
280280
release() method, and the kobject must persist (in a consistent state)
281281
until that method is called. If these constraints are not met, the code is
282-
flawed. Note that the kernel will warn you if you forget to provide a
282+
flawed. Note that the kernel will warn you if you forget to provide a
283283
release() method. Do not try to get rid of this warning by providing an
284-
"empty" release function; you will be mocked mercilessly by the kobject
285-
maintainer if you attempt this.
284+
"empty" release function.
285+
286+
If all your cleanup function needs to do is call kfree(), then you must
287+
create a wrapper function which uses container_of() to upcast to the correct
288+
type (as shown in the example above) and then calls kfree() on the overall
289+
structure.
286290

287291
Note, the name of the kobject is available in the release function, but it
288292
must NOT be changed within this callback. Otherwise there will be a memory

‎drivers/base/bus.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ static struct kset *system_kset;
3131

3232
#define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
3333

34+
#define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
35+
struct driver_attribute driver_attr_##_name = \
36+
__ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
3437

3538
static int __must_check bus_rescan_devices_helper(struct device *dev,
3639
void *data);
@@ -195,7 +198,7 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
195198
bus_put(bus);
196199
return err;
197200
}
198-
static DRIVER_ATTR_WO(unbind);
201+
static DRIVER_ATTR_IGNORE_LOCKDEP(unbind, S_IWUSR, NULL, unbind_store);
199202

200203
/*
201204
* Manually attach a device to a driver.
@@ -231,7 +234,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
231234
bus_put(bus);
232235
return err;
233236
}
234-
static DRIVER_ATTR_WO(bind);
237+
static DRIVER_ATTR_IGNORE_LOCKDEP(bind, S_IWUSR, NULL, bind_store);
235238

236239
static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
237240
{
@@ -611,8 +614,10 @@ static void remove_probe_files(struct bus_type *bus)
611614
static ssize_t uevent_store(struct device_driver *drv, const char *buf,
612615
size_t count)
613616
{
614-
kobject_synth_uevent(&drv->p->kobj, buf, count);
615-
return count;
617+
int rc;
618+
619+
rc = kobject_synth_uevent(&drv->p->kobj, buf, count);
620+
return rc ? rc : count;
616621
}
617622
static DRIVER_ATTR_WO(uevent);
618623

@@ -828,8 +833,10 @@ static void klist_devices_put(struct klist_node *n)
828833
static ssize_t bus_uevent_store(struct bus_type *bus,
829834
const char *buf, size_t count)
830835
{
831-
kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
832-
return count;
836+
int rc;
837+
838+
rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count);
839+
return rc ? rc : count;
833840
}
834841
static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
835842

‎drivers/base/component.c‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,7 @@ static int component_devices_show(struct seq_file *s, void *data)
8585
return 0;
8686
}
8787

88-
static int component_devices_open(struct inode *inode, struct file *file)
89-
{
90-
return single_open(file, component_devices_show, inode->i_private);
91-
}
92-
93-
static const struct file_operations component_devices_fops = {
94-
.open = component_devices_open,
95-
.read = seq_read,
96-
.llseek = seq_lseek,
97-
.release = single_release,
98-
};
88+
DEFINE_SHOW_ATTRIBUTE(component_devices);
9989

10090
static int __init component_debug_init(void)
10191
{

‎drivers/base/core.c‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,12 @@ ssize_t device_store_ulong(struct device *dev,
815815
const char *buf, size_t size)
816816
{
817817
struct dev_ext_attribute *ea = to_ext_attr(attr);
818-
char *end;
819-
unsigned long new = simple_strtoul(buf, &end, 0);
820-
if (end == buf)
821-
return -EINVAL;
818+
int ret;
819+
unsigned long new;
820+
821+
ret = kstrtoul(buf, 0, &new);
822+
if (ret)
823+
return ret;
822824
*(unsigned long *)(ea->var) = new;
823825
/* Always return full write size even if we didn't consume all */
824826
return size;
@@ -839,9 +841,14 @@ ssize_t device_store_int(struct device *dev,
839841
const char *buf, size_t size)
840842
{
841843
struct dev_ext_attribute *ea = to_ext_attr(attr);
842-
char *end;
843-
long new = simple_strtol(buf, &end, 0);
844-
if (end == buf || new > INT_MAX || new < INT_MIN)
844+
int ret;
845+
long new;
846+
847+
ret = kstrtol(buf, 0, &new);
848+
if (ret)
849+
return ret;
850+
851+
if (new > INT_MAX || new < INT_MIN)
845852
return -EINVAL;
846853
*(int *)(ea->var) = new;
847854
/* Always return full write size even if we didn't consume all */
@@ -911,8 +918,7 @@ static void device_release(struct kobject *kobj)
911918
else if (dev->class && dev->class->dev_release)
912919
dev->class->dev_release(dev);
913920
else
914-
WARN(1, KERN_ERR "Device '%s' does not have a release() "
915-
"function, it is broken and must be fixed.\n",
921+
WARN(1, KERN_ERR "Device '%s' does not have a release() function, it is broken and must be fixed. See Documentation/kobject.txt.\n",
916922
dev_name(dev));
917923
kfree(p);
918924
}
@@ -1088,8 +1094,14 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
10881094
static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
10891095
const char *buf, size_t count)
10901096
{
1091-
if (kobject_synth_uevent(&dev->kobj, buf, count))
1097+
int rc;
1098+
1099+
rc = kobject_synth_uevent(&dev->kobj, buf, count);
1100+
1101+
if (rc) {
10921102
dev_err(dev, "uevent: failed to send synthetic uevent\n");
1103+
return rc;
1104+
}
10931105

10941106
return count;
10951107
}

‎drivers/base/dd.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void driver_deferred_probe_trigger(void)
179179
}
180180

181181
/**
182-
* device_block_probing() - Block/defere device's probes
182+
* device_block_probing() - Block/defer device's probes
183183
*
184184
* It will disable probing of devices and defer their probes instead.
185185
*/
@@ -223,7 +223,10 @@ DEFINE_SHOW_ATTRIBUTE(deferred_devs);
223223
static int deferred_probe_timeout = -1;
224224
static int __init deferred_probe_timeout_setup(char *str)
225225
{
226-
deferred_probe_timeout = simple_strtol(str, NULL, 10);
226+
int timeout;
227+
228+
if (!kstrtoint(str, 10, &timeout))
229+
deferred_probe_timeout = timeout;
227230
return 1;
228231
}
229232
__setup("deferred_probe_timeout=", deferred_probe_timeout_setup);
@@ -453,7 +456,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
453456
if (defer_all_probes) {
454457
/*
455458
* Value of defer_all_probes can be set only by
456-
* device_defer_all_probes_enable() which, in turn, will call
459+
* device_block_probing() which, in turn, will call
457460
* wait_for_device_probe() right after that to avoid any races.
458461
*/
459462
dev_dbg(dev, "Driver %s force probe deferral\n", drv->name);
@@ -928,16 +931,13 @@ static void __device_release_driver(struct device *dev, struct device *parent)
928931

929932
drv = dev->driver;
930933
if (drv) {
931-
if (driver_allows_async_probing(drv))
932-
async_synchronize_full();
933-
934934
while (device_links_busy(dev)) {
935935
device_unlock(dev);
936-
if (parent)
936+
if (parent && dev->bus->need_parent_lock)
937937
device_unlock(parent);
938938

939939
device_links_unbind_consumers(dev);
940-
if (parent)
940+
if (parent && dev->bus->need_parent_lock)
941941
device_lock(parent);
942942

943943
device_lock(dev);
@@ -1036,6 +1036,9 @@ void driver_detach(struct device_driver *drv)
10361036
struct device_private *dev_prv;
10371037
struct device *dev;
10381038

1039+
if (driver_allows_async_probing(drv))
1040+
async_synchronize_full();
1041+
10391042
for (;;) {
10401043
spin_lock(&drv->p->klist_devices.k_lock);
10411044
if (list_empty(&drv->p->klist_devices.k_list)) {

0 commit comments

Comments
 (0)