All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: use kbasename in btrfsic_mount
@ 2015-11-27  8:11 Rasmus Villemoes
  2015-11-27  8:31 ` David Sterba
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Rasmus Villemoes @ 2015-11-27  8:11 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: Rasmus Villemoes, linux-btrfs, linux-kernel

This is more readable.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---

I think the following strlcpy may be somewhat fragile since obviously
ds->name and p overlap. It certainly relies on strlcpy doing a forward
copy, and since different architectures can have their own strlcpy,
that's hard to verify (and also won't necessarily continue to hold).

Maybe

  if (p != ds->name)
    memmove(ds->name, p, strlen(p)+1);

instead.


 fs/btrfs/check-integrity.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 0340c57bf377..55a5cff390b9 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -95,6 +95,7 @@
 #include <linux/genhd.h>
 #include <linux/blkdev.h>
 #include <linux/vmalloc.h>
+#include <linux/string.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "hash.h"
@@ -3136,11 +3137,7 @@ int btrfsic_mount(struct btrfs_root *root,
 		ds->state = state;
 		bdevname(ds->bdev, ds->name);
 		ds->name[BDEVNAME_SIZE - 1] = '\0';
-		for (p = ds->name; *p != '\0'; p++);
-		while (p > ds->name && *p != '/')
-			p--;
-		if (*p == '/')
-			p++;
+		p = kbasename(ds->name);
 		strlcpy(ds->name, p, sizeof(ds->name));
 		btrfsic_dev_state_hashtable_add(ds,
 						&btrfsic_dev_state_hashtable);
-- 
2.6.1


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

end of thread, other threads:[~2015-11-27  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-27  8:11 [PATCH] btrfs: use kbasename in btrfsic_mount Rasmus Villemoes
2015-11-27  8:31 ` David Sterba
2015-11-27  8:32 ` kbuild test robot
2015-11-27  8:38   ` Rasmus Villemoes
2015-11-27  9:37 ` Andy Shevchenko

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.