Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16c14b46 authored by Nathan Fontenot's avatar Nathan Fontenot Committed by Benjamin Herrenschmidt
Browse files

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: default avatarNathan Fotenot <nfont@austin.ibm.com>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 8391e42a
Loading
Loading
Loading
Loading
+12 −16
Original line number Original line Diff line number Diff line
@@ -573,29 +573,27 @@ static ssize_t update_mpp(u64 *entitlement, u8 *weight)
static ssize_t lparcfg_write(struct file *file, const char __user * buf,
static ssize_t lparcfg_write(struct file *file, const char __user * buf,
			     size_t count, loff_t * off)
			     size_t count, loff_t * off)
{
{
	char *kbuf;
	int kbuf_sz = 64;
	char kbuf[kbuf_sz];
	char *tmp;
	char *tmp;
	u64 new_entitled, *new_entitled_ptr = &new_entitled;
	u64 new_entitled, *new_entitled_ptr = &new_entitled;
	u8 new_weight, *new_weight_ptr = &new_weight;
	u8 new_weight, *new_weight_ptr = &new_weight;
	ssize_t retval = -ENOMEM;
	ssize_t retval;


	if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
	if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
			firmware_has_feature(FW_FEATURE_ISERIES))
			firmware_has_feature(FW_FEATURE_ISERIES))
		return -EINVAL;
		return -EINVAL;


	kbuf = kmalloc(count, GFP_KERNEL);
	if (count > kbuf_sz)
	if (!kbuf)
		return -EINVAL;
		goto out;


	retval = -EFAULT;
	if (copy_from_user(kbuf, buf, count))
	if (copy_from_user(kbuf, buf, count))
		goto out;
		return -EFAULT;


	retval = -EINVAL;
	kbuf[count - 1] = '\0';
	kbuf[count - 1] = '\0';
	tmp = strchr(kbuf, '=');
	tmp = strchr(kbuf, '=');
	if (!tmp)
	if (!tmp)
		goto out;
		return -EINVAL;


	*tmp++ = '\0';
	*tmp++ = '\0';


@@ -603,32 +601,32 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,
		char *endp;
		char *endp;
		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
		if (endp == tmp)
		if (endp == tmp)
			goto out;
			return -EINVAL;


		retval = update_ppp(new_entitled_ptr, NULL);
		retval = update_ppp(new_entitled_ptr, NULL);
	} else if (!strcmp(kbuf, "capacity_weight")) {
	} else if (!strcmp(kbuf, "capacity_weight")) {
		char *endp;
		char *endp;
		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
		if (endp == tmp)
		if (endp == tmp)
			goto out;
			return -EINVAL;


		retval = update_ppp(NULL, new_weight_ptr);
		retval = update_ppp(NULL, new_weight_ptr);
	} else if (!strcmp(kbuf, "entitled_memory")) {
	} else if (!strcmp(kbuf, "entitled_memory")) {
		char *endp;
		char *endp;
		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
		if (endp == tmp)
		if (endp == tmp)
			goto out;
			return -EINVAL;


		retval = update_mpp(new_entitled_ptr, NULL);
		retval = update_mpp(new_entitled_ptr, NULL);
	} else if (!strcmp(kbuf, "entitled_memory_weight")) {
	} else if (!strcmp(kbuf, "entitled_memory_weight")) {
		char *endp;
		char *endp;
		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
		if (endp == tmp)
		if (endp == tmp)
			goto out;
			return -EINVAL;


		retval = update_mpp(NULL, new_weight_ptr);
		retval = update_mpp(NULL, new_weight_ptr);
	} else
	} else
		goto out;
		return -EINVAL;


	if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
	if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
		retval = count;
		retval = count;
@@ -644,8 +642,6 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,
		retval = -EIO;
		retval = -EIO;
	}
	}


out:
	kfree(kbuf);
	return retval;
	return retval;
}
}