On Mon, Jun 23, 2025 at 6:48 AM Viktor Malik <vmalik@xxxxxxxxxx> wrote: > > +/* Kfuncs for string operations. Pls use normal kernel style comments instead of old networking. That's what we prefer for all new code. > + * > + * Since strings are not necessarily %NUL-terminated, we cannot directly call > + * in-kernel implementations. Instead, we open-code the implementations using > + * __get_kernel_nofault instead of plain dereference to make them safe. > + */ > + > +/** > + * bpf_strcmp - Compare two strings > + * @s1__ign: One string > + * @s2__ign: Another string > + * > + * Return: > + * * %0 - Strings are equal > + * * %-1 - @s1__ign is smaller > + * * %1 - @s2__ign is smaller Here -1 and 1 return values are probably ok, since they match traditional strcmp. > + * * %-EFAULT - Cannot read one of the strings > + * * %-E2BIG - One of strings is too large > + * * %-ERANGE - One of strings is outside of kernel address space > + */ ... > +/** > + * bpf_strnchr - Find a character in a length limited string > + * @s__ign: The string to be searched > + * @count: The number of characters to be searched > + * @c: The character to search for > + * > + * Note that the %NUL-terminator is considered part of the string, and can > + * be searched for. > + * > + * Return: > + * * >=0 - Index of the first occurrence of @c within @s__ign > + * * %-1 - @c not found in the first @count characters of @s__ign > + * * %-EFAULT - Cannot read @s__ign > + * * %-E2BIG - @s__ign is too large > + * * %-ERANGE - @s__ign is outside of kernel address space > + */ but here and in a few other places returning -1 is effectively returning -EPERM for "not found". Which is odd. Maybe let's return -ENOENT instead ?