/* kstrndup - allocate space for and copy an existing string @s: the string to duplicate @max: read at most @max chars from @s @gfp: the GFP mask used in the kmalloc() call when allocating memory  */
char* kstrndup(const char *s, size_t max, gfp_t gfp)
/* kstrndup - allocate space for and copy an existing string @s: the string to duplicate @max: read at most @max chars from @s @gfp: the GFP mask used in the kmalloc() call when allocating memory  */
char* kstrndup(const char *s, size_t max, gfp_t gfp)
{
	size_t len;
	char *buf;
	if (!s)
		return NULL;
	len = strnlen(s, max);
	buf = kmalloc_track_caller(len+1, gfp);
	if (buf) {
		memcpy(buf, s, len);
		buf[len] = '\0';
	}
	return buf;
}