const char *name;
int ret;
- mutex_lock(&eventfs_mutex);
+ guard(mutex)(&eventfs_mutex);
ei = dentry->d_fsdata;
- if (ei->is_freed) {
- /* Do not allow changes if the event is about to be removed. */
- mutex_unlock(&eventfs_mutex);
+ /* Do not allow changes if the event is about to be removed. */
+ if (ei->is_freed)
return -ENODEV;
- }
/* Preallocate the children mode array if necessary */
if (!(dentry->d_inode->i_mode & S_IFDIR)) {
if (!ei->entry_attrs) {
ei->entry_attrs = kzalloc_objs(*ei->entry_attrs,
ei->nr_entries, GFP_NOFS);
- if (!ei->entry_attrs) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!ei->entry_attrs)
+ return -ENOMEM;
}
}
ret = simple_setattr(idmap, dentry, iattr);
if (ret < 0)
- goto out;
+ return ret;
/*
* If this is a dir, then update the ei cache, only the file
}
}
}
- out:
- mutex_unlock(&eventfs_mutex);
return ret;
}
struct tracefs_inode *ti;
struct eventfs_inode *ei;
const char *name = dentry->d_name.name;
- struct dentry *result = NULL;
ti = get_tracefs(dir);
if (WARN_ON_ONCE(!(ti->flags & TRACEFS_EVENT_INODE)))
return ERR_PTR(-EIO);
- mutex_lock(&eventfs_mutex);
+ guard(mutex)(&eventfs_mutex);
ei = ti->private;
if (!ei || ei->is_freed)
- goto out;
+ return NULL;
list_for_each_entry(ei_child, &ei->children, list) {
if (strcmp(ei_child->name, name) != 0)
continue;
/* A child is freed and removed from the list at the same time */
if (WARN_ON_ONCE(ei_child->is_freed))
- goto out;
- result = lookup_dir_entry(dentry, ei, ei_child);
- goto out;
+ return NULL;
+ return lookup_dir_entry(dentry, ei, ei_child);
}
for (int i = 0; i < ei->nr_entries; i++) {
data = ei->data;
if (entry->callback(name, &mode, &data, &fops) <= 0)
- goto out;
+ return NULL;
+
+ return lookup_file_dentry(dentry, ei, i, mode, data, fops);
- result = lookup_file_dentry(dentry, ei, i, mode, data, fops);
- goto out;
}
- out:
- mutex_unlock(&eventfs_mutex);
- return result;
+ return NULL;
}
/*
struct eventfs_inode *ei;
const char *name;
umode_t mode;
- int idx;
int ret = -EINVAL;
int ino;
int i, r, c;
c = ctx->pos - 2;
- idx = srcu_read_lock(&eventfs_srcu);
+ guard(srcu)(&eventfs_srcu);
- mutex_lock(&eventfs_mutex);
- ei = READ_ONCE(ti->private);
- if (ei && ei->is_freed)
- ei = NULL;
- mutex_unlock(&eventfs_mutex);
-
- if (!ei)
- goto out;
+ scoped_guard(mutex, &eventfs_mutex) {
+ ei = READ_ONCE(ti->private);
+ if (!ei || ei->is_freed)
+ return -EINVAL;
+ }
/*
* Need to create the dentries and inodes to have a consistent
entry = &ei->entries[i];
name = entry->name;
- mutex_lock(&eventfs_mutex);
/* If ei->is_freed then just bail here, nothing more to do */
- if (ei->is_freed) {
- mutex_unlock(&eventfs_mutex);
- goto out;
+ scoped_guard(mutex, &eventfs_mutex) {
+ if (ei->is_freed)
+ return -EINVAL;
+ r = entry->callback(name, &mode, &cdata, &fops);
}
- r = entry->callback(name, &mode, &cdata, &fops);
- mutex_unlock(&eventfs_mutex);
if (r <= 0)
continue;
ino = EVENTFS_FILE_INODE_INO;
if (!dir_emit(ctx, name, strlen(name), ino, DT_REG))
- goto out;
+ return -EINVAL;
}
/* Subtract the skipped entries above */
ino = eventfs_dir_ino(ei_child);
- if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR))
- goto out_dec;
+ if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) {
+ /* Incremented ctx->pos without adding something, reset it */
+ ctx->pos--;
+ return -EINVAL;
+ }
}
- ret = 1;
- out:
- srcu_read_unlock(&eventfs_srcu, idx);
-
- return ret;
-
- out_dec:
- /* Incremented ctx->pos without adding something, reset it */
- ctx->pos--;
- goto out;
+ return 1;
}
/**
INIT_LIST_HEAD(&ei->children);
INIT_LIST_HEAD(&ei->list);
- mutex_lock(&eventfs_mutex);
- if (!parent->is_freed)
- list_add_tail(&ei->list, &parent->children);
- mutex_unlock(&eventfs_mutex);
-
+ scoped_guard(mutex, &eventfs_mutex) {
+ if (!parent->is_freed)
+ list_add_tail(&ei->list, &parent->children);
+ }
/* Was the parent freed? */
if (list_empty(&ei->list)) {
cleanup_ei(ei);
if (!ei)
return;
- mutex_lock(&eventfs_mutex);
+ guard(mutex)(&eventfs_mutex);
eventfs_remove_rec(ei, 0);
- mutex_unlock(&eventfs_mutex);
}
/**