xen: add error handling for xenbus_printf
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
@@ -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
Quoted 33 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>--- drivers/xen/manage.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/xen/manage.c +9
-2@@ -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
Quoted 33 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>--- drivers/xen/manage.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/xen/manage.c +9
-2@@ -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
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_printffails, 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 <[email protected]>--- drivers/xen/manage.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/xen/manage.c +0
-0@@ -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
-2return ; } -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 incontrol/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
PATCH v2 1/1 xen: add error handling for xenbus_printf
In reply to Zhouyang JiaWhen 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
@@ -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
PATCH v2 1/1 xen: add error handling for xenbus_printf
In reply to Zhouyang JiaWhen 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
@@ -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
Quoted 6 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>
(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
Quoted 6 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>
(I wasn't asking you to use xenbus_dev_error() for this patch. Only for the other two patches --- for scsi front and back).
Quoted 6 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>
Pushed to xen/tip.git for-linus-4.18
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Zhouyang Jia
When
xenbus_printffails, 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 <[email protected]>
Pushed to xen/tip.git for-linus-4.18
Juergen