History

tracing: Clean up tracing_mark_write()

On gcc 4.5 the function tracing_mark_write() would give a warning of page2 being uninitialized. This is due to a bug in gcc because the logic prevents page2 from being used uninitialized, and gcc 4.6+ does not complain (correctly). Instead of adding a "unitialized" around page2, which could show a bug later on, I combined page1 and page2 into an array map_pages[]. This binds the two and the two are modified according to nr_pages (what gcc 4.5 seems to ignore). This no longer gives a warning with gcc 4.5 nor with gcc 4.6.

Steven Rostedt committed 14 years ago

Commit 6edb2a81 parent 978da301 file · +11 −13Browse files

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

Unified · Split

kernel/trace/trace.c+11−13
@@ -3875,14 +3875,14 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 3874 unmodified lines
38753875 struct print_entry *entry;
38763876 unsigned long irq_flags;
38773877 struct page *pages[2];
3878+ void *map_page[2];
38783879 int nr_pages = 1;
38793880 ssize_t written;
3880− void *page1;
3881− void *page2;
38823881 int offset;
38833882 int size;
38843883 int len;
38853884 int ret;
3885+ int i;
38863886
38873887 if (tracing_disabled)
38883888 return -EINVAL;
@@ -3921,9 +3921,8 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 32 unmodified lines
39213921 goto out;
39223922 }
39233923
3924− page1 = kmap_atomic(pages[0]);
3925− if (nr_pages == 2)
3926− page2 = kmap_atomic(pages[1]);
3924+ for (i = 0; i < nr_pages; i++)
3925+ map_page[i] = kmap_atomic(pages[i]);
39273926
39283927 local_save_flags(irq_flags);
39293928 size = sizeof(*entry) + cnt + 2; /* possible \n added */
@@ -3941,10 +3940,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 11 unmodified lines
39413940
39423941 if (nr_pages == 2) {
39433942 len = PAGE_SIZE - offset;
3944− memcpy(&entry->buf, page1 + offset, len);
3945− memcpy(&entry->buf[len], page2, cnt - len);
3943+ memcpy(&entry->buf, map_page[0] + offset, len);
3944+ memcpy(&entry->buf[len], map_page[1], cnt - len);
39463945 } else
3947− memcpy(&entry->buf, page1 + offset, cnt);
3946+ memcpy(&entry->buf, map_page[0] + offset, cnt);
39483947
39493948 if (entry->buf[cnt - 1] != '\n') {
39503949 entry->buf[cnt] = '\n';
@@ -3959,11 +3958,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 8 unmodified lines
39593958 *fpos += written;
39603959
39613960 out_unlock:
3962− if (nr_pages == 2)
3963− kunmap_atomic(page2);
3964− kunmap_atomic(page1);
3965− while (nr_pages > 0)
3966− put_page(pages[--nr_pages]);
3961+ for (i = 0; i < nr_pages; i++){
3962+ kunmap_atomic(map_page[i]);
3963+ put_page(pages[i]);
3964+ }
39673965 out:
39683966 return written;
39693967 }