Skip to content

Commit 84928ce

Browse files
committed
Merge tag 'driver-core-5.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core fixes from Greg KH: "Here are some driver core and kernfs fixes for reported issues for 5.15-rc4. These fixes include: - kernfs positive dentry bugfix - debugfs_create_file_size error path fix - cpumask sysfs file bugfix to preserve the user/kernel abi (has been reported multiple times.) - devlink fixes for mdiobus devices as reported by the subsystem maintainers. Also included in here are some devlink debugging changes to make it easier for people to report problems when asked. They have already helped with the mdiobus and other subsystems reporting issues. All of these have been linux-next for a while with no reported issues" * tag 'driver-core-5.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: kernfs: also call kernfs_set_rev() for positive dentry driver core: Add debug logs when fwnode links are added/deleted driver core: Create __fwnode_link_del() helper function driver core: Set deferred probe reason when deferred by driver core net: mdiobus: Set FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD for mdiobus parents driver core: fw_devlink: Add support for FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD driver core: fw_devlink: Improve handling of cyclic dependencies cpumask: Omit terminating null byte in cpumap_print_{list,bitmask}_to_buf debugfs: debugfs_create_file_size(): use IS_ERR to check for error
2 parents 777feab + df38d85 commit 84928ce

File tree

6 files changed

+87
-36
lines changed

6 files changed

+87
-36
lines changed

drivers/base/core.c

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,29 @@ int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup)
9595

9696
list_add(&link->s_hook, &sup->consumers);
9797
list_add(&link->c_hook, &con->suppliers);
98+
pr_debug("%pfwP Linked as a fwnode consumer to %pfwP\n",
99+
con, sup);
98100
out:
99101
mutex_unlock(&fwnode_link_lock);
100102

101103
return ret;
102104
}
103105

106+
/**
107+
* __fwnode_link_del - Delete a link between two fwnode_handles.
108+
* @link: the fwnode_link to be deleted
109+
*
110+
* The fwnode_link_lock needs to be held when this function is called.
111+
*/
112+
static void __fwnode_link_del(struct fwnode_link *link)
113+
{
114+
pr_debug("%pfwP Dropping the fwnode link to %pfwP\n",
115+
link->consumer, link->supplier);
116+
list_del(&link->s_hook);
117+
list_del(&link->c_hook);
118+
kfree(link);
119+
}
120+
104121
/**
105122
* fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle.
106123
* @fwnode: fwnode whose supplier links need to be deleted
@@ -112,11 +129,8 @@ static void fwnode_links_purge_suppliers(struct fwnode_handle *fwnode)
112129
struct fwnode_link *link, *tmp;
113130

114131
mutex_lock(&fwnode_link_lock);
115-
list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) {
116-
list_del(&link->s_hook);
117-
list_del(&link->c_hook);
118-
kfree(link);
119-
}
132+
list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook)
133+
__fwnode_link_del(link);
120134
mutex_unlock(&fwnode_link_lock);
121135
}
122136

@@ -131,11 +145,8 @@ static void fwnode_links_purge_consumers(struct fwnode_handle *fwnode)
131145
struct fwnode_link *link, *tmp;
132146

133147
mutex_lock(&fwnode_link_lock);
134-
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) {
135-
list_del(&link->s_hook);
136-
list_del(&link->c_hook);
137-
kfree(link);
138-
}
148+
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook)
149+
__fwnode_link_del(link);
139150
mutex_unlock(&fwnode_link_lock);
140151
}
141152

@@ -975,6 +986,7 @@ int device_links_check_suppliers(struct device *dev)
975986
{
976987
struct device_link *link;
977988
int ret = 0;
989+
struct fwnode_handle *sup_fw;
978990

979991
/*
980992
* Device waiting for supplier to become available is not allowed to
@@ -983,10 +995,11 @@ int device_links_check_suppliers(struct device *dev)
983995
mutex_lock(&fwnode_link_lock);
984996
if (dev->fwnode && !list_empty(&dev->fwnode->suppliers) &&
985997
!fw_devlink_is_permissive()) {
986-
dev_dbg(dev, "probe deferral - wait for supplier %pfwP\n",
987-
list_first_entry(&dev->fwnode->suppliers,
988-
struct fwnode_link,
989-
c_hook)->supplier);
998+
sup_fw = list_first_entry(&dev->fwnode->suppliers,
999+
struct fwnode_link,
1000+
c_hook)->supplier;
1001+
dev_err_probe(dev, -EPROBE_DEFER, "wait for supplier %pfwP\n",
1002+
sup_fw);
9901003
mutex_unlock(&fwnode_link_lock);
9911004
return -EPROBE_DEFER;
9921005
}
@@ -1001,8 +1014,9 @@ int device_links_check_suppliers(struct device *dev)
10011014
if (link->status != DL_STATE_AVAILABLE &&
10021015
!(link->flags & DL_FLAG_SYNC_STATE_ONLY)) {
10031016
device_links_missing_supplier(dev);
1004-
dev_dbg(dev, "probe deferral - supplier %s not ready\n",
1005-
dev_name(link->supplier));
1017+
dev_err_probe(dev, -EPROBE_DEFER,
1018+
"supplier %s not ready\n",
1019+
dev_name(link->supplier));
10061020
ret = -EPROBE_DEFER;
10071021
break;
10081022
}
@@ -1722,6 +1736,25 @@ static int fw_devlink_create_devlink(struct device *con,
17221736
struct device *sup_dev;
17231737
int ret = 0;
17241738

1739+
/*
1740+
* In some cases, a device P might also be a supplier to its child node
1741+
* C. However, this would defer the probe of C until the probe of P
1742+
* completes successfully. This is perfectly fine in the device driver
1743+
* model. device_add() doesn't guarantee probe completion of the device
1744+
* by the time it returns.
1745+
*
1746+
* However, there are a few drivers that assume C will finish probing
1747+
* as soon as it's added and before P finishes probing. So, we provide
1748+
* a flag to let fw_devlink know not to delay the probe of C until the
1749+
* probe of P completes successfully.
1750+
*
1751+
* When such a flag is set, we can't create device links where P is the
1752+
* supplier of C as that would delay the probe of C.
1753+
*/
1754+
if (sup_handle->flags & FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD &&
1755+
fwnode_is_ancestor_of(sup_handle, con->fwnode))
1756+
return -EINVAL;
1757+
17251758
sup_dev = get_dev_from_fwnode(sup_handle);
17261759
if (sup_dev) {
17271760
/*
@@ -1772,14 +1805,21 @@ static int fw_devlink_create_devlink(struct device *con,
17721805
* be broken by applying logic. Check for these types of cycles and
17731806
* break them so that devices in the cycle probe properly.
17741807
*
1775-
* If the supplier's parent is dependent on the consumer, then
1776-
* the consumer-supplier dependency is a false dependency. So,
1777-
* treat it as an invalid link.
1808+
* If the supplier's parent is dependent on the consumer, then the
1809+
* consumer and supplier have a cyclic dependency. Since fw_devlink
1810+
* can't tell which of the inferred dependencies are incorrect, don't
1811+
* enforce probe ordering between any of the devices in this cyclic
1812+
* dependency. Do this by relaxing all the fw_devlink device links in
1813+
* this cycle and by treating the fwnode link between the consumer and
1814+
* the supplier as an invalid dependency.
17781815
*/
17791816
sup_dev = fwnode_get_next_parent_dev(sup_handle);
17801817
if (sup_dev && device_is_dependent(con, sup_dev)) {
1781-
dev_dbg(con, "Not linking to %pfwP - False link\n",
1782-
sup_handle);
1818+
dev_info(con, "Fixing up cyclic dependency with %pfwP (%s)\n",
1819+
sup_handle, dev_name(sup_dev));
1820+
device_links_write_lock();
1821+
fw_devlink_relax_cycle(con, sup_dev);
1822+
device_links_write_unlock();
17831823
ret = -EINVAL;
17841824
} else {
17851825
/*
@@ -1858,9 +1898,7 @@ static void __fw_devlink_link_to_consumers(struct device *dev)
18581898
if (!own_link || ret == -EAGAIN)
18591899
continue;
18601900

1861-
list_del(&link->s_hook);
1862-
list_del(&link->c_hook);
1863-
kfree(link);
1901+
__fwnode_link_del(link);
18641902
}
18651903
}
18661904

@@ -1912,9 +1950,7 @@ static void __fw_devlink_link_to_suppliers(struct device *dev,
19121950
if (!own_link || ret == -EAGAIN)
19131951
continue;
19141952

1915-
list_del(&link->s_hook);
1916-
list_del(&link->c_hook);
1917-
kfree(link);
1953+
__fwnode_link_del(link);
19181954

19191955
/* If no device link was created, nothing more to do. */
19201956
if (ret)

drivers/net/phy/mdio_bus.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
525525
NULL == bus->read || NULL == bus->write)
526526
return -EINVAL;
527527

528+
if (bus->parent && bus->parent->of_node)
529+
bus->parent->of_node->fwnode.flags |=
530+
FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD;
531+
528532
BUG_ON(bus->state != MDIOBUS_ALLOCATED &&
529533
bus->state != MDIOBUS_UNREGISTERED);
530534

fs/debugfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ void debugfs_create_file_size(const char *name, umode_t mode,
528528
{
529529
struct dentry *de = debugfs_create_file(name, mode, parent, data, fops);
530530

531-
if (de)
531+
if (!IS_ERR(de))
532532
d_inode(de)->i_size = file_size;
533533
}
534534
EXPORT_SYMBOL_GPL(debugfs_create_file_size);

fs/kernfs/dir.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,13 @@ static struct dentry *kernfs_iop_lookup(struct inode *dir,
11161116
if (!inode)
11171117
inode = ERR_PTR(-ENOMEM);
11181118
}
1119-
/* Needed only for negative dentry validation */
1120-
if (!inode)
1119+
/*
1120+
* Needed for negative dentry validation.
1121+
* The negative dentry can be created in kernfs_iop_lookup()
1122+
* or transforms from positive dentry in dentry_unlink_inode()
1123+
* called from vfs_rmdir().
1124+
*/
1125+
if (!IS_ERR(inode))
11211126
kernfs_set_rev(parent, dentry);
11221127
up_read(&kernfs_rwsem);
11231128

include/linux/cpumask.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,14 +996,15 @@ cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
996996
* cpumask; Typically used by bin_attribute to export cpumask bitmask
997997
* ABI.
998998
*
999-
* Returns the length of how many bytes have been copied.
999+
* Returns the length of how many bytes have been copied, excluding
1000+
* terminating '\0'.
10001001
*/
10011002
static inline ssize_t
10021003
cpumap_print_bitmask_to_buf(char *buf, const struct cpumask *mask,
10031004
loff_t off, size_t count)
10041005
{
10051006
return bitmap_print_bitmask_to_buf(buf, cpumask_bits(mask),
1006-
nr_cpu_ids, off, count);
1007+
nr_cpu_ids, off, count) - 1;
10071008
}
10081009

10091010
/**
@@ -1018,7 +1019,7 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
10181019
loff_t off, size_t count)
10191020
{
10201021
return bitmap_print_list_to_buf(buf, cpumask_bits(mask),
1021-
nr_cpu_ids, off, count);
1022+
nr_cpu_ids, off, count) - 1;
10221023
}
10231024

10241025
#if NR_CPUS <= BITS_PER_LONG

include/linux/fwnode.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ struct device;
2222
* LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
2323
* NOT_DEVICE: The fwnode will never be populated as a struct device.
2424
* INITIALIZED: The hardware corresponding to fwnode has been initialized.
25+
* NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
26+
* driver needs its child devices to be bound with
27+
* their respective drivers as soon as they are
28+
* added.
2529
*/
26-
#define FWNODE_FLAG_LINKS_ADDED BIT(0)
27-
#define FWNODE_FLAG_NOT_DEVICE BIT(1)
28-
#define FWNODE_FLAG_INITIALIZED BIT(2)
30+
#define FWNODE_FLAG_LINKS_ADDED BIT(0)
31+
#define FWNODE_FLAG_NOT_DEVICE BIT(1)
32+
#define FWNODE_FLAG_INITIALIZED BIT(2)
33+
#define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
2934

3035
struct fwnode_handle {
3136
struct fwnode_handle *secondary;

0 commit comments

Comments
 (0)