From f3792e07f663c24047fa48e209633abf833908d1 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Sun, 15 Oct 2017 16:03:45 +0000 Subject: [PATCH] Use sizeof instead of strlen on string constants. The compiler doesn't optimise the strlen calls away with -ffreestanding. --- sys/compat/linux/linux_util.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c index 61be7b9ab87e..e829ab12343e 100644 --- a/sys/compat/linux/linux_util.c +++ b/sys/compat/linux/linux_util.c @@ -128,33 +128,32 @@ linux_driver_get_major_minor(const char *node, int *major, int *minor) { 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) { *major = de->entry.linux_major;