Date: Sun, 15 Oct 2017 16:03:45 +0000 (UTC) From: Tijl Coosemans <tijl@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324628 - head/sys/compat/linux Message-ID: <201710151603.v9FG3jUH090991@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201710151603.v9FG3jUH090991>