diff options
author | Jonathan Corbet <corbet@lwn.net> | 2009-08-06 15:35:44 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2009-10-14 09:31:10 -0400 |
commit | 1a6deaea3584fd7af1cad492b1fe0867060b45db (patch) | |
tree | 83e6f420efe2622c76fba4becd74dd9087cccf59 /kernel | |
parent | e6fe07a014c7a3466dcd1a387a9ac04d84c2703c (diff) |
pm_qos: clean up racy global "name" variable
"name" is a poor name for a file-global variable. It was used in three
different functions, with no mutual exclusion. But it's just a tiny,
temporary string; let's just move it onto the stack in the functions that
need it. Also use snprintf() just in case.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
LKML-Reference: <20091010153349.113570550@linutronix.de>
Acked-by: Mark Gross <mgross@linux.intel.com>
Reviewed-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/pm_qos_params.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c index d96b83ed21cb..3db49b9ca374 100644 --- a/kernel/pm_qos_params.c +++ b/kernel/pm_qos_params.c | |||
@@ -343,18 +343,18 @@ int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) | |||
343 | } | 343 | } |
344 | EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); | 344 | EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); |
345 | 345 | ||
346 | #define PID_NAME_LEN sizeof("process_1234567890") | 346 | #define PID_NAME_LEN 32 |
347 | static char name[PID_NAME_LEN]; | ||
348 | 347 | ||
349 | static int pm_qos_power_open(struct inode *inode, struct file *filp) | 348 | static int pm_qos_power_open(struct inode *inode, struct file *filp) |
350 | { | 349 | { |
351 | int ret; | 350 | int ret; |
352 | long pm_qos_class; | 351 | long pm_qos_class; |
352 | char name[PID_NAME_LEN]; | ||
353 | 353 | ||
354 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); | 354 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); |
355 | if (pm_qos_class >= 0) { | 355 | if (pm_qos_class >= 0) { |
356 | filp->private_data = (void *)pm_qos_class; | 356 | filp->private_data = (void *)pm_qos_class; |
357 | sprintf(name, "process_%d", current->pid); | 357 | snprintf(name, PID_NAME_LEN, "process_%d", current->pid); |
358 | ret = pm_qos_add_requirement(pm_qos_class, name, | 358 | ret = pm_qos_add_requirement(pm_qos_class, name, |
359 | PM_QOS_DEFAULT_VALUE); | 359 | PM_QOS_DEFAULT_VALUE); |
360 | if (ret >= 0) | 360 | if (ret >= 0) |
@@ -366,9 +366,10 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp) | |||
366 | static int pm_qos_power_release(struct inode *inode, struct file *filp) | 366 | static int pm_qos_power_release(struct inode *inode, struct file *filp) |
367 | { | 367 | { |
368 | int pm_qos_class; | 368 | int pm_qos_class; |
369 | char name[PID_NAME_LEN]; | ||
369 | 370 | ||
370 | pm_qos_class = (long)filp->private_data; | 371 | pm_qos_class = (long)filp->private_data; |
371 | sprintf(name, "process_%d", current->pid); | 372 | snprintf(name, PID_NAME_LEN, "process_%d", current->pid); |
372 | pm_qos_remove_requirement(pm_qos_class, name); | 373 | pm_qos_remove_requirement(pm_qos_class, name); |
373 | 374 | ||
374 | return 0; | 375 | return 0; |
@@ -379,13 +380,14 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, | |||
379 | { | 380 | { |
380 | s32 value; | 381 | s32 value; |
381 | int pm_qos_class; | 382 | int pm_qos_class; |
383 | char name[PID_NAME_LEN]; | ||
382 | 384 | ||
383 | pm_qos_class = (long)filp->private_data; | 385 | pm_qos_class = (long)filp->private_data; |
384 | if (count != sizeof(s32)) | 386 | if (count != sizeof(s32)) |
385 | return -EINVAL; | 387 | return -EINVAL; |
386 | if (copy_from_user(&value, buf, sizeof(s32))) | 388 | if (copy_from_user(&value, buf, sizeof(s32))) |
387 | return -EFAULT; | 389 | return -EFAULT; |
388 | sprintf(name, "process_%d", current->pid); | 390 | snprintf(name, PID_NAME_LEN, "process_%d", current->pid); |
389 | pm_qos_update_requirement(pm_qos_class, name, value); | 391 | pm_qos_update_requirement(pm_qos_class, name, value); |
390 | 392 | ||
391 | return sizeof(s32); | 393 | return sizeof(s32); |