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
3875 struct print_entry *entry;3875 struct print_entry *entry;
3876 unsigned long irq_flags;3876 unsigned long irq_flags;
3877 struct page *pages[2];3877 struct page *pages[2];
3878 void *map_page[2];
3878 int nr_pages = 1;3879 int nr_pages = 1;
3879 ssize_t written;3880 ssize_t written;
3880 void *page1;
3881 void *page2;
3882 int offset;3881 int offset;
3883 int size;3882 int size;
3884 int len;3883 int len;
3885 int ret;3884 int ret;
3885 int i;
3886 3886
3887 if (tracing_disabled)3887 if (tracing_disabled)
3888 return -EINVAL;3888 return -EINVAL;
@@ -3921,9 +3921,8 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 32 unmodified lines
3921 goto out;3921 goto out;
3922 }3922 }
3923 3923
3924 page1 = kmap_atomic(pages[0]);3924 for (i = 0; i < nr_pages; i++)
3925 if (nr_pages == 2)3925 map_page[i] = kmap_atomic(pages[i]);
3926 page2 = kmap_atomic(pages[1]);
3927 3926
3928 local_save_flags(irq_flags);3927 local_save_flags(irq_flags);
3929 size = sizeof(*entry) + cnt + 2; /* possible \n added */3928 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
3941 3940
3942 if (nr_pages == 2) {3941 if (nr_pages == 2) {
3943 len = PAGE_SIZE - offset;3942 len = PAGE_SIZE - offset;
3944 memcpy(&entry->buf, page1 + offset, len);3943 memcpy(&entry->buf, map_page[0] + offset, len);
3945 memcpy(&entry->buf[len], page2, cnt - len);3944 memcpy(&entry->buf[len], map_page[1], cnt - len);
3946 } else3945 } else
3947 memcpy(&entry->buf, page1 + offset, cnt);3946 memcpy(&entry->buf, map_page[0] + offset, cnt);
3948 3947
3949 if (entry->buf[cnt - 1] != '\n') {3948 if (entry->buf[cnt - 1] != '\n') {
3950 entry->buf[cnt] = '\n';3949 entry->buf[cnt] = '\n';
@@ -3959,11 +3958,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, · 8 unmodified lines
3959 *fpos += written;3958 *fpos += written;
3960 3959
3961 out_unlock:3960 out_unlock:
3962 if (nr_pages == 2)3961 for (i = 0; i < nr_pages; i++){
3963 kunmap_atomic(page2);3962 kunmap_atomic(map_page[i]);
3964 kunmap_atomic(page1);3963 put_page(pages[i]);
3965 while (nr_pages > 0)3964 }
3966 put_page(pages[--nr_pages]);
3967 out:3965 out:
3968 return written;3966 return written;
3969}3967}