aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorNathan Fontenot <nfont@austin.ibm.com>2008-07-23 15:10:46 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2008-07-25 01:44:45 -0400
commit16c14b4621c7b6fc4611abf1f86cd78cdb1b2b03 (patch)
tree3e6ce7b3b7b040667573b019f60227c2f86c0762 /arch
parent8391e42a5c1f3d757faa5e7f46a4a68f9aa6cb12 (diff)
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>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/kernel/lparcfg.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/arch/powerpc/kernel/lparcfg.c b/arch/powerpc/kernel/lparcfg.c
index 64381a204a58..9f856a0c3e38 100644
--- a/arch/powerpc/kernel/lparcfg.c
+++ b/arch/powerpc/kernel/lparcfg.c
@@ -573,29 +573,27 @@ static ssize_t update_mpp(u64 *entitlement, u8 *weight)
573static ssize_t lparcfg_write(struct file *file, const char __user * buf, 573static ssize_t lparcfg_write(struct file *file, const char __user * buf,
574 size_t count, loff_t * off) 574 size_t count, loff_t * off)
575{ 575{
576 char *kbuf; 576 int kbuf_sz = 64;
577 char kbuf[kbuf_sz];
577 char *tmp; 578 char *tmp;
578 u64 new_entitled, *new_entitled_ptr = &new_entitled; 579 u64 new_entitled, *new_entitled_ptr = &new_entitled;
579 u8 new_weight, *new_weight_ptr = &new_weight; 580 u8 new_weight, *new_weight_ptr = &new_weight;
580 ssize_t retval = -ENOMEM; 581 ssize_t retval;
581 582
582 if (!firmware_has_feature(FW_FEATURE_SPLPAR) || 583 if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
583 firmware_has_feature(FW_FEATURE_ISERIES)) 584 firmware_has_feature(FW_FEATURE_ISERIES))
584 return -EINVAL; 585 return -EINVAL;
585 586
586 kbuf = kmalloc(count, GFP_KERNEL); 587 if (count > kbuf_sz)
587 if (!kbuf) 588 return -EINVAL;
588 goto out;
589 589
590 retval = -EFAULT;
591 if (copy_from_user(kbuf, buf, count)) 590 if (copy_from_user(kbuf, buf, count))
592 goto out; 591 return -EFAULT;
593 592
594 retval = -EINVAL;
595 kbuf[count - 1] = '\0'; 593 kbuf[count - 1] = '\0';
596 tmp = strchr(kbuf, '='); 594 tmp = strchr(kbuf, '=');
597 if (!tmp) 595 if (!tmp)
598 goto out; 596 return -EINVAL;
599 597
600 *tmp++ = '\0'; 598 *tmp++ = '\0';
601 599
@@ -603,32 +601,32 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,
603 char *endp; 601 char *endp;
604 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); 602 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
605 if (endp == tmp) 603 if (endp == tmp)
606 goto out; 604 return -EINVAL;
607 605
608 retval = update_ppp(new_entitled_ptr, NULL); 606 retval = update_ppp(new_entitled_ptr, NULL);
609 } else if (!strcmp(kbuf, "capacity_weight")) { 607 } else if (!strcmp(kbuf, "capacity_weight")) {
610 char *endp; 608 char *endp;
611 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); 609 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
612 if (endp == tmp) 610 if (endp == tmp)
613 goto out; 611 return -EINVAL;
614 612
615 retval = update_ppp(NULL, new_weight_ptr); 613 retval = update_ppp(NULL, new_weight_ptr);
616 } else if (!strcmp(kbuf, "entitled_memory")) { 614 } else if (!strcmp(kbuf, "entitled_memory")) {
617 char *endp; 615 char *endp;
618 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); 616 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
619 if (endp == tmp) 617 if (endp == tmp)
620 goto out; 618 return -EINVAL;
621 619
622 retval = update_mpp(new_entitled_ptr, NULL); 620 retval = update_mpp(new_entitled_ptr, NULL);
623 } else if (!strcmp(kbuf, "entitled_memory_weight")) { 621 } else if (!strcmp(kbuf, "entitled_memory_weight")) {
624 char *endp; 622 char *endp;
625 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); 623 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
626 if (endp == tmp) 624 if (endp == tmp)
627 goto out; 625 return -EINVAL;
628 626
629 retval = update_mpp(NULL, new_weight_ptr); 627 retval = update_mpp(NULL, new_weight_ptr);
630 } else 628 } else
631 goto out; 629 return -EINVAL;
632 630
633 if (retval == H_SUCCESS || retval == H_CONSTRAINED) { 631 if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
634 retval = count; 632 retval = count;
@@ -644,8 +642,6 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,
644 retval = -EIO; 642 retval = -EIO;
645 } 643 }
646 644
647out:
648 kfree(kbuf);
649 return retval; 645 return retval;
650} 646}
651 647