Improving kernel string handling
Improving kernel string handling
Posted May 8, 2015 18:49 UTC (Fri) by cesarb (subscriber, #6266)In reply to: Improving kernel string handling by reubenhwk
Parent article: Improving kernel string handling
long sys_foo(...)
{
long ret = 0;
/* ... */
ret = strscpy(dest, src, sizeof_dest);
if (ret < 0)
goto err;
/* ret now has the string length, saving a strlen() */
/* ... */
return ret;
err:
/* ...cleanup... */
return ret;
}
That is, in case of error, the value can be returned directly to userspace. That is a common design pattern in the kernel: if a function you called returns a negative value (indicating failure), abort what you were doing and pass that value up the stack.