linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] befs: avoid dereferencing dentry twice
@ 2016-07-01  0:07 Luis de Bethencourt
  2016-07-01  0:07 ` [PATCH 2/3] befs: remove constant variable Luis de Bethencourt
  2016-07-01  0:07 ` [PATCH 3/3] befs: use simpler while loop Luis de Bethencourt
  0 siblings, 2 replies; 4+ messages in thread
From: Luis de Bethencourt @ 2016-07-01  0:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, salah.triki, viro, hannes, vdavydov, Luis de Bethencourt

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] befs: remove constant variable
  2016-07-01  0:07 [PATCH 1/3] befs: avoid dereferencing dentry twice Luis de Bethencourt
@ 2016-07-01  0:07 ` Luis de Bethencourt
  2016-07-28  0:11   ` Salah Triki
  2016-07-01  0:07 ` [PATCH 3/3] befs: use simpler while loop Luis de Bethencourt
  1 sibling, 1 reply; 4+ messages in thread
From: Luis de Bethencourt @ 2016-07-01  0:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, salah.triki, viro, hannes, vdavydov, Luis de Bethencourt

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] befs: use simpler while loop
  2016-07-01  0:07 [PATCH 1/3] befs: avoid dereferencing dentry twice Luis de Bethencourt
  2016-07-01  0:07 ` [PATCH 2/3] befs: remove constant variable Luis de Bethencourt
@ 2016-07-01  0:07 ` Luis de Bethencourt
  1 sibling, 0 replies; 4+ messages in thread
From: Luis de Bethencourt @ 2016-07-01  0:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, salah.triki, viro, hannes, vdavydov, Luis de Bethencourt

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] befs: remove constant variable
  2016-07-01  0:07 ` [PATCH 2/3] befs: remove constant variable Luis de Bethencourt
@ 2016-07-28  0:11   ` Salah Triki
  0 siblings, 0 replies; 4+ messages in thread
From: Salah Triki @ 2016-07-28  0:11 UTC (permalink / raw)
  To: Luis de Bethencourt; +Cc: linux-kernel, akpm, viro, hannes, vdavydov

On Fri, Jul 01, 2016 at 01:07:31AM +0100, Luis de Bethencourt wrote:
> 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
> 

Acked-by: Salah Triki <salah.triki@gmail.com>

Thanx :)
salah

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-28  0:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-01  0:07 [PATCH 1/3] befs: avoid dereferencing dentry twice Luis de Bethencourt
2016-07-01  0:07 ` [PATCH 2/3] befs: remove constant variable Luis de Bethencourt
2016-07-28  0:11   ` Salah Triki
2016-07-01  0:07 ` [PATCH 3/3] befs: use simpler while loop Luis de Bethencourt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).