Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
preemption_checks: avoid snprintf before checking error conditions
Browse files Browse the repository at this point in the history
snprintf can cause hangs.  Move the string processing into the function so
that the string operations only occur when necessary after the conditions
have been checked.

Signed-off-by: Christoph Lameter <cl@linux.com>
Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
Tested-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Christoph Lameter authored and sfrothwell committed Mar 19, 2014
1 parent 70cff5a commit 9a7c2c9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/smp_processor_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <linux/kallsyms.h>
#include <linux/sched.h>

notrace static unsigned int check_preemption_disabled(char *what)
notrace static unsigned int check_preemption_disabled(const char *what1,
const char *what2)
{
int this_cpu = raw_smp_processor_id();

Expand Down Expand Up @@ -38,8 +39,8 @@ notrace static unsigned int check_preemption_disabled(char *what)
if (!printk_ratelimit())
goto out_enable;

printk(KERN_ERR "BUG: using %s in preemptible [%08x] code: %s/%d\n",
what, preempt_count() - 1, current->comm, current->pid);
printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
what1, what2, preempt_count() - 1, current->comm, current->pid);

print_symbol("caller is %s\n", (long)__builtin_return_address(0));
dump_stack();
Expand All @@ -52,15 +53,12 @@ notrace static unsigned int check_preemption_disabled(char *what)

notrace unsigned int debug_smp_processor_id(void)
{
return check_preemption_disabled("smp_processor_id()");
return check_preemption_disabled("smp_processor_id","");
}
EXPORT_SYMBOL(debug_smp_processor_id);

notrace void __this_cpu_preempt_check(const char *op)
{
char text[40];

snprintf(text, sizeof(text), "__this_cpu_%s()", op);
check_preemption_disabled(text);
check_preemption_disabled("__this_cpu_", op);
}
EXPORT_SYMBOL(__this_cpu_preempt_check);

0 comments on commit 9a7c2c9

Please sign in to comment.