Skip to content

Commit 8c8e62c

Browse files
committed
Merge tag 'driver-core-5.0-rc6' 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 fixes for 5.0-rc6. Well, not so much "driver core" as "debugfs". There's a lot of outstanding debugfs cleanup patches coming in through different subsystem trees, and in that process the debugfs core was found that it really should return errors when something bad happens, to prevent random files from showing up in the root of debugfs afterward. So debugfs was fixed up to handle this properly, and then two fixes for the relay and blk-mq code was needed as it was making invalid assumptions about debugfs return values. There's also a cacheinfo fix in here that resolves a tiny issue. All of these have been in linux-next for over a week with no reported problems" * tag 'driver-core-5.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: blk-mq: protect debugfs_create_files() from failures relay: check return of create_buf_file() properly debugfs: debugfs_lookup() should return NULL if not found debugfs: return error values, not NULL debugfs: fix debugfs_rename parameter checking cacheinfo: Keep the old value if of_property_read_u32 fails
2 parents e464f50 + 36991ca commit 8c8e62c

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

block/blk-mq-debugfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
839839
static bool debugfs_create_files(struct dentry *parent, void *data,
840840
const struct blk_mq_debugfs_attr *attr)
841841
{
842+
if (IS_ERR_OR_NULL(parent))
843+
return false;
844+
842845
d_inode(parent)->i_private = data;
843846

844847
for (; attr->name; attr++) {

drivers/base/cacheinfo.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static void cache_size(struct cacheinfo *this_leaf, struct device_node *np)
7979
ct_idx = get_cacheinfo_idx(this_leaf->type);
8080
propname = cache_type_info[ct_idx].size_prop;
8181

82-
if (of_property_read_u32(np, propname, &this_leaf->size))
83-
this_leaf->size = 0;
82+
of_property_read_u32(np, propname, &this_leaf->size);
8483
}
8584

8685
/* not cache_line_size() because that's a macro in include/linux/cache.h */
@@ -114,8 +113,7 @@ static void cache_nr_sets(struct cacheinfo *this_leaf, struct device_node *np)
114113
ct_idx = get_cacheinfo_idx(this_leaf->type);
115114
propname = cache_type_info[ct_idx].nr_sets_prop;
116115

117-
if (of_property_read_u32(np, propname, &this_leaf->number_of_sets))
118-
this_leaf->number_of_sets = 0;
116+
of_property_read_u32(np, propname, &this_leaf->number_of_sets);
119117
}
120118

121119
static void cache_associativity(struct cacheinfo *this_leaf)

fs/debugfs/inode.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static struct dentry *failed_creating(struct dentry *dentry)
324324
inode_unlock(d_inode(dentry->d_parent));
325325
dput(dentry);
326326
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
327-
return NULL;
327+
return ERR_PTR(-ENOMEM);
328328
}
329329

330330
static struct dentry *end_creating(struct dentry *dentry)
@@ -347,7 +347,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
347347
dentry = start_creating(name, parent);
348348

349349
if (IS_ERR(dentry))
350-
return NULL;
350+
return dentry;
351351

352352
inode = debugfs_get_inode(dentry->d_sb);
353353
if (unlikely(!inode))
@@ -386,7 +386,8 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
386386
* This function will return a pointer to a dentry if it succeeds. This
387387
* pointer must be passed to the debugfs_remove() function when the file is
388388
* to be removed (no automatic cleanup happens if your module is unloaded,
389-
* you are responsible here.) If an error occurs, %NULL will be returned.
389+
* you are responsible here.) If an error occurs, %ERR_PTR(-ERROR) will be
390+
* returned.
390391
*
391392
* If debugfs is not enabled in the kernel, the value -%ENODEV will be
392393
* returned.
@@ -464,7 +465,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_unsafe);
464465
* This function will return a pointer to a dentry if it succeeds. This
465466
* pointer must be passed to the debugfs_remove() function when the file is
466467
* to be removed (no automatic cleanup happens if your module is unloaded,
467-
* you are responsible here.) If an error occurs, %NULL will be returned.
468+
* you are responsible here.) If an error occurs, %ERR_PTR(-ERROR) will be
469+
* returned.
468470
*
469471
* If debugfs is not enabled in the kernel, the value -%ENODEV will be
470472
* returned.
@@ -495,7 +497,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
495497
* This function will return a pointer to a dentry if it succeeds. This
496498
* pointer must be passed to the debugfs_remove() function when the file is
497499
* to be removed (no automatic cleanup happens if your module is unloaded,
498-
* you are responsible here.) If an error occurs, %NULL will be returned.
500+
* you are responsible here.) If an error occurs, %ERR_PTR(-ERROR) will be
501+
* returned.
499502
*
500503
* If debugfs is not enabled in the kernel, the value -%ENODEV will be
501504
* returned.
@@ -506,7 +509,7 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
506509
struct inode *inode;
507510

508511
if (IS_ERR(dentry))
509-
return NULL;
512+
return dentry;
510513

511514
inode = debugfs_get_inode(dentry->d_sb);
512515
if (unlikely(!inode))
@@ -545,7 +548,7 @@ struct dentry *debugfs_create_automount(const char *name,
545548
struct inode *inode;
546549

547550
if (IS_ERR(dentry))
548-
return NULL;
551+
return dentry;
549552

550553
inode = debugfs_get_inode(dentry->d_sb);
551554
if (unlikely(!inode))
@@ -581,8 +584,8 @@ EXPORT_SYMBOL(debugfs_create_automount);
581584
* This function will return a pointer to a dentry if it succeeds. This
582585
* pointer must be passed to the debugfs_remove() function when the symbolic
583586
* link is to be removed (no automatic cleanup happens if your module is
584-
* unloaded, you are responsible here.) If an error occurs, %NULL will be
585-
* returned.
587+
* unloaded, you are responsible here.) If an error occurs, %ERR_PTR(-ERROR)
588+
* will be returned.
586589
*
587590
* If debugfs is not enabled in the kernel, the value -%ENODEV will be
588591
* returned.
@@ -594,12 +597,12 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
594597
struct inode *inode;
595598
char *link = kstrdup(target, GFP_KERNEL);
596599
if (!link)
597-
return NULL;
600+
return ERR_PTR(-ENOMEM);
598601

599602
dentry = start_creating(name, parent);
600603
if (IS_ERR(dentry)) {
601604
kfree(link);
602-
return NULL;
605+
return dentry;
603606
}
604607

605608
inode = debugfs_get_inode(dentry->d_sb);
@@ -787,6 +790,13 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
787790
struct dentry *dentry = NULL, *trap;
788791
struct name_snapshot old_name;
789792

793+
if (IS_ERR(old_dir))
794+
return old_dir;
795+
if (IS_ERR(new_dir))
796+
return new_dir;
797+
if (IS_ERR_OR_NULL(old_dentry))
798+
return old_dentry;
799+
790800
trap = lock_rename(new_dir, old_dir);
791801
/* Source or destination directories don't exist? */
792802
if (d_really_is_negative(old_dir) || d_really_is_negative(new_dir))
@@ -820,7 +830,9 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
820830
if (dentry && !IS_ERR(dentry))
821831
dput(dentry);
822832
unlock_rename(new_dir, old_dir);
823-
return NULL;
833+
if (IS_ERR(dentry))
834+
return dentry;
835+
return ERR_PTR(-EINVAL);
824836
}
825837
EXPORT_SYMBOL_GPL(debugfs_rename);
826838

kernel/relay.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ static struct dentry *relay_create_buf_file(struct rchan *chan,
428428
dentry = chan->cb->create_buf_file(tmpname, chan->parent,
429429
S_IRUSR, buf,
430430
&chan->is_global);
431+
if (IS_ERR(dentry))
432+
dentry = NULL;
431433

432434
kfree(tmpname);
433435

@@ -461,7 +463,7 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
461463
dentry = chan->cb->create_buf_file(NULL, NULL,
462464
S_IRUSR, buf,
463465
&chan->is_global);
464-
if (WARN_ON(dentry))
466+
if (IS_ERR_OR_NULL(dentry))
465467
goto free_buf;
466468
}
467469

0 commit comments

Comments
 (0)