Skip to contentSkip to conversation

Cleanup use of strlen() to check for empty string

PATCH In review Jacob Gorm Hansen 2 participants 3 messages Oct 4, 2005 – Oct 5, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleanup use of strlen() to check for empty string

I came across checks for strlen(s)==0 a few places in drivers/xen. Here is a patch to fix that.

Jacob
--
Save time and bandwidth with EDelta: http://www.diku.dk/~jacobg/edelta/

linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
@@ -226,7 +226,7 @@
 				 dev->nodename);
 		goto free_be;
 	}
-	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
+	if (*frontend=='\0' || !xenbus_exists(frontend, "")) {
 		/* If we can't get a frontend path and a frontend-id,
 		 * then our bus-id is no longer valid and we need to
 		 * destroy the backend device.
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
@@ -537,7 +537,7 @@
 			    NULL);
 	if (XENBUS_EXIST_ERR(err))
 		goto out;
-	if (backend && strlen(backend) == 0) {
+	if (backend && *backend =='\0') {
 		err = -ENOENT;
 		goto out;
 	}
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c
@@ -160,7 +160,7 @@
 				 dev->nodename);
 		goto free_be;
 	}
-	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
+	if (*frontend=='\0' || !xenbus_exists(frontend, "")) {
 		/* If we can't get a frontend path and a frontend-id,
 		 * then our bus-id is no longer valid and we need to
 		 * destroy the backend device.
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
@@ -230,7 +230,7 @@
 				 dev->nodename);
 		goto free_be;
 	}
-	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
+	if (*frontend=='\0' || !xenbus_exists(frontend, "")) {
 		/* If we can't get a frontend path and a frontend-id,
 		 * then our bus-id is no longer valid and we need to
 		 * destroy the backend device.
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
@@ -1090,7 +1090,7 @@
 			    NULL);
 	if (XENBUS_EXIST_ERR(err))
 		goto out;
-	if (backend && strlen(backend) == 0) {
+	if (backend && *backend=='\0') {
 		err = -ENOENT;
 		goto out;
 	}
linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c
@@ -209,7 +209,7 @@
 				 dev->nodename);
 		goto free_be;
 	}
-	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
+	if (*frontend=='\0' || !xenbus_exists(frontend, "")) {
 		/* If we can't get a frontend path and a frontend-id,
 		 * then our bus-id is no longer valid and we need to
 		 * destroy the backend device.
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
@@ -314,7 +314,7 @@
 			    NULL);
 	if (XENBUS_EXIST_ERR(err))
 		goto out;
-	if (backend && strlen(backend) == 0) {
+	if (backend && *backend=='\0') {
 		err = -ENOENT;
 		goto out;
 	}
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
@@ -130,7 +130,7 @@
 			    NULL);
 	if (err)
 		return err;
-	if (strlen(frontend) == 0)
+	if (*frontend=='\0')
 		err = -ERANGE;
 
 	if (!err && !xenbus_exists(frontend, ""))
linux-2.6-xen-sparse/include/asm-xen/xenbus.h +1 -1
diff -r 00037ba13f0b linux-2.6-xen-sparse/include/asm-xen/xenbus.h
@@ -129,7 +129,7 @@
 void xenbus_resume(void);
 
 #define XENBUS_IS_ERR_READ(str) ({			\
-	if (!IS_ERR(str) && strlen(str) == 0) {		\
+	if (!IS_ERR(str) && *str=='\0') {		\
 		kfree(str);				\
 		str = ERR_PTR(-ERANGE);			\
 	}						\

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 2 lines · Jacob Gorm Hansen

I came across checks for strlen(s)==0 a few places in drivers/xen. Here is a patch to fix that.

Isn't your patch exactly equivalent? None of that code is time critical enough that a call to strlen matters.

-- Keir

#2 lore raw
Quoted 8 lines · Keir Fraser
Quoted 2 lines · Jacob Gorm Hansen

I came across checks for strlen(s)==0 a few places in drivers/xen. Here is a patch to fix that.

Isn't your patch exactly equivalent? None of that code is time critical enough that a call to strlen matters.

It's just gross (looping over the entire length of a string just to see if the first char is empty) that's all. Apply if you will.

Jacob