Commit 542401d9 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Linus Torvalds

CRIS: check for memory allocation

Add checking for allocated memory.  Indents and spaces are added to be
familiar with the kernel coding style.
Signed-off-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
Acked-by: default avatarMikael Starvik <starvik@axis.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c65808ef
...@@ -17,28 +17,36 @@ cris_profile_sample(struct pt_regs* regs) ...@@ -17,28 +17,36 @@ cris_profile_sample(struct pt_regs* regs)
{ {
if (!prof_running) if (!prof_running)
return; return;
if (user_mode(regs)) if (user_mode(regs))
*(unsigned int*)sample_buffer_pos = current->pid; *(unsigned int*)sample_buffer_pos = current->pid;
else else
*(unsigned int*)sample_buffer_pos = 0; *(unsigned int*)sample_buffer_pos = 0;
*(unsigned int*)(sample_buffer_pos + 4) = instruction_pointer(regs); *(unsigned int*)(sample_buffer_pos + 4) = instruction_pointer(regs);
sample_buffer_pos += 8; sample_buffer_pos += 8;
if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE) if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE)
sample_buffer_pos = sample_buffer; sample_buffer_pos = sample_buffer;
} }
static ssize_t static ssize_t
read_cris_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos) read_cris_profile(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{ {
unsigned long p = *ppos; unsigned long p = *ppos;
if (p > SAMPLE_BUFFER_SIZE) if (p > SAMPLE_BUFFER_SIZE)
return 0; return 0;
if (p + count > SAMPLE_BUFFER_SIZE) if (p + count > SAMPLE_BUFFER_SIZE)
count = SAMPLE_BUFFER_SIZE - p; count = SAMPLE_BUFFER_SIZE - p;
if (copy_to_user(buf, sample_buffer + p,count)) if (copy_to_user(buf, sample_buffer + p,count))
return -EFAULT; return -EFAULT;
memset(sample_buffer + p, 0, count); memset(sample_buffer + p, 0, count);
*ppos += count; *ppos += count;
return count; return count;
} }
...@@ -59,14 +67,21 @@ static int ...@@ -59,14 +67,21 @@ static int
__init init_cris_profile(void) __init init_cris_profile(void)
{ {
struct proc_dir_entry *entry; struct proc_dir_entry *entry;
sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL); sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
if (!sample_buffer) {
return -ENOMEM;
}
sample_buffer_pos = sample_buffer; sample_buffer_pos = sample_buffer;
entry = create_proc_entry("system_profile", S_IWUSR | S_IRUGO, NULL); entry = create_proc_entry("system_profile", S_IWUSR | S_IRUGO, NULL);
if (entry) { if (entry) {
entry->proc_fops = &cris_proc_profile_operations; entry->proc_fops = &cris_proc_profile_operations;
entry->size = SAMPLE_BUFFER_SIZE; entry->size = SAMPLE_BUFFER_SIZE;
} }
prof_running = 1; prof_running = 1;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment