linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH 0/8] Introduce strreplace
@ 2015-06-04  9:37 Rasmus Villemoes
  2015-06-04  9:37 ` [RFC/PATCH 7/8] fs/jbd2/journal.c: Use strreplace Rasmus Villemoes
  2015-06-04  9:37 ` [RFC/PATCH 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super Rasmus Villemoes
  0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-06-04  9:37 UTC (permalink / raw)
  To: Andrew Morton, Greg Kroah-Hartman, Neil Brown, Theodore Ts'o,
	Andreas Dilger, Steven Rostedt, Ingo Molnar
  Cc: Rasmus Villemoes, linux-kernel, linux-raid, linux-ext4

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.

Rasmus Villemoes (8):
  lib: string: Introduce strreplace
  kernel/trace/trace_events_filter.c: Use strreplace
  blktrace: use strreplace in do_blk_trace_setup
  lib/kobject.c: Use strreplace
  drivers/base/core.c: Use strreplace
  drivers/md/md.c: Use strreplace
  fs/jbd2/journal.c: Use strreplace
  fs/ext4/super.c: Use strreplace in ext4_fill_super

 drivers/base/core.c                |  5 +----
 drivers/md/md.c                    |  4 +---
 fs/ext4/super.c                    |  4 +---
 fs/jbd2/journal.c                  | 10 ++--------
 include/linux/string.h             |  1 +
 kernel/trace/blktrace.c            |  6 ++----
 kernel/trace/trace_events_filter.c |  5 ++---
 lib/kobject.c                      |  4 +---
 lib/string.c                       | 17 +++++++++++++++++
 9 files changed, 28 insertions(+), 28 deletions(-)

-- 
2.1.3

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

* [RFC/PATCH 7/8] fs/jbd2/journal.c: Use strreplace
  2015-06-04  9:37 [RFC/PATCH 0/8] Introduce strreplace Rasmus Villemoes
@ 2015-06-04  9:37 ` Rasmus Villemoes
  2015-06-04  9:37 ` [RFC/PATCH 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super Rasmus Villemoes
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-06-04  9:37 UTC (permalink / raw)
  To: Andrew Morton, Theodore Ts'o
  Cc: 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>
---
 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] 3+ messages in thread

* [RFC/PATCH 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super
  2015-06-04  9:37 [RFC/PATCH 0/8] Introduce strreplace Rasmus Villemoes
  2015-06-04  9:37 ` [RFC/PATCH 7/8] fs/jbd2/journal.c: Use strreplace Rasmus Villemoes
@ 2015-06-04  9:37 ` Rasmus Villemoes
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-06-04  9:37 UTC (permalink / raw)
  To: Andrew Morton, Theodore Ts'o, Andreas Dilger
  Cc: Rasmus Villemoes, linux-ext4, linux-kernel

This makes a very large function a little smaller.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 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] 3+ messages in thread

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-04  9:37 [RFC/PATCH 0/8] Introduce strreplace Rasmus Villemoes
2015-06-04  9:37 ` [RFC/PATCH 7/8] fs/jbd2/journal.c: Use strreplace Rasmus Villemoes
2015-06-04  9:37 ` [RFC/PATCH 8/8] fs/ext4/super.c: Use strreplace in ext4_fill_super Rasmus Villemoes

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).