diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 1d4bc493b2f4..66bc712f590c 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -91,10 +91,23 @@ static ssize_t profiling_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { + static DEFINE_MUTEX(lock); int ret; - if (prof_on) - return -EEXIST; + /* + * We need serialization, for profile_setup() initializes prof_on + * value. Also, use killable wait in case memory allocation from + * profile_init() triggered the OOM killer and chose current thread + * blocked here. + */ + if (mutex_lock_killable(&lock)) + return -EINTR; + + if (prof_on) { + count = -EEXIST; + goto out; + } + /* * This eventually calls into get_option() which * has a ton of callers and is not const. It is @@ -102,11 +115,15 @@ static ssize_t profiling_store(struct kobject *kobj, */ profile_setup((char *)buf); ret = profile_init(); - if (ret) - return ret; + if (ret) { + count = ret; + goto out; + } ret = create_proc_profile(); if (ret) - return ret; + count = ret; +out: + mutex_unlock(&lock); return count; } KERNEL_ATTR_RW(profiling); diff --git a/kernel/profile.c b/kernel/profile.c index 8a77769bc4b4..7575747e2ac6 100644 --- a/kernel/profile.c +++ b/kernel/profile.c @@ -114,11 +114,9 @@ int __ref profile_init(void) buffer_bytes = prof_len*sizeof(atomic_t); - if (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL)) + if (!zalloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL)) return -ENOMEM; - cpumask_copy(prof_cpu_mask, cpu_possible_mask); - prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL|__GFP_NOWARN); if (prof_buffer) return 0; @@ -481,6 +479,8 @@ int __ref create_proc_profile(void) goto err_state_prep; online_state = err; err = 0; +#else + cpumask_copy(prof_cpu_mask, cpu_possible_mask); #endif entry = proc_create("profile", S_IWUSR | S_IRUGO, NULL, &profile_proc_ops);