Adding return value to securityfs_remove.
PATCH 1/1 Adding return value to securityfs_remove.
"securityfs_remove" can fail if it tries to remove a non-empty directory. This can happen, for example, if it tries to remove a file and its parent directory while the file is busy: the file removal will be delayed and the directory removal will fail.
This patch adds a return value to "securityfs_remove" so that the caller knows if it succeeded or not.
Signed-off-by Salvatore Mesoraca <[email protected]>
--- include/linux/security.h | 4 ++-- security/inode.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/security.h +2 -2
@@ -1590,7 +1590,7 @@ extern struct dentry *securityfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops);extern struct dentry *securityfs_create_dir (const char *name,struct dentry *parent); -extern void securityfs_remove (struct dentry *dentry); +extern int securityfs_remove (struct dentry *dentry);#else /* CONFIG_SECURITYFS */
@@ -1609,7 +1609,7 @@ static inline struct dentry *securityfs_create_file(const char *name, return ERR_PTR(-ENODEV); } -static inline void securityfs_remove (struct dentry *dentry) +static inline int securityfs_remove (struct dentry *dentry) {}#endif
security/inode.c +9 -5
@@ -183,28 +183,32 @@ EXPORT_SYMBOL_GPL(securityfs_create_dir);* This function is required to be called in order for the file to be * removed. No automatic cleanup of files will happen when a module is * removed; you are responsible here. +* +* Returns 0 if the remove succeeds, -errno on error. */ -void securityfs_remove (struct dentry *dentry) +int securityfs_remove (struct dentry *dentry) { +int ret = -EINVAL ;struct dentry *parent;if (!dentry ||IS_ERR (dentry)) -return ; +return ret; parent = dentry->d_parent;if (!parent ||d_really_is_negative (parent)) -return ; +return ret;mutex_lock (&d_inode (parent)->i_mutex);if (simple_positive (dentry)) {if (d_is_dir (dentry)) -simple_rmdir (d_inode (parent), dentry); + ret =simple_rmdir (d_inode (parent), dentry);else -simple_unlink (d_inode (parent), dentry); + ret =simple_unlink (d_inode (parent), dentry);dput (dentry); }mutex_unlock (&d_inode (parent)->i_mutex);simple_release_fs (&mount, &mount_count); +return ret; }EXPORT_SYMBOL_GPL (securityfs_remove);
--
2.3.6