Skip to content

Commit

Permalink
tracing: Clean up tracing_mark_write()
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt authored and rostedt committed May 16, 2012
1 parent 978da30 commit 6edb2a8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3875,14 +3875,14 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
struct print_entry *entry;
unsigned long irq_flags;
struct page *pages[2];
void *map_page[2];
int nr_pages = 1;
ssize_t written;
void *page1;
void *page2;
int offset;
int size;
int len;
int ret;
int i;

if (tracing_disabled)
return -EINVAL;
Expand Down Expand Up @@ -3921,9 +3921,8 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
goto out;
}

page1 = kmap_atomic(pages[0]);
if (nr_pages == 2)
page2 = kmap_atomic(pages[1]);
for (i = 0; i < nr_pages; i++)
map_page[i] = kmap_atomic(pages[i]);

local_save_flags(irq_flags);
size = sizeof(*entry) + cnt + 2; /* possible \n added */
Expand All @@ -3941,10 +3940,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,

if (nr_pages == 2) {
len = PAGE_SIZE - offset;
memcpy(&entry->buf, page1 + offset, len);
memcpy(&entry->buf[len], page2, cnt - len);
memcpy(&entry->buf, map_page[0] + offset, len);
memcpy(&entry->buf[len], map_page[1], cnt - len);
} else
memcpy(&entry->buf, page1 + offset, cnt);
memcpy(&entry->buf, map_page[0] + offset, cnt);

if (entry->buf[cnt - 1] != '\n') {
entry->buf[cnt] = '\n';
Expand All @@ -3959,11 +3958,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
*fpos += written;

out_unlock:
if (nr_pages == 2)
kunmap_atomic(page2);
kunmap_atomic(page1);
while (nr_pages > 0)
put_page(pages[--nr_pages]);
for (i = 0; i < nr_pages; i++){
kunmap_atomic(map_page[i]);
put_page(pages[i]);
}
out:
return written;
}
Expand Down

0 comments on commit 6edb2a8

Please sign in to comment.