* [PATCH v2 7/8] fs/jbd2/journal.c: Use strreplace
2015-06-08 23:26 [PATCH v2 0/8] Introduce strreplace Rasmus Villemoes
@ 2015-06-08 23:26 ` Rasmus Villemoes
2015-06-08 23:26 ` [PATCH v2 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super Rasmus Villemoes
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2015-06-08 23:26 UTC (permalink / raw)
To: Andrew Morton, Theodore Ts'o
Cc: Joe Perches, Al Viro, Rasmus Villemoes, linux-ext4, linux-kernel
In one case, we eliminate a local variable; in the other a strlen()
call and some .text.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
v2: no changes.
fs/jbd2/journal.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b96bd8076b70..5c187ded12d6 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1137,7 +1137,6 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
{
journal_t *journal = journal_init_common();
struct buffer_head *bh;
- char *p;
int n;
if (!journal)
@@ -1150,9 +1149,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
journal->j_blk_offset = start;
journal->j_maxlen = len;
bdevname(journal->j_dev, journal->j_devname);
- p = journal->j_devname;
- while ((p = strchr(p, '/')))
- *p = '!';
+ strreplace(journal->j_devname, '/', '!');
jbd2_stats_proc_init(journal);
n = journal->j_blocksize / sizeof(journal_block_tag_t);
journal->j_wbufsize = n;
@@ -1204,10 +1201,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
journal->j_inode = inode;
bdevname(journal->j_dev, journal->j_devname);
- p = journal->j_devname;
- while ((p = strchr(p, '/')))
- *p = '!';
- p = journal->j_devname + strlen(journal->j_devname);
+ p = strreplace(journal->j_devname, '/', '!');
sprintf(p, "-%lu", journal->j_inode->i_ino);
jbd_debug(1,
"journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
--
2.1.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super
2015-06-08 23:26 [PATCH v2 0/8] Introduce strreplace Rasmus Villemoes
2015-06-08 23:26 ` [PATCH v2 7/8] fs/jbd2/journal.c: Use strreplace Rasmus Villemoes
@ 2015-06-08 23:26 ` Rasmus Villemoes
2015-06-09 0:55 ` [PATCH v2 0/8] Introduce strreplace Theodore Ts'o
2015-06-09 21:02 ` Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2015-06-08 23:26 UTC (permalink / raw)
To: Andrew Morton, Theodore Ts'o, Andreas Dilger
Cc: Joe Perches, Al Viro, Rasmus Villemoes, linux-ext4, linux-kernel
This makes a very large function a little smaller.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
v2: no changes.
fs/ext4/super.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ca9d4a2fed41..5f3c43a66937 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3420,7 +3420,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
unsigned long journal_devnum = 0;
unsigned long def_mount_opts;
struct inode *root;
- char *cp;
const char *descr;
int ret = -ENOMEM;
int blocksize, clustersize;
@@ -3456,8 +3455,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
#endif
/* Cleanup superblock name */
- for (cp = sb->s_id; (cp = strchr(cp, '/'));)
- *cp = '!';
+ strreplace(sb->s_id, '/', '!');
/* -EINVAL is default */
ret = -EINVAL;
--
2.1.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/8] Introduce strreplace
2015-06-08 23:26 [PATCH v2 0/8] Introduce strreplace Rasmus Villemoes
2015-06-08 23:26 ` [PATCH v2 7/8] fs/jbd2/journal.c: Use strreplace Rasmus Villemoes
2015-06-08 23:26 ` [PATCH v2 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super Rasmus Villemoes
@ 2015-06-09 0:55 ` Theodore Ts'o
2015-06-09 7:25 ` Rasmus Villemoes
2015-06-09 21:02 ` Andrew Morton
3 siblings, 1 reply; 6+ messages in thread
From: Theodore Ts'o @ 2015-06-09 0:55 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: Andrew Morton, Greg Kroah-Hartman, Neil Brown, Andreas Dilger,
Steven Rostedt, Ingo Molnar, Joe Perches, Al Viro, linux-kernel,
linux-raid, linux-ext4
On Tue, Jun 09, 2015 at 01:26:48AM +0200, Rasmus Villemoes wrote:
> Doing single-character substitution on an entire string is open-coded
> in a few places, sometimes in a rather suboptimal way. This introduces
> a trivial helper, strreplace, for this task along with a few example
> conversions.
>
> Andrew, can I get you to take 1/8 through the mm tree? I'm not sure
> what the easiest path is for the remaining patches.
This is not super urgent, right? So we could let 1/8 go into
mainline, and then the rest of the patches could go in the next
release. That would be the simplest, although it would drag out how
long it would take for strreplace to be used everywhere.
- Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/8] Introduce strreplace
2015-06-09 0:55 ` [PATCH v2 0/8] Introduce strreplace Theodore Ts'o
@ 2015-06-09 7:25 ` Rasmus Villemoes
0 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2015-06-09 7:25 UTC (permalink / raw)
To: Theodore Ts'o
Cc: Andrew Morton, Greg Kroah-Hartman, Neil Brown, Andreas Dilger,
Steven Rostedt, Ingo Molnar, Joe Perches, Al Viro, linux-kernel,
linux-raid, linux-ext4
On Tue, Jun 09 2015, Theodore Ts'o <tytso@mit.edu> wrote:
> On Tue, Jun 09, 2015 at 01:26:48AM +0200, Rasmus Villemoes wrote:
>> Doing single-character substitution on an entire string is open-coded
>> in a few places, sometimes in a rather suboptimal way. This introduces
>> a trivial helper, strreplace, for this task along with a few example
>> conversions.
>>
>> Andrew, can I get you to take 1/8 through the mm tree? I'm not sure
>> what the easiest path is for the remaining patches.
>
> This is not super urgent, right?
Right, not urgent at all.
> So we could let 1/8 go into mainline, and then the rest of the patches
> could go in the next release. That would be the simplest, although it
> would drag out how long it would take for strreplace to be used
> everywhere.
Sure, though it would be a little weird to have a helper with no users
until 4.3 comes out.
Rasmus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/8] Introduce strreplace
2015-06-08 23:26 [PATCH v2 0/8] Introduce strreplace Rasmus Villemoes
` (2 preceding siblings ...)
2015-06-09 0:55 ` [PATCH v2 0/8] Introduce strreplace Theodore Ts'o
@ 2015-06-09 21:02 ` Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2015-06-09 21:02 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: Greg Kroah-Hartman, Neil Brown, Theodore Ts'o, Andreas Dilger,
Steven Rostedt, Ingo Molnar, Joe Perches, Al Viro, linux-kernel,
linux-raid, linux-ext4
On Tue, 9 Jun 2015 01:26:48 +0200 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> Doing single-character substitution on an entire string is open-coded
> in a few places, sometimes in a rather suboptimal way. This introduces
> a trivial helper, strreplace, for this task along with a few example
> conversions.
>
> Andrew, can I get you to take 1/8 through the mm tree? I'm not sure
> what the easiest path is for the remaining patches.
With this sort of thing I grab everything them feed the dependent
patches to maintainers after the base patch is upstream.
Or I merge the dependent patches myself if they were acked.
Or if the dependent patches are simple I'll just merge them anyway,
shrug. I'd say these fall into that category.
^ permalink raw reply [flat|nested] 6+ messages in thread