svn commit: r324628 - head/sys/compat/linux
Tijl Coosemans
tijl at FreeBSD.org
Sun Oct 15 16:03:46 UTC 2017
Author: tijl
Date: Sun Oct 15 16:03:45 2017
New Revision: 324628
URL: https://svnweb.freebsd.org/changeset/base/324628
Log:
Use sizeof instead of strlen on string constants. The compiler doesn't
optimise the strlen calls away with -ffreestanding.
Modified:
head/sys/compat/linux/linux_util.c
Modified: head/sys/compat/linux/linux_util.c
==============================================================================
--- head/sys/compat/linux/linux_util.c Sun Oct 15 14:03:53 2017 (r324627)
+++ head/sys/compat/linux/linux_util.c Sun Oct 15 16:03:45 2017 (r324628)
@@ -128,32 +128,31 @@ linux_driver_get_major_minor(const char *node, int *ma
{
struct device_element *de;
unsigned long devno;
+ size_t sz;
if (node == NULL || major == NULL || minor == NULL)
return 1;
- if (strlen(node) > strlen("pts/") &&
- strncmp(node, "pts/", strlen("pts/")) == 0) {
+ sz = sizeof("pts/") - 1;
+ if (strncmp(node, "pts/", sz) == 0 && node[sz] != '\0') {
/*
* Linux checks major and minors of the slave device
* to make sure it's a pty device, so let's make him
* believe it is.
*/
- devno = strtoul(node + strlen("pts/"), NULL, 10);
+ devno = strtoul(node + sz, NULL, 10);
*major = 136 + (devno / 256);
*minor = devno % 256;
-
return (0);
}
- if ((strlen(node) > strlen("drm/") &&
- strncmp(node, "drm/", strlen("drm/")) == 0) ) {
- devno = strtoul(node + strlen("drm/"), NULL, 10);
+ sz = sizeof("drm/") - 1;
+ if (strncmp(node, "drm/", sz) == 0 && node[sz] != '\0') {
+ devno = strtoul(node + sz, NULL, 10);
*major = 226 + (devno / 256);
*minor = devno % 256;
return (0);
}
-
TAILQ_FOREACH(de, &devices, list) {
if (strcmp(node, de->entry.bsd_device_name) == 0) {
More information about the svn-src-all
mailing list