diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2012-09-25 13:03:56 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2012-09-25 13:03:56 -0400 |
commit | 593d1006cdf710ab3469c0c37c184fea0bc3da97 (patch) | |
tree | e4db58440018a52089e8d6b39160f753ab10df99 /fs/debugfs | |
parent | 5217192b85480353aeeb395574e60d0db04f3676 (diff) | |
parent | 9b20aa63b8fc9a6a3b6831f4eae3621755e51211 (diff) |
Merge remote-tracking branch 'tip/core/rcu' into next.2012.09.25b
Resolved conflict in kernel/sched/core.c using Peter Zijlstra's
approach from https://lkml.org/lkml/2012/9/5/585.
Diffstat (limited to 'fs/debugfs')
-rw-r--r-- | fs/debugfs/file.c | 76 |
1 files changed, 27 insertions, 49 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 2340f6978d6e..c5ca6ae5a30c 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -526,73 +526,51 @@ struct array_data { | |||
526 | u32 elements; | 526 | u32 elements; |
527 | }; | 527 | }; |
528 | 528 | ||
529 | static int u32_array_open(struct inode *inode, struct file *file) | 529 | static size_t u32_format_array(char *buf, size_t bufsize, |
530 | { | 530 | u32 *array, int array_size) |
531 | file->private_data = NULL; | ||
532 | return nonseekable_open(inode, file); | ||
533 | } | ||
534 | |||
535 | static size_t format_array(char *buf, size_t bufsize, const char *fmt, | ||
536 | u32 *array, u32 array_size) | ||
537 | { | 531 | { |
538 | size_t ret = 0; | 532 | size_t ret = 0; |
539 | u32 i; | ||
540 | 533 | ||
541 | for (i = 0; i < array_size; i++) { | 534 | while (--array_size >= 0) { |
542 | size_t len; | 535 | size_t len; |
536 | char term = array_size ? ' ' : '\n'; | ||
543 | 537 | ||
544 | len = snprintf(buf, bufsize, fmt, array[i]); | 538 | len = snprintf(buf, bufsize, "%u%c", *array++, term); |
545 | len++; /* ' ' or '\n' */ | ||
546 | ret += len; | 539 | ret += len; |
547 | 540 | ||
548 | if (buf) { | 541 | buf += len; |
549 | buf += len; | 542 | bufsize -= len; |
550 | bufsize -= len; | ||
551 | buf[-1] = (i == array_size-1) ? '\n' : ' '; | ||
552 | } | ||
553 | } | 543 | } |
554 | |||
555 | ret++; /* \0 */ | ||
556 | if (buf) | ||
557 | *buf = '\0'; | ||
558 | |||
559 | return ret; | 544 | return ret; |
560 | } | 545 | } |
561 | 546 | ||
562 | static char *format_array_alloc(const char *fmt, u32 *array, | 547 | static int u32_array_open(struct inode *inode, struct file *file) |
563 | u32 array_size) | ||
564 | { | 548 | { |
565 | size_t len = format_array(NULL, 0, fmt, array, array_size); | 549 | struct array_data *data = inode->i_private; |
566 | char *ret; | 550 | int size, elements = data->elements; |
567 | 551 | char *buf; | |
568 | ret = kmalloc(len, GFP_KERNEL); | 552 | |
569 | if (ret == NULL) | 553 | /* |
570 | return NULL; | 554 | * Max size: |
555 | * - 10 digits + ' '/'\n' = 11 bytes per number | ||
556 | * - terminating NUL character | ||
557 | */ | ||
558 | size = elements*11; | ||
559 | buf = kmalloc(size+1, GFP_KERNEL); | ||
560 | if (!buf) | ||
561 | return -ENOMEM; | ||
562 | buf[size] = 0; | ||
563 | |||
564 | file->private_data = buf; | ||
565 | u32_format_array(buf, size, data->array, data->elements); | ||
571 | 566 | ||
572 | format_array(ret, len, fmt, array, array_size); | 567 | return nonseekable_open(inode, file); |
573 | return ret; | ||
574 | } | 568 | } |
575 | 569 | ||
576 | static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len, | 570 | static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len, |
577 | loff_t *ppos) | 571 | loff_t *ppos) |
578 | { | 572 | { |
579 | struct inode *inode = file->f_path.dentry->d_inode; | 573 | size_t size = strlen(file->private_data); |
580 | struct array_data *data = inode->i_private; | ||
581 | size_t size; | ||
582 | |||
583 | if (*ppos == 0) { | ||
584 | if (file->private_data) { | ||
585 | kfree(file->private_data); | ||
586 | file->private_data = NULL; | ||
587 | } | ||
588 | |||
589 | file->private_data = format_array_alloc("%u", data->array, | ||
590 | data->elements); | ||
591 | } | ||
592 | |||
593 | size = 0; | ||
594 | if (file->private_data) | ||
595 | size = strlen(file->private_data); | ||
596 | 574 | ||
597 | return simple_read_from_buffer(buf, len, ppos, | 575 | return simple_read_from_buffer(buf, len, ppos, |
598 | file->private_data, size); | 576 | file->private_data, size); |