Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1434917 > unrolled thread

[PATCH 1/3] befs: avoid dereferencing dentry twice

Started byLuis de Bethencourt <luisbg@osg.samsung.com>
First post2016-07-01 02:10 +0200
Last post2016-07-01 02:10 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/3] befs: avoid dereferencing dentry twice Luis de Bethencourt <luisbg@osg.samsung.com> - 2016-07-01 02:10 +0200
    [PATCH 3/3] befs: use simpler while loop Luis de Bethencourt <luisbg@osg.samsung.com> - 2016-07-01 02:10 +0200
    [PATCH 2/3] befs: remove constant variable Luis de Bethencourt <luisbg@osg.samsung.com> - 2016-07-01 02:10 +0200

#1434917 — [PATCH 1/3] befs: avoid dereferencing dentry twice

FromLuis de Bethencourt <luisbg@osg.samsung.com>
Date2016-07-01 02:10 +0200
Subject[PATCH 1/3] befs: avoid dereferencing dentry twice
Message-ID<rPUbT-7Nl-7@gated-at.bofh.it>
No need to dereference dentry twice to get the name when we already have
it stored in a local variable.

Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
---

Hi,

3 more things I noticed while familiarizing myself with the code of this
filesystem. Enjoying very much learning how it works.

Thanks,
Luis

 fs/befs/linuxvfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 619b998..6740b0d 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -179,7 +179,7 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
 		kfree(utfname);
 
 	} else {
-		ret = befs_btree_find(sb, ds, dentry->d_name.name, &offset);
+		ret = befs_btree_find(sb, ds, name, &offset);
 	}
 
 	if (ret == BEFS_BT_NOT_FOUND) {
-- 
2.5.1

[toc] | [next] | [standalone]


#1434918 — [PATCH 3/3] befs: use simpler while loop

FromLuis de Bethencourt <luisbg@osg.samsung.com>
Date2016-07-01 02:10 +0200
Subject[PATCH 3/3] befs: use simpler while loop
Message-ID<rPUbT-7Nl-5@gated-at.bofh.it>
In reply to#1434917
Replace goto with simpler while loop to make befs_readdir() more readable.

Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
---
 fs/befs/linuxvfs.c | 74 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 38 insertions(+), 36 deletions(-)

diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index a16421a..3879048 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -216,48 +216,50 @@ befs_readdir(struct file *file, struct dir_context *ctx)
 	befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld",
 		  __func__, file, inode->i_ino, ctx->pos);
 
-more:
-	result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
-				 keybuf, &keysize, &value);
-
-	if (result == BEFS_ERR) {
-		befs_debug(sb, "<--- %s ERROR", __func__);
-		befs_error(sb, "IO error reading %pD (inode %lu)",
-			   file, inode->i_ino);
-		return -EIO;
-
-	} else if (result == BEFS_BT_END) {
-		befs_debug(sb, "<--- %s END", __func__);
-		return 0;
-
-	} else if (result == BEFS_BT_EMPTY) {
-		befs_debug(sb, "<--- %s Empty directory", __func__);
-		return 0;
-	}
+	while (1) {
+		result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
+					 keybuf, &keysize, &value);
 
-	/* Convert to NLS */
-	if (BEFS_SB(sb)->nls) {
-		char *nlsname;
-		int nlsnamelen;
-		result =
-		    befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen);
-		if (result < 0) {
+		if (result == BEFS_ERR) {
 			befs_debug(sb, "<--- %s ERROR", __func__);
-			return result;
+			befs_error(sb, "IO error reading %pD (inode %lu)",
+				   file, inode->i_ino);
+			return -EIO;
+
+		} else if (result == BEFS_BT_END) {
+			befs_debug(sb, "<--- %s END", __func__);
+			return 0;
+
+		} else if (result == BEFS_BT_EMPTY) {
+			befs_debug(sb, "<--- %s Empty directory", __func__);
+			return 0;
 		}
-		if (!dir_emit(ctx, nlsname, nlsnamelen,
-				 (ino_t) value, DT_UNKNOWN)) {
+
+		/* Convert to NLS */
+		if (BEFS_SB(sb)->nls) {
+			char *nlsname;
+			int nlsnamelen;
+
+			result =
+			    befs_utf2nls(sb, keybuf, keysize, &nlsname,
+					 &nlsnamelen);
+			if (result < 0) {
+				befs_debug(sb, "<--- %s ERROR", __func__);
+				return result;
+			}
+			if (!dir_emit(ctx, nlsname, nlsnamelen,
+				      (ino_t) value, DT_UNKNOWN)) {
+				kfree(nlsname);
+				return 0;
+			}
 			kfree(nlsname);
-			return 0;
+		} else {
+			if (!dir_emit(ctx, keybuf, keysize,
+				      (ino_t) value, DT_UNKNOWN))
+				return 0;
 		}
-		kfree(nlsname);
-	} else {
-		if (!dir_emit(ctx, keybuf, keysize,
-				 (ino_t) value, DT_UNKNOWN))
-			return 0;
+		ctx->pos++;
 	}
-	ctx->pos++;
-	goto more;
 }
 
 static struct inode *
-- 
2.5.1

[toc] | [prev] | [next] | [standalone]


#1434920 — [PATCH 2/3] befs: remove constant variable

FromLuis de Bethencourt <luisbg@osg.samsung.com>
Date2016-07-01 02:10 +0200
Subject[PATCH 2/3] befs: remove constant variable
Message-ID<rPUbT-7Nl-11@gated-at.bofh.it>
In reply to#1434917
Use macro directly instead of via assigning it to an unchanging variable.

Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
---
 fs/befs/linuxvfs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 6740b0d..a16421a 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -211,7 +211,6 @@ befs_readdir(struct file *file, struct dir_context *ctx)
 	befs_off_t value;
 	int result;
 	size_t keysize;
-	unsigned char d_type;
 	char keybuf[BEFS_NAME_LEN + 1];
 
 	befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld",
@@ -236,8 +235,6 @@ more:
 		return 0;
 	}
 
-	d_type = DT_UNKNOWN;
-
 	/* Convert to NLS */
 	if (BEFS_SB(sb)->nls) {
 		char *nlsname;
@@ -249,14 +246,14 @@ more:
 			return result;
 		}
 		if (!dir_emit(ctx, nlsname, nlsnamelen,
-				 (ino_t) value, d_type)) {
+				 (ino_t) value, DT_UNKNOWN)) {
 			kfree(nlsname);
 			return 0;
 		}
 		kfree(nlsname);
 	} else {
 		if (!dir_emit(ctx, keybuf, keysize,
-				 (ino_t) value, d_type))
+				 (ino_t) value, DT_UNKNOWN))
 			return 0;
 	}
 	ctx->pos++;
-- 
2.5.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web