History

tracing: Clean up alloc_synth_event()

alloc_synth_event() currently has the following code to initialize the event fields and dynamic_fields: for (i = 0, j = 0; i < n_fields; i++) { event->fields[i] = fields[i]; if (fields[i]->is_dynamic) { event->dynamic_fields[j] = fields[i]; event->dynamic_fields[j]->field_pos = i; event->dynamic_fields[j++] = fields[i]; event->n_dynamic_fields++; } } 1) It would make more sense to have all fields keep track of their field_pos. 2) event->dynmaic_fields[j] is assigned twice for no reason. 3) We can move updating event->n_dynamic_fields outside the loop, and just assign it to j. This combination makes the code much cleaner. Link: https://lkml.kernel.org/r/20210721195341.29bb0f77@oasis.local.home

Steven Rostedt (VMware) committed 5 years ago

Commit 9528c191 parent 1e3bac71 file · +3 −5Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/trace/trace_events_synth.c+3−5
@@ -893,15 +893,13 @@ static struct synth_event *alloc_synth_event(const char *name, int n_fields, · 892 unmodified lines
893 dyn_event_init(&event->devent, &synth_event_ops);893 dyn_event_init(&event->devent, &synth_event_ops);
894 894
895 for (i = 0, j = 0; i < n_fields; i++) {895 for (i = 0, j = 0; i < n_fields; i++) {
896 fields[i]->field_pos = i;
896 event->fields[i] = fields[i];897 event->fields[i] = fields[i];
897 898
898 if (fields[i]->is_dynamic) {899 if (fields[i]->is_dynamic)
899 event->dynamic_fields[j] = fields[i];
900 event->dynamic_fields[j]->field_pos = i;
901 event->dynamic_fields[j++] = fields[i];900 event->dynamic_fields[j++] = fields[i];
902 event->n_dynamic_fields++;
903 }
904 }901 }
902 event->n_dynamic_fields = j;
905 event->n_fields = n_fields;903 event->n_fields = n_fields;
906 out:904 out:
907 return event;905 return event;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t