* [PATCH v2] btrfs: use kbasename in btrfsic_mount
@ 2015-11-27 8:42 Rasmus Villemoes
2015-11-27 8:46 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2015-11-27 8:42 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>
---
v2: make p const char* (thanks 0day).
Original comment:
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 | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 0340c57bf377..d6fe77c5b4ac 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"
@@ -3120,7 +3121,7 @@ int btrfsic_mount(struct btrfs_root *root,
list_for_each_entry(device, dev_head, dev_list) {
struct btrfsic_dev_state *ds;
- char *p;
+ const char *p;
if (!device->bdev || !device->name)
continue;
@@ -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 [flat|nested] 2+ messages in thread
* Re: [PATCH v2] btrfs: use kbasename in btrfsic_mount
2015-11-27 8:42 [PATCH v2] btrfs: use kbasename in btrfsic_mount Rasmus Villemoes
@ 2015-11-27 8:46 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2015-11-27 8:46 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs, linux-kernel
On Fri, Nov 27, 2015 at 10:42 AM, Rasmus Villemoes
<linux@rasmusvillemoes.dk> wrote:
> This is more readable.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
You missed David's tag.
Anyway, also mine is here
Reviewed-by Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
> v2: make p const char* (thanks 0day).
>
> Original comment:
>
> 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 | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
> index 0340c57bf377..d6fe77c5b4ac 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"
> @@ -3120,7 +3121,7 @@ int btrfsic_mount(struct btrfs_root *root,
>
> list_for_each_entry(device, dev_head, dev_list) {
> struct btrfsic_dev_state *ds;
> - char *p;
> + const char *p;
>
> if (!device->bdev || !device->name)
> continue;
> @@ -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
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-27 8:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-27 8:42 [PATCH v2] btrfs: use kbasename in btrfsic_mount Rasmus Villemoes
2015-11-27 8:46 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®