linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen: add error handling for xenbus_printf
@ 2018-06-12  3:44 Zhouyang Jia
  2018-06-14 21:57 ` Boris Ostrovsky
  2018-06-14 23:34 ` [PATCH v2] " Zhouyang Jia
  0 siblings, 2 replies; 5+ messages in thread
From: Zhouyang Jia @ 2018-06-12  3:44 UTC (permalink / raw)
  Cc: Zhouyang Jia, Boris Ostrovsky, Juergen Gross, xen-devel, linux-kernel

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

This patch adds error-handling code after calling xenbus_printf.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/xen/manage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 8835065..159694d 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen: add error handling for xenbus_printf
  2018-06-12  3:44 [PATCH] xen: add error handling for xenbus_printf Zhouyang Jia
@ 2018-06-14 21:57 ` Boris Ostrovsky
  2018-06-14 23:34 ` [PATCH v2] " Zhouyang Jia
  1 sibling, 0 replies; 5+ messages in thread
From: Boris Ostrovsky @ 2018-06-14 21:57 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Juergen Gross, xen-devel, linux-kernel

On 06/11/2018 11:44 PM, Zhouyang Jia wrote:
> When xenbus_printf fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling xenbus_printf.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
>  drivers/xen/manage.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
> index 8835065..159694d 100644
> --- a/drivers/xen/manage.c
> +++ b/drivers/xen/manage.c
> @@ -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);


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] xen: add error handling for xenbus_printf
  2018-06-12  3:44 [PATCH] xen: add error handling for xenbus_printf Zhouyang Jia
  2018-06-14 21:57 ` Boris Ostrovsky
@ 2018-06-14 23:34 ` Zhouyang Jia
  2018-06-15 12:54   ` Boris Ostrovsky
  2018-06-19 13:02   ` Juergen Gross
  1 sibling, 2 replies; 5+ messages in thread
From: Zhouyang Jia @ 2018-06-14 23:34 UTC (permalink / raw)
  Cc: Zhouyang Jia, Boris Ostrovsky, Juergen Gross, xen-devel, linux-kernel

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

This patch adds error-handling code after calling xenbus_printf.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
v1->v2:
- Add __func__.
---
 drivers/xen/manage.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 8835065..c93d8ef 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xen: add error handling for xenbus_printf
  2018-06-14 23:34 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-15 12:54   ` Boris Ostrovsky
  2018-06-19 13:02   ` Juergen Gross
  1 sibling, 0 replies; 5+ messages in thread
From: Boris Ostrovsky @ 2018-06-15 12:54 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Juergen Gross, xen-devel, linux-kernel

On 06/14/2018 07:34 PM, Zhouyang Jia wrote:
> When xenbus_printf fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling xenbus_printf.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>

Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] xen: add error handling for xenbus_printf
  2018-06-14 23:34 ` [PATCH v2] " Zhouyang Jia
  2018-06-15 12:54   ` Boris Ostrovsky
@ 2018-06-19 13:02   ` Juergen Gross
  1 sibling, 0 replies; 5+ messages in thread
From: Juergen Gross @ 2018-06-19 13:02 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Boris Ostrovsky, xen-devel, linux-kernel

On 15/06/18 01:34, Zhouyang Jia wrote:
> When xenbus_printf fails, the lack of error-handling code may
> cause unexpected results.
> 
> This patch adds error-handling code after calling xenbus_printf.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>

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


Juergen

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-19 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  3:44 [PATCH] xen: add error handling for xenbus_printf Zhouyang Jia
2018-06-14 21:57 ` Boris Ostrovsky
2018-06-14 23:34 ` [PATCH v2] " Zhouyang Jia
2018-06-15 12:54   ` Boris Ostrovsky
2018-06-19 13:02   ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).