All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fanotify: cleanups around return codes
@ 2010-12-07 19:39 Eric Paris
  0 siblings, 0 replies; only message in thread
From: Eric Paris @ 2010-12-07 19:39 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: LinoSanfilippo, Eric Paris

I just really happen to like

ret = -ENOMEM;
obj = kmalloc()
if (!obj)
	goto out;

As opposed to setting ret inside the conditional.  I also noticed that a
two functions were always returning 0 when they should have been passing
the errors back up the stack.  Fix both.

Signed-off-by: Eric Paris <eparis@redhat.com>
---
 fs/notify/fanotify/fanotify_user.c |   46 +++++++++++++++++------------------
 1 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index c9cd1b9..294dda0 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -540,23 +540,23 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
 {
 	struct fsnotify_mark *fsn_mark = NULL;
 	__u32 removed;
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&group->mutex);
+	ret = -ENOENT;
 	fsn_mark = fsnotify_find_vfsmount_mark(group, mnt);
-	if (!fsn_mark) {
-		ret = -ENOENT;
+	if (!fsn_mark)
 		goto err;
-	}
 
 	removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags);
 	fsnotify_put_mark(fsn_mark);
 	if (removed & mnt->mnt_fsnotify_mask)
 		fsnotify_recalc_vfsmount_mask(mnt);
+	ret = 0;
 err:
 	mutex_unlock(&group->mutex);
 
-	return 0;
+	return ret;
 }
 
 static int fanotify_remove_inode_mark(struct fsnotify_group *group,
@@ -565,24 +565,24 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,
 {
 	struct fsnotify_mark *fsn_mark = NULL;
 	__u32 removed;
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&group->mutex);
+	ret = -ENOENT;
 	fsn_mark = fsnotify_find_inode_mark(group, inode);
-	if (!fsn_mark) {
-		ret = -ENOENT;
+	if (!fsn_mark)
 		goto err;
-	}
 
 	removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags);
 	/* matches the fsnotify_find_inode_mark() */
 	fsnotify_put_mark(fsn_mark);
 	if (removed & inode->i_fsnotify_mask)
 		fsnotify_recalc_inode_mask(inode);
+	ret = 0;
 err:
 	mutex_unlock(&group->mutex);
 
-	return 0;
+	return ret;
 }
 
 static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
@@ -618,22 +618,20 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
 {
 	struct fsnotify_mark *fsn_mark;
 	__u32 added;
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&group->mutex);
 	fsn_mark = fsnotify_find_vfsmount_mark(group, mnt);
 	if (!fsn_mark) {
+		ret = -ENOSPC;
 		if (atomic_read(&group->num_marks) >
-		    group->fanotify_data.max_marks) {
-			ret = -ENOSPC;
+		    group->fanotify_data.max_marks)
 			goto err;
-		}
 
+		ret = -ENOMEM;
 		fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
-		if (!fsn_mark) {
-			ret = -ENOMEM;
+		if (!fsn_mark)
 			goto err;
-		}
 
 		fsnotify_init_mark(fsn_mark, fanotify_free_mark);
 		ret = fsnotify_add_mark(fsn_mark, group, NULL, mnt, 0);
@@ -644,6 +642,7 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
 
 	if (added & ~mnt->mnt_fsnotify_mask)
 		fsnotify_recalc_vfsmount_mask(mnt);
+	ret = 0;
 err2:
 	fsnotify_put_mark(fsn_mark);
 err:
@@ -657,7 +656,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
 {
 	struct fsnotify_mark *fsn_mark;
 	__u32 added;
-	int ret = 0;
+	int ret;
 
 	pr_debug("%s: group=%p inode=%p\n", __func__, group, inode);
 
@@ -674,17 +673,15 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
 	mutex_lock(&group->mutex);
 	fsn_mark = fsnotify_find_inode_mark(group, inode);
 	if (!fsn_mark) {
+		ret = -ENOSPC;
 		if (atomic_read(&group->num_marks) >
-		    group->fanotify_data.max_marks) {
-			ret = -ENOSPC;
+		    group->fanotify_data.max_marks)
 			goto err;
-		}
 
+		ret = -ENOMEM;
 		fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
-		if (!fsn_mark) {
-			ret = -ENOMEM;
+		if (!fsn_mark)
 			goto err;
-		}
 
 		fsnotify_init_mark(fsn_mark, fanotify_free_mark);
 		ret = fsnotify_add_mark(fsn_mark, group, inode, NULL, 0);
@@ -695,6 +692,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
 
 	if (added & ~inode->i_fsnotify_mask)
 		fsnotify_recalc_inode_mask(inode);
+	ret = 0;
 err2:
 	fsnotify_put_mark(fsn_mark);
 err:
-- 
1.7.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-07 19:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07 19:39 [PATCH] fanotify: cleanups around return codes Eric Paris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.