diff options
author | Mike Frysinger <vapier.adi@gmail.com> | 2008-07-14 04:34:05 -0400 |
---|---|---|
committer | Bryan Wu <cooloney@kernel.org> | 2008-07-14 04:34:05 -0400 |
commit | 260d5d3517c67c5b68b4e28c5d3e1e3b73976a90 (patch) | |
tree | 5ebf3e3bc00a2b4116442ac974b08507d9592966 /arch/blackfin | |
parent | 1f2d18690f4390ac4cf75648a5bc18fc07b3aef6 (diff) |
Blackfin arch: Fix bug - do not overflow the buffer given to us which tends to happen when CONFIG_L1_MAX_PIECE is increased past its default
Singed-off-by: Mike Frysinger <vapier.adi@gmail.com>
Signed-off-by: Bryan Wu <cooloney@kernel.org>
Diffstat (limited to 'arch/blackfin')
-rw-r--r-- | arch/blackfin/mm/blackfin_sram.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c index 3246f91c7baa..8f6fdc245330 100644 --- a/arch/blackfin/mm/blackfin_sram.c +++ b/arch/blackfin/mm/blackfin_sram.c | |||
@@ -549,13 +549,16 @@ EXPORT_SYMBOL(sram_alloc_with_lsl); | |||
549 | /* Once we get a real allocator, we'll throw all of this away. | 549 | /* Once we get a real allocator, we'll throw all of this away. |
550 | * Until then, we need some sort of visibility into the L1 alloc. | 550 | * Until then, we need some sort of visibility into the L1 alloc. |
551 | */ | 551 | */ |
552 | static void _l1sram_proc_read(char *buf, int *len, const char *desc, | 552 | /* Need to keep line of output the same. Currently, that is 44 bytes |
553 | * (including newline). | ||
554 | */ | ||
555 | static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc, | ||
553 | struct l1_sram_piece *pfree, const int array_size) | 556 | struct l1_sram_piece *pfree, const int array_size) |
554 | { | 557 | { |
555 | int i; | 558 | int i; |
556 | 559 | ||
557 | *len += sprintf(&buf[*len], "--- L1 %-14s Size PID State\n", desc); | 560 | *len += sprintf(&buf[*len], "--- L1 %-14s Size PID State \n", desc); |
558 | for (i = 0; i < array_size; ++i) { | 561 | for (i = 0; i < array_size && *len < count; ++i) { |
559 | const char *alloc_type; | 562 | const char *alloc_type; |
560 | switch (pfree[i].flag) { | 563 | switch (pfree[i].flag) { |
561 | case SRAM_SLT_NULL: alloc_type = "NULL"; break; | 564 | case SRAM_SLT_NULL: alloc_type = "NULL"; break; |
@@ -563,31 +566,42 @@ static void _l1sram_proc_read(char *buf, int *len, const char *desc, | |||
563 | case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break; | 566 | case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break; |
564 | default: alloc_type = "????"; break; | 567 | default: alloc_type = "????"; break; |
565 | } | 568 | } |
566 | *len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n", | 569 | /* if we've got a lot of space to cover, omit things */ |
570 | if ((PAGE_SIZE - 1024) < (CONFIG_L1_MAX_PIECE + 1) * 4 * 44 && | ||
571 | pfree[i].size == 0) | ||
572 | continue; | ||
573 | *len += sprintf(&buf[*len], "%p-%p %8i %5i %-10s\n", | ||
567 | pfree[i].paddr, pfree[i].paddr + pfree[i].size, | 574 | pfree[i].paddr, pfree[i].paddr + pfree[i].size, |
568 | pfree[i].size, pfree[i].pid, alloc_type); | 575 | pfree[i].size, pfree[i].pid, alloc_type); |
569 | } | 576 | } |
577 | return (i != array_size); | ||
570 | } | 578 | } |
571 | static int l1sram_proc_read(char *buf, char **start, off_t offset, int count, | 579 | static int l1sram_proc_read(char *buf, char **start, off_t offset, int count, |
572 | int *eof, void *data) | 580 | int *eof, void *data) |
573 | { | 581 | { |
574 | int len = 0; | 582 | int len = 0; |
575 | 583 | ||
576 | _l1sram_proc_read(buf, &len, "Scratchpad", | 584 | if (_l1sram_proc_read(buf, &len, count, "Scratchpad", |
577 | l1_ssram, ARRAY_SIZE(l1_ssram)); | 585 | l1_ssram, ARRAY_SIZE(l1_ssram))) |
586 | goto not_done; | ||
578 | #if L1_DATA_A_LENGTH != 0 | 587 | #if L1_DATA_A_LENGTH != 0 |
579 | _l1sram_proc_read(buf, &len, "Data A", | 588 | if (_l1sram_proc_read(buf, &len, count, "Data A", |
580 | l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram)); | 589 | l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram))) |
590 | goto not_done; | ||
581 | #endif | 591 | #endif |
582 | #if L1_DATA_B_LENGTH != 0 | 592 | #if L1_DATA_B_LENGTH != 0 |
583 | _l1sram_proc_read(buf, &len, "Data B", | 593 | if (_l1sram_proc_read(buf, &len, count, "Data B", |
584 | l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram)); | 594 | l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram))) |
595 | goto not_done; | ||
585 | #endif | 596 | #endif |
586 | #if L1_CODE_LENGTH != 0 | 597 | #if L1_CODE_LENGTH != 0 |
587 | _l1sram_proc_read(buf, &len, "Instruction", | 598 | if (_l1sram_proc_read(buf, &len, count, "Instruction", |
588 | l1_inst_sram, ARRAY_SIZE(l1_inst_sram)); | 599 | l1_inst_sram, ARRAY_SIZE(l1_inst_sram))) |
600 | goto not_done; | ||
589 | #endif | 601 | #endif |
590 | 602 | ||
603 | *eof = 1; | ||
604 | not_done: | ||
591 | return len; | 605 | return len; |
592 | } | 606 | } |
593 | 607 | ||