Skip to contentSkip to conversation

xen: add error handling for xenbus_printf

PATCH In review Zhouyang Jia 3 participants 10 messages Jun 12, 2018 – Jun 19, 2018 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: add error handling for xenbus_printf

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
 drivers/xen/manage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/xen/manage.c +14 -3
index 8835065..159694d 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,
 		return;
 	}
 
-	if (sysrq_key != '\0')
-		xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+	if (sysrq_key != '\0') {
+		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+		if (err) {
+			pr_err("Error %d writing sysrq code in control/sysrq\n",
+			       err);
+			xenbus_transaction_end(xbt, 1);
+			return;
+		}
+	}
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN)
@@ -342,7 +349,11 @@ static int setup_shutdown_watcher(void)
 			continue;
 		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
 			 shutdown_handlers[idx].command);
-		xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		if (err) {
+			pr_err("Error %d writing %s\n", err, node);
+			return err;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 33 lines · Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
 drivers/xen/manage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/xen/manage.c +9 -2
index 8835065..159694d 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,
 		return;
 	}
 
-	if (sysrq_key != '\0')
-		xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+	if (sysrq_key != '\0') {
+		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+		if (err) {
+			pr_err("Error %d writing sysrq code in control/sysrq\n",
+			       err);
+			xenbus_transaction_end(xbt, 1);
+			return;
+		}
+	}
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN)

drivers/xen/manage.c static int setup_shutdown_watcher(void) · line 354

Quoted 7 lines
drivers/xen/manage.c +3 -1
@@ -342,7 +349,11 @@ static int setup_shutdown_watcher(void)
 			continue;
 		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
 			 shutdown_handlers[idx].command);
-		xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		if (err) {
+			pr_err("Error %d writing %s\n", err, node);

Adding __func__ will make it it easier trying to understand where the error is coming from. And for consistency, I'd add it to the one above as well.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Zhouyang Jia
Quoted 33 lines · Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
 drivers/xen/manage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/xen/manage.c +9 -2
index 8835065..159694d 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,
 		return;
 	}
 
-	if (sysrq_key != '\0')
-		xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+	if (sysrq_key != '\0') {
+		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+		if (err) {
+			pr_err("Error %d writing sysrq code in control/sysrq\n",
+			       err);
+			xenbus_transaction_end(xbt, 1);
+			return;
+		}
+	}
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN)

drivers/xen/manage.c static int setup_shutdown_watcher(void) · line 354

Quoted 7 lines
drivers/xen/manage.c +3 -1
@@ -342,7 +349,11 @@ static int setup_shutdown_watcher(void)
 			continue;
 		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
 			 shutdown_handlers[idx].command);
-		xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		if (err) {
+			pr_err("Error %d writing %s\n", err, node);

Adding __func__ will make it it easier trying to understand where the error is coming from. And for consistency, I'd add it to the one above as well.

-boris

#3 lore raw

Hi,

Sorry, I can't find which xenbus_device to print. So I inherit the existing style and use pr_err.

I add __func__ in v2. If it needs to be changed, please let me know.

Thanks for your kind reply.

Best,
Zhouyang

2018-06-15 5:57 GMT+08:00 Boris Ostrovsky <[email protected]>:

Quoted 50 lines · Zhouyang Jia

drivers/xen/manage.c static void sysrq_handler(struct xenbus_watch

Quoted 15 lines

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
 drivers/xen/manage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/xen/manage.c +0 -0
index 8835065..159694d 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch

*watch, const char *path,

drivers/xen/manage.c static void sysrq_handler(struct xenbus_watch *watch, const char *path,

Quoted 9 lines
drivers/xen/manage.c +4 -2
              return;
      }
 
-     if (sysrq_key != '\0')
-             xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+     if (sysrq_key != '\0') {
+             err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+             if (err) {
+                     pr_err("Error %d writing sysrq code in

control/sysrq\n",

Quoted 9 lines
drivers/xen/manage.c +5 -0
+                            err);
+                     xenbus_transaction_end(xbt, 1);
+                     return;
+             }
+     }
 
      err = xenbus_transaction_end(xbt, 0);
      if (err == -EAGAIN)

drivers/xen/manage.c static int setup_shutdown_watcher(void) · line 354

Quoted 7 lines
drivers/xen/manage.c +3 -1
@@ -342,7 +349,11 @@ static int setup_shutdown_watcher(void)
                      continue;
              snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
                       shutdown_handlers[idx].command);
-             xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+             err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+             if (err) {
+                     pr_err("Error %d writing %s\n", err, node);

Adding __func__ will make it it easier trying to understand where the error is coming from. And for consistency, I'd add it to the one above as well.

Quoted 3 lines

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

PATCH v2 1/1 xen: add error handling for xenbus_printf

In reply to Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
v1->v2:
- Add __func__.

---
 drivers/xen/manage.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/xen/manage.c +15 -3
index 8835065..c93d8ef 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,
 		return;
 	}
 
-	if (sysrq_key != '\0')
-		xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+	if (sysrq_key != '\0') {
+		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+		if (err) {
+			pr_err("%s: Error %d writing sysrq in control/sysrq\n",
+			       __func__, err);
+			xenbus_transaction_end(xbt, 1);
+			return;
+		}
+	}
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN)
@@ -342,7 +349,12 @@ static int setup_shutdown_watcher(void)
 			continue;
 		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
 			 shutdown_handlers[idx].command);
-		xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		if (err) {
+			pr_err("%s: Error %d writing %s\n", __func__,
+				err, node);
+			return err;
+		}
 	}
 
 	return 0;
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

PATCH v2 1/1 xen: add error handling for xenbus_printf

In reply to Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

---
v1->v2:
- Add __func__.

---
 drivers/xen/manage.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/xen/manage.c +15 -3
index 8835065..c93d8ef 100644
@@ -289,8 +289,15 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,
 		return;
 	}
 
-	if (sysrq_key != '\0')
-		xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+	if (sysrq_key != '\0') {
+		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+		if (err) {
+			pr_err("%s: Error %d writing sysrq in control/sysrq\n",
+			       __func__, err);
+			xenbus_transaction_end(xbt, 1);
+			return;
+		}
+	}
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN)
@@ -342,7 +349,12 @@ static int setup_shutdown_watcher(void)
 			continue;
 		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
 			 shutdown_handlers[idx].command);
-		xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		err = xenbus_printf(XBT_NIL, "control", node, "%u", 1);
+		if (err) {
+			pr_err("%s: Error %d writing %s\n", __func__,
+				err, node);
+			return err;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#6 lore raw
Quoted 6 lines · Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

(I wasn't asking you to use xenbus_dev_error() for this patch. Only for the other two patches --- for scsi front and back).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer Applied
#8 lore raw
In reply to Zhouyang Jia
Quoted 6 lines · Zhouyang Jia

When xenbus_printf fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling xenbus_printf.

Pushed to xen/tip.git for-linus-4.18

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel