aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_util.c
diff options
context:
space:
mode:
authorTijl Coosemans <tijl@FreeBSD.org>2017-10-15 16:03:45 +0000
committerTijl Coosemans <tijl@FreeBSD.org>2017-10-15 16:03:45 +0000
commitf3792e07f663c24047fa48e209633abf833908d1 (patch)
treea075020738fd9ca21e56e7cb1d228327a17c9b3b /sys/compat/linux/linux_util.c
parent4ffeccf1e84e539920b81b2567a8d1df54c2c886 (diff)
Use sizeof instead of strlen on string constants. The compiler doesn't
optimise the strlen calls away with -ffreestanding.
Notes
Notes: svn path=/head/; revision=324628
Diffstat (limited to 'sys/compat/linux/linux_util.c')
-rw-r--r--sys/compat/linux/linux_util.c15
1 files 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;