powerpc/pseries: Remove kmalloc call in handling writes to lparcfg

There are only 4 valid name=value pairs for writes to
/proc/ppc64/lparcfg. Current code allocates a buffer to copy
this information in from the user. Since the longest name=value
pair will easily fit into a buffer of 64 characters, simply
put the buffer on the stack instead of allocating the buffer.

Signed-off-by: Nathan Fotenot <nfont@austin.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Nathan Fontenot and committed by
Benjamin Herrenschmidt
16c14b46 8391e42a

+12 -16
+12 -16
arch/powerpc/kernel/lparcfg.c
··· 573 573 static ssize_t lparcfg_write(struct file *file, const char __user * buf, 574 574 size_t count, loff_t * off) 575 575 { 576 - char *kbuf; 576 + int kbuf_sz = 64; 577 + char kbuf[kbuf_sz]; 577 578 char *tmp; 578 579 u64 new_entitled, *new_entitled_ptr = &new_entitled; 579 580 u8 new_weight, *new_weight_ptr = &new_weight; 580 - ssize_t retval = -ENOMEM; 581 + ssize_t retval; 581 582 582 583 if (!firmware_has_feature(FW_FEATURE_SPLPAR) || 583 584 firmware_has_feature(FW_FEATURE_ISERIES)) 584 585 return -EINVAL; 585 586 586 - kbuf = kmalloc(count, GFP_KERNEL); 587 - if (!kbuf) 588 - goto out; 587 + if (count > kbuf_sz) 588 + return -EINVAL; 589 589 590 - retval = -EFAULT; 591 590 if (copy_from_user(kbuf, buf, count)) 592 - goto out; 591 + return -EFAULT; 593 592 594 - retval = -EINVAL; 595 593 kbuf[count - 1] = '\0'; 596 594 tmp = strchr(kbuf, '='); 597 595 if (!tmp) 598 - goto out; 596 + return -EINVAL; 599 597 600 598 *tmp++ = '\0'; 601 599 ··· 601 603 char *endp; 602 604 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); 603 605 if (endp == tmp) 604 - goto out; 606 + return -EINVAL; 605 607 606 608 retval = update_ppp(new_entitled_ptr, NULL); 607 609 } else if (!strcmp(kbuf, "capacity_weight")) { 608 610 char *endp; 609 611 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); 610 612 if (endp == tmp) 611 - goto out; 613 + return -EINVAL; 612 614 613 615 retval = update_ppp(NULL, new_weight_ptr); 614 616 } else if (!strcmp(kbuf, "entitled_memory")) { 615 617 char *endp; 616 618 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); 617 619 if (endp == tmp) 618 - goto out; 620 + return -EINVAL; 619 621 620 622 retval = update_mpp(new_entitled_ptr, NULL); 621 623 } else if (!strcmp(kbuf, "entitled_memory_weight")) { 622 624 char *endp; 623 625 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); 624 626 if (endp == tmp) 625 - goto out; 627 + return -EINVAL; 626 628 627 629 retval = update_mpp(NULL, new_weight_ptr); 628 630 } else 629 - goto out; 631 + return -EINVAL; 630 632 631 633 if (retval == H_SUCCESS || retval == H_CONSTRAINED) { 632 634 retval = count; ··· 642 644 retval = -EIO; 643 645 } 644 646 645 - out: 646 - kfree(kbuf); 647 647 return retval; 648 648 } 649 649