Skip to contentSkip to conversation

f2fs: Use return value of strreplace()

PATCH In review Andy Shevchenko 3 participants 3 messages Jun 28, 2023 – Jul 11, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: Use return value of strreplace()

Since strreplace() returns the pointer to the string itself, we may use it directly in the code.

---
 include/trace/events/f2fs.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +2 -4
index 793f82cc1515..f5994515290c 100644
@@ -2234,13 +2234,11 @@ DECLARE_EVENT_CLASS(f2fs__rw_start,
 		 * because this screws up the tooling that parses
 		 * the traces.
 		 */
-		__assign_str(pathbuf, pathname);
-		(void)strreplace(__get_str(pathbuf), ' ', '_');
+		__assign_str(pathbuf, strreplace(pathname, ' ', '_'));
 		__entry->offset = offset;
 		__entry->bytes = bytes;
 		__entry->i_size = i_size_read(inode);
-		__assign_str(cmdline, command);
-		(void)strreplace(__get_str(cmdline), ' ', '_');
+		__assign_str(cmdline, strreplace(command, ' ', '_'));
 		__entry->pid = pid;
 		__entry->ino = inode->i_ino;
 	),
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer
#1 lore raw
Quoted 13 lines · On Wed, 28 Jun 2023 18:02:43 +0300 Andy Shevchenko…

Since strreplace() returns the pointer to the string itself, we may use it directly in the code.

---
 include/trace/events/f2fs.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +0 -0
index 793f82cc1515..f5994515290c 100644

include/trace/events/f2fs.h DECLARE_EVENT_CLASS(f2fs__rw_start, · line 2237

Quoted 6 lines
include/trace/events/f2fs.h +1 -2
@@ -2234,13 +2234,11 @@ DECLARE_EVENT_CLASS(f2fs__rw_start,
 		 * because this screws up the tooling that parses
 		 * the traces.
 		 */
-		__assign_str(pathbuf, pathname);
-		(void)strreplace(__get_str(pathbuf), ' ', '_');
+		__assign_str(pathbuf, strreplace(pathname, ' ', '_'));

But this modifies the pathname that is passed into the trace event, which is something that a trace point should never do! In fact, the char *pathname, really should be a const char * (for which this would fail to build).

Note, I went to look for these events and I can not find where they are used. Should these events just be deleted?

-- Steve

Quoted 9 lines
include/trace/events/f2fs.h +1 -2
 		__entry->offset = offset;
 		__entry->bytes = bytes;
 		__entry->i_size = i_size_read(inode);
-		__assign_str(cmdline, command);
-		(void)strreplace(__get_str(cmdline), ' ', '_');
+		__assign_str(cmdline, strreplace(command, ' ', '_'));
 		__entry->pid = pid;
 		__entry->ino = inode->i_ino;
 	),
maintainer
#2 lore raw
Quoted 28 lines · Steven Rostedt
Quoted 13 lines · On Wed, 28 Jun 2023 18:02:43 +0300 Andy Shevchenko…

Since strreplace() returns the pointer to the string itself, we may use it directly in the code.

---
 include/trace/events/f2fs.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +0 -0
index 793f82cc1515..f5994515290c 100644

include/trace/events/f2fs.h DECLARE_EVENT_CLASS(f2fs__rw_start, · line 2237

Quoted 6 lines
include/trace/events/f2fs.h +1 -2
@@ -2234,13 +2234,11 @@ DECLARE_EVENT_CLASS(f2fs__rw_start,
 		 * because this screws up the tooling that parses
 		 * the traces.
 		 */
-		__assign_str(pathbuf, pathname);
-		(void)strreplace(__get_str(pathbuf), ' ', '_');
+		__assign_str(pathbuf, strreplace(pathname, ' ', '_'));

But this modifies the pathname that is passed into the trace event, which is something that a trace point should never do! In fact, the char *pathname, really should be a const char * (for which this would fail to build).

Quoted 2 lines

Note, I went to look for these events and I can not find where they are used. Should these events just be deleted?

Hmm, this was a part of upstream effort to replace the previous android_fs tracepoints like:
https://android-review.git.corp.google.com/c/platform/system/extras/+/2223339

Quoted 13 lines

-- Steve

Quoted 9 lines
include/trace/events/f2fs.h +1 -2
 		__entry->offset = offset;
 		__entry->bytes = bytes;
 		__entry->i_size = i_size_read(inode);
-		__assign_str(cmdline, command);
-		(void)strreplace(__get_str(cmdline), ' ', '_');
+		__assign_str(cmdline, strreplace(command, ' ', '_'));
 		__entry->pid = pid;
 		__entry->ino = inode->i_ino;
 	),