/* strndup_user - duplicate an existing string from user space @s: The string to duplicate  */
char* strndup_user(const char __user *s, long n)
/* strndup_user - duplicate an existing string from user space @s: The string to duplicate  */
char* strndup_user(const char __user *s, long n)
{
	char *p;
	long length;
	length = strnlen_user(s, n);
	if (!length)
		return ERR_PTR(-EFAULT);
	if (length > n)
		return ERR_PTR(-EINVAL);
	p = kmalloc(length, GFP_KERNEL);
	if (!p)
		return ERR_PTR(-ENOMEM);
	if (copy_from_user(p, s, length)) {
		kfree(p);
		return ERR_PTR(-EFAULT);
	}
	p[length - 1] = '\0';
	return p;
}