Skip to content

Commit eceae1e

Browse files
committed
Merge tag 'configfs-5.15' of git://git.infradead.org/users/hch/configfs
Pull configfs updates from Christoph Hellwig: - fix a race in configfs_lookup (Sishuai Gong) - minor cleanups (me) * tag 'configfs-5.15' of git://git.infradead.org/users/hch/configfs: configfs: fix a race in configfs_lookup() configfs: fold configfs_attach_attr into configfs_lookup configfs: simplify the configfs_dirent_is_ready configfs: return -ENAMETOOLONG earlier in configfs_lookup
2 parents 265113f + c42dd06 commit eceae1e

1 file changed

Lines changed: 31 additions & 56 deletions

File tree

fs/configfs/dir.c

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void configfs_d_iput(struct dentry * dentry,
4545
/*
4646
* Set sd->s_dentry to null only when this dentry is the one
4747
* that is going to be killed. Otherwise configfs_d_iput may
48-
* run just after configfs_attach_attr and set sd->s_dentry to
48+
* run just after configfs_lookup and set sd->s_dentry to
4949
* NULL even it's still in use.
5050
*/
5151
if (sd->s_dentry == dentry)
@@ -417,44 +417,16 @@ static void configfs_remove_dir(struct config_item * item)
417417
dput(dentry);
418418
}
419419

420-
421-
/* attaches attribute's configfs_dirent to the dentry corresponding to the
422-
* attribute file
423-
*/
424-
static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry)
425-
{
426-
struct configfs_attribute * attr = sd->s_element;
427-
struct inode *inode;
428-
429-
spin_lock(&configfs_dirent_lock);
430-
dentry->d_fsdata = configfs_get(sd);
431-
sd->s_dentry = dentry;
432-
spin_unlock(&configfs_dirent_lock);
433-
434-
inode = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG);
435-
if (IS_ERR(inode)) {
436-
configfs_put(sd);
437-
return PTR_ERR(inode);
438-
}
439-
if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
440-
inode->i_size = 0;
441-
inode->i_fop = &configfs_bin_file_operations;
442-
} else {
443-
inode->i_size = PAGE_SIZE;
444-
inode->i_fop = &configfs_file_operations;
445-
}
446-
d_add(dentry, inode);
447-
return 0;
448-
}
449-
450420
static struct dentry * configfs_lookup(struct inode *dir,
451421
struct dentry *dentry,
452422
unsigned int flags)
453423
{
454424
struct configfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
455425
struct configfs_dirent * sd;
456-
int found = 0;
457-
int err;
426+
struct inode *inode = NULL;
427+
428+
if (dentry->d_name.len > NAME_MAX)
429+
return ERR_PTR(-ENAMETOOLONG);
458430

459431
/*
460432
* Fake invisibility if dir belongs to a group/default groups hierarchy
@@ -464,36 +436,39 @@ static struct dentry * configfs_lookup(struct inode *dir,
464436
* not complete their initialization, since the dentries of the
465437
* attributes won't be instantiated.
466438
*/
467-
err = -ENOENT;
468439
if (!configfs_dirent_is_ready(parent_sd))
469-
goto out;
440+
return ERR_PTR(-ENOENT);
470441

442+
spin_lock(&configfs_dirent_lock);
471443
list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
472-
if (sd->s_type & CONFIGFS_NOT_PINNED) {
473-
const unsigned char * name = configfs_get_name(sd);
444+
if ((sd->s_type & CONFIGFS_NOT_PINNED) &&
445+
!strcmp(configfs_get_name(sd), dentry->d_name.name)) {
446+
struct configfs_attribute *attr = sd->s_element;
447+
umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
474448

475-
if (strcmp(name, dentry->d_name.name))
476-
continue;
449+
dentry->d_fsdata = configfs_get(sd);
450+
sd->s_dentry = dentry;
451+
spin_unlock(&configfs_dirent_lock);
477452

478-
found = 1;
479-
err = configfs_attach_attr(sd, dentry);
480-
break;
453+
inode = configfs_create(dentry, mode);
454+
if (IS_ERR(inode)) {
455+
configfs_put(sd);
456+
return ERR_CAST(inode);
457+
}
458+
if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
459+
inode->i_size = 0;
460+
inode->i_fop = &configfs_bin_file_operations;
461+
} else {
462+
inode->i_size = PAGE_SIZE;
463+
inode->i_fop = &configfs_file_operations;
464+
}
465+
goto done;
481466
}
482467
}
483-
484-
if (!found) {
485-
/*
486-
* If it doesn't exist and it isn't a NOT_PINNED item,
487-
* it must be negative.
488-
*/
489-
if (dentry->d_name.len > NAME_MAX)
490-
return ERR_PTR(-ENAMETOOLONG);
491-
d_add(dentry, NULL);
492-
return NULL;
493-
}
494-
495-
out:
496-
return ERR_PTR(err);
468+
spin_unlock(&configfs_dirent_lock);
469+
done:
470+
d_add(dentry, inode);
471+
return NULL;
497472
}
498473

499474
/*

0 commit comments

Comments
 (0)