Skip to content

Commit

Permalink
Blackfin arch: Fix bug - do not overflow the buffer given to us which…
Browse files Browse the repository at this point in the history
… tends to happen when CONFIG_L1_MAX_PIECE is increased past its default

Singed-off-by: Mike Frysinger <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
  • Loading branch information
Mike Frysinger authored and Bryan Wu committed Jul 14, 2008
1 parent 1f2d186 commit 260d5d3
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions arch/blackfin/mm/blackfin_sram.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,45 +549,59 @@ EXPORT_SYMBOL(sram_alloc_with_lsl);
/* Once we get a real allocator, we'll throw all of this away.
* Until then, we need some sort of visibility into the L1 alloc.
*/
static void _l1sram_proc_read(char *buf, int *len, const char *desc,
/* Need to keep line of output the same. Currently, that is 44 bytes
* (including newline).
*/
static int _l1sram_proc_read(char *buf, int *len, int count, const char *desc,
struct l1_sram_piece *pfree, const int array_size)
{
int i;

*len += sprintf(&buf[*len], "--- L1 %-14s Size PID State\n", desc);
for (i = 0; i < array_size; ++i) {
*len += sprintf(&buf[*len], "--- L1 %-14s Size PID State \n", desc);
for (i = 0; i < array_size && *len < count; ++i) {
const char *alloc_type;
switch (pfree[i].flag) {
case SRAM_SLT_NULL: alloc_type = "NULL"; break;
case SRAM_SLT_FREE: alloc_type = "FREE"; break;
case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break;
default: alloc_type = "????"; break;
}
*len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n",
/* if we've got a lot of space to cover, omit things */
if ((PAGE_SIZE - 1024) < (CONFIG_L1_MAX_PIECE + 1) * 4 * 44 &&
pfree[i].size == 0)
continue;
*len += sprintf(&buf[*len], "%p-%p %8i %5i %-10s\n",
pfree[i].paddr, pfree[i].paddr + pfree[i].size,
pfree[i].size, pfree[i].pid, alloc_type);
}
return (i != array_size);
}
static int l1sram_proc_read(char *buf, char **start, off_t offset, int count,
int *eof, void *data)
{
int len = 0;

_l1sram_proc_read(buf, &len, "Scratchpad",
l1_ssram, ARRAY_SIZE(l1_ssram));
if (_l1sram_proc_read(buf, &len, count, "Scratchpad",
l1_ssram, ARRAY_SIZE(l1_ssram)))
goto not_done;
#if L1_DATA_A_LENGTH != 0
_l1sram_proc_read(buf, &len, "Data A",
l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram));
if (_l1sram_proc_read(buf, &len, count, "Data A",
l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram)))
goto not_done;
#endif
#if L1_DATA_B_LENGTH != 0
_l1sram_proc_read(buf, &len, "Data B",
l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram));
if (_l1sram_proc_read(buf, &len, count, "Data B",
l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram)))
goto not_done;
#endif
#if L1_CODE_LENGTH != 0
_l1sram_proc_read(buf, &len, "Instruction",
l1_inst_sram, ARRAY_SIZE(l1_inst_sram));
if (_l1sram_proc_read(buf, &len, count, "Instruction",
l1_inst_sram, ARRAY_SIZE(l1_inst_sram)))
goto not_done;
#endif

*eof = 1;
not_done:
return len;
}

Expand Down

0 comments on commit 260d5d3

Please sign in to comment.