Skip to content

Commit 0fb7b6f

Browse files
author
Peter Zijlstra
committed
Merge branch 'driver-core/driver-core-next'
Pull in dependent cgroup patches Signed-off-by: Peter Zijlstra <[email protected]>
2 parents 7e18e42 + 61742a7 commit 0fb7b6f

File tree

13 files changed

+172
-134
lines changed

13 files changed

+172
-134
lines changed

Documentation/driver-api/driver-model/devres.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ IOMAP
310310
devm_ioremap()
311311
devm_ioremap_uc()
312312
devm_ioremap_wc()
313-
devm_ioremap_np()
314313
devm_ioremap_resource() : checks resource, requests memory region, ioremaps
315314
devm_ioremap_resource_wc()
316315
devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device

drivers/base/class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ EXPORT_SYMBOL_GPL(__class_create);
260260
*/
261261
void class_destroy(struct class *cls)
262262
{
263-
if ((cls == NULL) || (IS_ERR(cls)))
263+
if (IS_ERR_OR_NULL(cls))
264264
return;
265265

266266
class_unregister(cls);

drivers/base/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
25092509
rc = kobject_synth_uevent(&dev->kobj, buf, count);
25102510

25112511
if (rc) {
2512-
dev_err(dev, "uevent: failed to send synthetic uevent\n");
2512+
dev_err(dev, "uevent: failed to send synthetic uevent: %d\n", rc);
25132513
return rc;
25142514
}
25152515

drivers/base/dd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static int __init save_async_options(char *buf)
836836
if (strlen(buf) >= ASYNC_DRV_NAMES_MAX_LEN)
837837
pr_warn("Too long list of driver names for 'driver_async_probe'!\n");
838838

839-
strlcpy(async_probe_drv_names, buf, ASYNC_DRV_NAMES_MAX_LEN);
839+
strscpy(async_probe_drv_names, buf, ASYNC_DRV_NAMES_MAX_LEN);
840840
async_probe_default = parse_option_str(async_probe_drv_names, "*");
841841

842842
return 1;

drivers/base/devres.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ static __always_inline struct devres * alloc_dr(dr_release_t release,
117117
if (unlikely(!dr))
118118
return NULL;
119119

120-
memset(dr, 0, offsetof(struct devres, data));
120+
/* No need to clear memory twice */
121+
if (!(gfp & __GFP_ZERO))
122+
memset(dr, 0, offsetof(struct devres, data));
121123

122124
INIT_LIST_HEAD(&dr->node.entry);
123125
dr->node.release = release;

fs/kernfs/dir.c

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,16 @@ static void kernfs_drain(struct kernfs_node *kn)
472472
lockdep_assert_held_write(&root->kernfs_rwsem);
473473
WARN_ON_ONCE(kernfs_active(kn));
474474

475+
/*
476+
* Skip draining if already fully drained. This avoids draining and its
477+
* lockdep annotations for nodes which have never been activated
478+
* allowing embedding kernfs_remove() in create error paths without
479+
* worrying about draining.
480+
*/
481+
if (atomic_read(&kn->active) == KN_DEACTIVATED_BIAS &&
482+
!kernfs_should_drain_open_files(kn))
483+
return;
484+
475485
up_write(&root->kernfs_rwsem);
476486

477487
if (kernfs_lockdep(kn)) {
@@ -480,7 +490,6 @@ static void kernfs_drain(struct kernfs_node *kn)
480490
lock_contended(&kn->dep_map, _RET_IP_);
481491
}
482492

483-
/* but everyone should wait for draining */
484493
wait_event(root->deactivate_waitq,
485494
atomic_read(&kn->active) == KN_DEACTIVATED_BIAS);
486495

@@ -489,7 +498,8 @@ static void kernfs_drain(struct kernfs_node *kn)
489498
rwsem_release(&kn->dep_map, _RET_IP_);
490499
}
491500

492-
kernfs_drain_open_files(kn);
501+
if (kernfs_should_drain_open_files(kn))
502+
kernfs_drain_open_files(kn);
493503

494504
down_write(&root->kernfs_rwsem);
495505
}
@@ -695,13 +705,7 @@ struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root,
695705
goto err_unlock;
696706
}
697707

698-
/*
699-
* ACTIVATED is protected with kernfs_mutex but it was clear when
700-
* @kn was added to idr and we just wanna see it set. No need to
701-
* grab kernfs_mutex.
702-
*/
703-
if (unlikely(!(kn->flags & KERNFS_ACTIVATED) ||
704-
!atomic_inc_not_zero(&kn->count)))
708+
if (unlikely(!kernfs_active(kn) || !atomic_inc_not_zero(&kn->count)))
705709
goto err_unlock;
706710

707711
spin_unlock(&kernfs_idr_lock);
@@ -743,10 +747,7 @@ int kernfs_add_one(struct kernfs_node *kn)
743747
goto out_unlock;
744748

745749
ret = -ENOENT;
746-
if (parent->flags & KERNFS_EMPTY_DIR)
747-
goto out_unlock;
748-
749-
if ((parent->flags & KERNFS_ACTIVATED) && !kernfs_active(parent))
750+
if (parent->flags & (KERNFS_REMOVING | KERNFS_EMPTY_DIR))
750751
goto out_unlock;
751752

752753
kn->hash = kernfs_name_hash(kn->name, kn->ns);
@@ -1304,6 +1305,21 @@ static struct kernfs_node *kernfs_next_descendant_post(struct kernfs_node *pos,
13041305
return pos->parent;
13051306
}
13061307

1308+
static void kernfs_activate_one(struct kernfs_node *kn)
1309+
{
1310+
lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem);
1311+
1312+
kn->flags |= KERNFS_ACTIVATED;
1313+
1314+
if (kernfs_active(kn) || (kn->flags & (KERNFS_HIDDEN | KERNFS_REMOVING)))
1315+
return;
1316+
1317+
WARN_ON_ONCE(kn->parent && RB_EMPTY_NODE(&kn->rb));
1318+
WARN_ON_ONCE(atomic_read(&kn->active) != KN_DEACTIVATED_BIAS);
1319+
1320+
atomic_sub(KN_DEACTIVATED_BIAS, &kn->active);
1321+
}
1322+
13071323
/**
13081324
* kernfs_activate - activate a node which started deactivated
13091325
* @kn: kernfs_node whose subtree is to be activated
@@ -1325,15 +1341,42 @@ void kernfs_activate(struct kernfs_node *kn)
13251341
down_write(&root->kernfs_rwsem);
13261342

13271343
pos = NULL;
1328-
while ((pos = kernfs_next_descendant_post(pos, kn))) {
1329-
if (pos->flags & KERNFS_ACTIVATED)
1330-
continue;
1344+
while ((pos = kernfs_next_descendant_post(pos, kn)))
1345+
kernfs_activate_one(pos);
1346+
1347+
up_write(&root->kernfs_rwsem);
1348+
}
13311349

1332-
WARN_ON_ONCE(pos->parent && RB_EMPTY_NODE(&pos->rb));
1333-
WARN_ON_ONCE(atomic_read(&pos->active) != KN_DEACTIVATED_BIAS);
1350+
/**
1351+
* kernfs_show - show or hide a node
1352+
* @kn: kernfs_node to show or hide
1353+
* @show: whether to show or hide
1354+
*
1355+
* If @show is %false, @kn is marked hidden and deactivated. A hidden node is
1356+
* ignored in future activaitons. If %true, the mark is removed and activation
1357+
* state is restored. This function won't implicitly activate a new node in a
1358+
* %KERNFS_ROOT_CREATE_DEACTIVATED root which hasn't been activated yet.
1359+
*
1360+
* To avoid recursion complexities, directories aren't supported for now.
1361+
*/
1362+
void kernfs_show(struct kernfs_node *kn, bool show)
1363+
{
1364+
struct kernfs_root *root = kernfs_root(kn);
13341365

1335-
atomic_sub(KN_DEACTIVATED_BIAS, &pos->active);
1336-
pos->flags |= KERNFS_ACTIVATED;
1366+
if (WARN_ON_ONCE(kernfs_type(kn) == KERNFS_DIR))
1367+
return;
1368+
1369+
down_write(&root->kernfs_rwsem);
1370+
1371+
if (show) {
1372+
kn->flags &= ~KERNFS_HIDDEN;
1373+
if (kn->flags & KERNFS_ACTIVATED)
1374+
kernfs_activate_one(kn);
1375+
} else {
1376+
kn->flags |= KERNFS_HIDDEN;
1377+
if (kernfs_active(kn))
1378+
atomic_add(KN_DEACTIVATED_BIAS, &kn->active);
1379+
kernfs_drain(kn);
13371380
}
13381381

13391382
up_write(&root->kernfs_rwsem);
@@ -1358,34 +1401,27 @@ static void __kernfs_remove(struct kernfs_node *kn)
13581401

13591402
pr_debug("kernfs %s: removing\n", kn->name);
13601403

1361-
/* prevent any new usage under @kn by deactivating all nodes */
1404+
/* prevent new usage by marking all nodes removing and deactivating */
13621405
pos = NULL;
1363-
while ((pos = kernfs_next_descendant_post(pos, kn)))
1406+
while ((pos = kernfs_next_descendant_post(pos, kn))) {
1407+
pos->flags |= KERNFS_REMOVING;
13641408
if (kernfs_active(pos))
13651409
atomic_add(KN_DEACTIVATED_BIAS, &pos->active);
1410+
}
13661411

13671412
/* deactivate and unlink the subtree node-by-node */
13681413
do {
13691414
pos = kernfs_leftmost_descendant(kn);
13701415

13711416
/*
1372-
* kernfs_drain() drops kernfs_rwsem temporarily and @pos's
1417+
* kernfs_drain() may drop kernfs_rwsem temporarily and @pos's
13731418
* base ref could have been put by someone else by the time
13741419
* the function returns. Make sure it doesn't go away
13751420
* underneath us.
13761421
*/
13771422
kernfs_get(pos);
13781423

1379-
/*
1380-
* Drain iff @kn was activated. This avoids draining and
1381-
* its lockdep annotations for nodes which have never been
1382-
* activated and allows embedding kernfs_remove() in create
1383-
* error paths without worrying about draining.
1384-
*/
1385-
if (kn->flags & KERNFS_ACTIVATED)
1386-
kernfs_drain(pos);
1387-
else
1388-
WARN_ON_ONCE(atomic_read(&kn->active) != KN_DEACTIVATED_BIAS);
1424+
kernfs_drain(pos);
13891425

13901426
/*
13911427
* kernfs_unlink_sibling() succeeds once per node. Use it

0 commit comments

Comments
 (0)