Skip to content

Commit 55bc7d1

Browse files
author
Fox Snowpatch
committed
1 parent a2f7734 commit 55bc7d1

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

arch/powerpc/platforms/pseries/lparcfg.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ static void read_lpar_name(struct seq_file *m)
385385
read_dt_lpar_name(m);
386386
}
387387

388-
#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
389-
390388
/*
391389
* parse_system_parameter_string()
392390
* Retrieve the potential_processors, max_entitled_capacity and friends
@@ -407,27 +405,32 @@ static void parse_system_parameter_string(struct seq_file *m)
407405
const char *local_buffer;
408406
int splpar_strlen;
409407
int idx, w_idx;
410-
char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
411-
412-
if (!workbuffer)
413-
goto out_free;
408+
size_t workbuf_size;
409+
char *workbuffer;
414410

415411
splpar_strlen = be16_to_cpu(buf->len);
416412
local_buffer = buf->val;
413+
workbuf_size = splpar_strlen + 1;
414+
415+
workbuffer = kzalloc(workbuf_size, GFP_KERNEL);
416+
if (!workbuffer)
417+
goto out_free;
417418

418419
w_idx = 0;
419420
idx = 0;
420-
while ((*local_buffer) && (idx < splpar_strlen)) {
421+
while ((idx < splpar_strlen) && local_buffer[idx]) {
421422
workbuffer[w_idx++] = local_buffer[idx++];
422-
if ((local_buffer[idx] == ',')
423+
if (idx >= splpar_strlen ||
424+
(local_buffer[idx] == ',')
423425
|| (local_buffer[idx] == '\0')) {
424426
workbuffer[w_idx] = '\0';
425427
if (w_idx) {
426428
/* avoid the empty string */
427429
seq_printf(m, "%s\n", workbuffer);
428430
}
429-
memset(workbuffer, 0, SPLPAR_MAXLENGTH);
430-
idx++; /* skip the comma */
431+
memset(workbuffer, 0, workbuf_size);
432+
if (idx < splpar_strlen)
433+
idx++; /* skip the comma */
431434
w_idx = 0;
432435
} else if (local_buffer[idx] == '=') {
433436
/* code here to replace workbuffer contents

0 commit comments

Comments
 (0)