Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 322985
b: refs/heads/master
c: e05e279
h: refs/heads/master
i:
  322983: 625a1f7
v: v3
  • Loading branch information
Linus Torvalds committed Sep 21, 2012
1 parent 8a66d12 commit 5151513
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 36048853c5257a7b6df346b83758ffa776a59e9f
refs/heads/master: e05e279e6fc940a2adb9d4d4bf2b814dfc286176
57 changes: 23 additions & 34 deletions trunk/fs/debugfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,55 +526,44 @@ struct array_data {
u32 elements;
};

static size_t format_array(char *buf, size_t bufsize, const char *fmt,
u32 *array, u32 array_size)
static size_t u32_format_array(char *buf, size_t bufsize,
u32 *array, int array_size)
{
size_t ret = 0;
u32 i;

for (i = 0; i < array_size; i++) {
while (--array_size >= 0) {
size_t len;
char term = array_size ? ' ' : '\n';

len = snprintf(buf, bufsize, fmt, array[i]);
len++; /* ' ' or '\n' */
len = snprintf(buf, bufsize, "%u%c", *array++, term);
ret += len;

if (buf) {
buf += len;
bufsize -= len;
buf[-1] = (i == array_size-1) ? '\n' : ' ';
}
buf += len;
bufsize -= len;
}

ret++; /* \0 */
if (buf)
*buf = '\0';

return ret;
}

static char *format_array_alloc(const char *fmt, u32 *array,
u32 array_size)
{
size_t len = format_array(NULL, 0, fmt, array, array_size);
char *ret;

ret = kmalloc(len, GFP_KERNEL);
if (ret == NULL)
return NULL;

format_array(ret, len, fmt, array, array_size);
return ret;
}

static int u32_array_open(struct inode *inode, struct file *file)
{
struct array_data *data = inode->i_private;

file->private_data = format_array_alloc("%u", data->array,
data->elements);
if (!file->private_data)
int size, elements = data->elements;
char *buf;

/*
* Max size:
* - 10 digits + ' '/'\n' = 11 bytes per number
* - terminating NUL character
*/
size = elements*11;
buf = kmalloc(size+1, GFP_KERNEL);
if (!buf)
return -ENOMEM;
buf[size] = 0;

file->private_data = buf;
u32_format_array(buf, size, data->array, data->elements);

return nonseekable_open(inode, file);
}

Expand Down

0 comments on commit 5151513

Please sign in to comment.