Skip to content

Commit 443d112

Browse files
committed
Merge tag 'driver-core-5.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core fixes from Greg KH: "Here are some small driver core fixes for 5.11-rc5 that resolve some reported problems: - revert of a -rc1 patch that was causing problems with some machines - device link device name collision problem fix (busses only have to name devices unique to their bus, not unique to all busses) - kernfs splice bugfixes to resolve firmware loading problems for Qualcomm systems. - other tiny driver core fixes for minor issues reported. All of these have been in linux-next with no reported problems" * tag 'driver-core-5.11-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: driver core: Fix device link device name collision driver core: Extend device_is_dependent() kernfs: wire up ->splice_read and ->splice_write kernfs: implement ->write_iter kernfs: implement ->read_iter Revert "driver core: Reorder devices on successful probe" Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity() drivers core: Free dma_range_map when driver probe failed
2 parents 832bcee + e020ff6 commit 443d112

File tree

7 files changed

+77
-67
lines changed

7 files changed

+77
-67
lines changed

Documentation/ABI/testing/sysfs-class-devlink

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Description:
55
Provide a place in sysfs for the device link objects in the
66
kernel at any given time. The name of a device link directory,
77
denoted as ... above, is of the form <supplier>--<consumer>
8-
where <supplier> is the supplier device name and <consumer> is
9-
the consumer device name.
8+
where <supplier> is the supplier bus:device name and <consumer>
9+
is the consumer bus:device name.
1010

1111
What: /sys/class/devlink/.../auto_remove_on
1212
Date: May 2020

Documentation/ABI/testing/sysfs-devices-consumer

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Contact: Saravana Kannan <[email protected]>
44
Description:
55
The /sys/devices/.../consumer:<consumer> are symlinks to device
66
links where this device is the supplier. <consumer> denotes the
7-
name of the consumer in that device link. There can be zero or
8-
more of these symlinks for a given device.
7+
name of the consumer in that device link and is of the form
8+
bus:device name. There can be zero or more of these symlinks
9+
for a given device.

Documentation/ABI/testing/sysfs-devices-supplier

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Contact: Saravana Kannan <[email protected]>
44
Description:
55
The /sys/devices/.../supplier:<supplier> are symlinks to device
66
links where this device is the consumer. <supplier> denotes the
7-
name of the supplier in that device link. There can be zero or
8-
more of these symlinks for a given device.
7+
name of the supplier in that device link and is of the form
8+
bus:device name. There can be zero or more of these symlinks
9+
for a given device.

drivers/base/core.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ int device_links_read_lock_held(void)
208208
#endif
209209
#endif /* !CONFIG_SRCU */
210210

211+
static bool device_is_ancestor(struct device *dev, struct device *target)
212+
{
213+
while (target->parent) {
214+
target = target->parent;
215+
if (dev == target)
216+
return true;
217+
}
218+
return false;
219+
}
220+
211221
/**
212222
* device_is_dependent - Check if one device depends on another one
213223
* @dev: Device to check dependencies for.
@@ -221,7 +231,12 @@ int device_is_dependent(struct device *dev, void *target)
221231
struct device_link *link;
222232
int ret;
223233

224-
if (dev == target)
234+
/*
235+
* The "ancestors" check is needed to catch the case when the target
236+
* device has not been completely initialized yet and it is still
237+
* missing from the list of children of its parent device.
238+
*/
239+
if (dev == target || device_is_ancestor(dev, target))
225240
return 1;
226241

227242
ret = device_for_each_child(dev, target, device_is_dependent);
@@ -456,7 +471,9 @@ static int devlink_add_symlinks(struct device *dev,
456471
struct device *con = link->consumer;
457472
char *buf;
458473

459-
len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
474+
len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
475+
strlen(dev_bus_name(con)) + strlen(dev_name(con)));
476+
len += strlen(":");
460477
len += strlen("supplier:") + 1;
461478
buf = kzalloc(len, GFP_KERNEL);
462479
if (!buf)
@@ -470,20 +487,20 @@ static int devlink_add_symlinks(struct device *dev,
470487
if (ret)
471488
goto err_con;
472489

473-
snprintf(buf, len, "consumer:%s", dev_name(con));
490+
snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
474491
ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
475492
if (ret)
476493
goto err_con_dev;
477494

478-
snprintf(buf, len, "supplier:%s", dev_name(sup));
495+
snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
479496
ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
480497
if (ret)
481498
goto err_sup_dev;
482499

483500
goto out;
484501

485502
err_sup_dev:
486-
snprintf(buf, len, "consumer:%s", dev_name(con));
503+
snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
487504
sysfs_remove_link(&sup->kobj, buf);
488505
err_con_dev:
489506
sysfs_remove_link(&link->link_dev.kobj, "consumer");
@@ -506,17 +523,19 @@ static void devlink_remove_symlinks(struct device *dev,
506523
sysfs_remove_link(&link->link_dev.kobj, "consumer");
507524
sysfs_remove_link(&link->link_dev.kobj, "supplier");
508525

509-
len = max(strlen(dev_name(sup)), strlen(dev_name(con)));
526+
len = max(strlen(dev_bus_name(sup)) + strlen(dev_name(sup)),
527+
strlen(dev_bus_name(con)) + strlen(dev_name(con)));
528+
len += strlen(":");
510529
len += strlen("supplier:") + 1;
511530
buf = kzalloc(len, GFP_KERNEL);
512531
if (!buf) {
513532
WARN(1, "Unable to properly free device link symlinks!\n");
514533
return;
515534
}
516535

517-
snprintf(buf, len, "supplier:%s", dev_name(sup));
536+
snprintf(buf, len, "supplier:%s:%s", dev_bus_name(sup), dev_name(sup));
518537
sysfs_remove_link(&con->kobj, buf);
519-
snprintf(buf, len, "consumer:%s", dev_name(con));
538+
snprintf(buf, len, "consumer:%s:%s", dev_bus_name(con), dev_name(con));
520539
sysfs_remove_link(&sup->kobj, buf);
521540
kfree(buf);
522541
}
@@ -737,8 +756,9 @@ struct device_link *device_link_add(struct device *consumer,
737756

738757
link->link_dev.class = &devlink_class;
739758
device_set_pm_not_required(&link->link_dev);
740-
dev_set_name(&link->link_dev, "%s--%s",
741-
dev_name(supplier), dev_name(consumer));
759+
dev_set_name(&link->link_dev, "%s:%s--%s:%s",
760+
dev_bus_name(supplier), dev_name(supplier),
761+
dev_bus_name(consumer), dev_name(consumer));
742762
if (device_register(&link->link_dev)) {
743763
put_device(consumer);
744764
put_device(supplier);
@@ -1808,9 +1828,7 @@ const char *dev_driver_string(const struct device *dev)
18081828
* never change once they are set, so they don't need special care.
18091829
*/
18101830
drv = READ_ONCE(dev->driver);
1811-
return drv ? drv->name :
1812-
(dev->bus ? dev->bus->name :
1813-
(dev->class ? dev->class->name : ""));
1831+
return drv ? drv->name : dev_bus_name(dev);
18141832
}
18151833
EXPORT_SYMBOL(dev_driver_string);
18161834

drivers/base/dd.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,6 @@ static void driver_bound(struct device *dev)
370370

371371
device_pm_check_callbacks(dev);
372372

373-
/*
374-
* Reorder successfully probed devices to the end of the device list.
375-
* This ensures that suspend/resume order matches probe order, which
376-
* is usually what drivers rely on.
377-
*/
378-
device_pm_move_to_tail(dev);
379-
380373
/*
381374
* Make sure the device is no longer in one of the deferred lists and
382375
* kick off retrying all pending devices
@@ -619,6 +612,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
619612
else if (drv->remove)
620613
drv->remove(dev);
621614
probe_failed:
615+
kfree(dev->dma_range_map);
616+
dev->dma_range_map = NULL;
622617
if (dev->bus)
623618
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
624619
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);

fs/kernfs/file.c

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/pagemap.h>
1515
#include <linux/sched/mm.h>
1616
#include <linux/fsnotify.h>
17+
#include <linux/uio.h>
1718

1819
#include "kernfs-internal.h"
1920

@@ -180,11 +181,10 @@ static const struct seq_operations kernfs_seq_ops = {
180181
* it difficult to use seq_file. Implement simplistic custom buffering for
181182
* bin files.
182183
*/
183-
static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
184-
char __user *user_buf, size_t count,
185-
loff_t *ppos)
184+
static ssize_t kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
186185
{
187-
ssize_t len = min_t(size_t, count, PAGE_SIZE);
186+
struct kernfs_open_file *of = kernfs_of(iocb->ki_filp);
187+
ssize_t len = min_t(size_t, iov_iter_count(iter), PAGE_SIZE);
188188
const struct kernfs_ops *ops;
189189
char *buf;
190190

@@ -210,7 +210,7 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
210210
of->event = atomic_read(&of->kn->attr.open->event);
211211
ops = kernfs_ops(of->kn);
212212
if (ops->read)
213-
len = ops->read(of, buf, len, *ppos);
213+
len = ops->read(of, buf, len, iocb->ki_pos);
214214
else
215215
len = -EINVAL;
216216

@@ -220,12 +220,12 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
220220
if (len < 0)
221221
goto out_free;
222222

223-
if (copy_to_user(user_buf, buf, len)) {
223+
if (copy_to_iter(buf, len, iter) != len) {
224224
len = -EFAULT;
225225
goto out_free;
226226
}
227227

228-
*ppos += len;
228+
iocb->ki_pos += len;
229229

230230
out_free:
231231
if (buf == of->prealloc_buf)
@@ -235,31 +235,14 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
235235
return len;
236236
}
237237

238-
/**
239-
* kernfs_fop_read - kernfs vfs read callback
240-
* @file: file pointer
241-
* @user_buf: data to write
242-
* @count: number of bytes
243-
* @ppos: starting offset
244-
*/
245-
static ssize_t kernfs_fop_read(struct file *file, char __user *user_buf,
246-
size_t count, loff_t *ppos)
238+
static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
247239
{
248-
struct kernfs_open_file *of = kernfs_of(file);
249-
250-
if (of->kn->flags & KERNFS_HAS_SEQ_SHOW)
251-
return seq_read(file, user_buf, count, ppos);
252-
else
253-
return kernfs_file_direct_read(of, user_buf, count, ppos);
240+
if (kernfs_of(iocb->ki_filp)->kn->flags & KERNFS_HAS_SEQ_SHOW)
241+
return seq_read_iter(iocb, iter);
242+
return kernfs_file_read_iter(iocb, iter);
254243
}
255244

256-
/**
257-
* kernfs_fop_write - kernfs vfs write callback
258-
* @file: file pointer
259-
* @user_buf: data to write
260-
* @count: number of bytes
261-
* @ppos: starting offset
262-
*
245+
/*
263246
* Copy data in from userland and pass it to the matching kernfs write
264247
* operation.
265248
*
@@ -269,20 +252,18 @@ static ssize_t kernfs_fop_read(struct file *file, char __user *user_buf,
269252
* modify only the the value you're changing, then write entire buffer
270253
* back.
271254
*/
272-
static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
273-
size_t count, loff_t *ppos)
255+
static ssize_t kernfs_fop_write_iter(struct kiocb *iocb, struct iov_iter *iter)
274256
{
275-
struct kernfs_open_file *of = kernfs_of(file);
257+
struct kernfs_open_file *of = kernfs_of(iocb->ki_filp);
258+
ssize_t len = iov_iter_count(iter);
276259
const struct kernfs_ops *ops;
277-
ssize_t len;
278260
char *buf;
279261

280262
if (of->atomic_write_len) {
281-
len = count;
282263
if (len > of->atomic_write_len)
283264
return -E2BIG;
284265
} else {
285-
len = min_t(size_t, count, PAGE_SIZE);
266+
len = min_t(size_t, len, PAGE_SIZE);
286267
}
287268

288269
buf = of->prealloc_buf;
@@ -293,7 +274,7 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
293274
if (!buf)
294275
return -ENOMEM;
295276

296-
if (copy_from_user(buf, user_buf, len)) {
277+
if (copy_from_iter(buf, len, iter) != len) {
297278
len = -EFAULT;
298279
goto out_free;
299280
}
@@ -312,15 +293,15 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
312293

313294
ops = kernfs_ops(of->kn);
314295
if (ops->write)
315-
len = ops->write(of, buf, len, *ppos);
296+
len = ops->write(of, buf, len, iocb->ki_pos);
316297
else
317298
len = -EINVAL;
318299

319300
kernfs_put_active(of->kn);
320301
mutex_unlock(&of->mutex);
321302

322303
if (len > 0)
323-
*ppos += len;
304+
iocb->ki_pos += len;
324305

325306
out_free:
326307
if (buf == of->prealloc_buf)
@@ -673,7 +654,7 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
673654

674655
/*
675656
* Write path needs to atomic_write_len outside active reference.
676-
* Cache it in open_file. See kernfs_fop_write() for details.
657+
* Cache it in open_file. See kernfs_fop_write_iter() for details.
677658
*/
678659
of->atomic_write_len = ops->atomic_write_len;
679660

@@ -960,14 +941,16 @@ void kernfs_notify(struct kernfs_node *kn)
960941
EXPORT_SYMBOL_GPL(kernfs_notify);
961942

962943
const struct file_operations kernfs_file_fops = {
963-
.read = kernfs_fop_read,
964-
.write = kernfs_fop_write,
944+
.read_iter = kernfs_fop_read_iter,
945+
.write_iter = kernfs_fop_write_iter,
965946
.llseek = generic_file_llseek,
966947
.mmap = kernfs_fop_mmap,
967948
.open = kernfs_fop_open,
968949
.release = kernfs_fop_release,
969950
.poll = kernfs_fop_poll,
970951
.fsync = noop_fsync,
952+
.splice_read = generic_file_splice_read,
953+
.splice_write = iter_file_splice_write,
971954
};
972955

973956
/**

include/linux/device.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,18 @@ static inline const char *dev_name(const struct device *dev)
609609
return kobject_name(&dev->kobj);
610610
}
611611

612+
/**
613+
* dev_bus_name - Return a device's bus/class name, if at all possible
614+
* @dev: struct device to get the bus/class name of
615+
*
616+
* Will return the name of the bus/class the device is attached to. If it is
617+
* not attached to a bus/class, an empty string will be returned.
618+
*/
619+
static inline const char *dev_bus_name(const struct device *dev)
620+
{
621+
return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : "");
622+
}
623+
612624
__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
613625

614626
#ifdef CONFIG_NUMA

0 commit comments

Comments
 (0)