linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/scsiback: add error handling for xenbus_printf
@ 2018-06-12  3:46 Zhouyang Jia
  2018-06-15 17:06 ` [PATCH v2] " Zhouyang Jia
  2018-06-16  0:14 ` [PATCH v3] " Zhouyang Jia
  0 siblings, 2 replies; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-12  3:46 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky, xen-devel,
	linux-scsi, 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/xen-scsiback.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 7bc88fd..13ab54c 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1027,8 +1027,9 @@ static void scsiback_do_add_lun(struct vscsibk_info *info, const char *state,
 			scsiback_del_translation_entry(info, vir);
 		}
 	} else if (!try) {
-		xenbus_printf(XBT_NIL, info->dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, info->dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			pr_err("xenbus_printf error %s\n", state);
 	}
 }
 
@@ -1067,8 +1068,9 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	snprintf(str, sizeof(str), "vscsi-devs/%s/p-dev", ent);
 	val = xenbus_read(XBT_NIL, dev->nodename, str, NULL);
 	if (IS_ERR(val)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			pr_err("xenbus_printf error %s\n", state);
 		return;
 	}
 	strlcpy(phy, val, VSCSI_NAMELEN);
@@ -1079,8 +1081,9 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	err = xenbus_scanf(XBT_NIL, dev->nodename, str, "%u:%u:%u:%u",
 			   &vir.hst, &vir.chn, &vir.tgt, &vir.lun);
 	if (XENBUS_EXIST_ERR(err)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			pr_err("xenbus_printf error %s\n", state);
 		return;
 	}
 
-- 
2.7.4


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

* [PATCH v2] xen/scsiback: add error handling for xenbus_printf
  2018-06-12  3:46 [PATCH] xen/scsiback: add error handling for xenbus_printf Zhouyang Jia
@ 2018-06-15 17:06 ` Zhouyang Jia
  2018-06-15 19:22   ` kbuild test robot
  2018-06-16  0:14 ` [PATCH v3] " Zhouyang Jia
  1 sibling, 1 reply; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-15 17:06 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky, xen-devel,
	linux-scsi, 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:
- Use xenbus_dev_error to report errors.
---
 drivers/xen/xen-scsiback.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 7bc88fd..cec2133 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1027,8 +1027,10 @@ static void scsiback_do_add_lun(struct vscsibk_info *info, const char *state,
 			scsiback_del_translation_entry(info, vir);
 		}
 	} else if (!try) {
-		xenbus_printf(XBT_NIL, info->dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, info->dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 	}
 }
 
@@ -1067,8 +1069,10 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	snprintf(str, sizeof(str), "vscsi-devs/%s/p-dev", ent);
 	val = xenbus_read(XBT_NIL, dev->nodename, str, NULL);
 	if (IS_ERR(val)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 		return;
 	}
 	strlcpy(phy, val, VSCSI_NAMELEN);
@@ -1079,8 +1083,10 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	err = xenbus_scanf(XBT_NIL, dev->nodename, str, "%u:%u:%u:%u",
 			   &vir.hst, &vir.chn, &vir.tgt, &vir.lun);
 	if (XENBUS_EXIST_ERR(err)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
-			      "%d", XenbusStateClosed);
+		if (xenbus_printf(XBT_NIL, dev->nodename, state,
+			      "%d", XenbusStateClosed))
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 		return;
 	}
 
-- 
2.7.4


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

* Re: [PATCH v2] xen/scsiback: add error handling for xenbus_printf
  2018-06-15 17:06 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-15 19:22   ` kbuild test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2018-06-15 19:22 UTC (permalink / raw)
  To: linux-kernel-owner
  Cc: kbuild-all, Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	xen-devel, linux-scsi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2283 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on xen-tip/linux-next]
[also build test ERROR on v4.17 next-20180615]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/linux-kernel-owner-vger-kernel-org/xen-scsiback-add-error-handling-for-xenbus_printf/20180616-011349
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
config: i386-randconfig-x009-201823 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers//xen/xen-scsiback.c: In function 'scsiback_do_add_lun':
>> drivers//xen/xen-scsiback.c:1032:32: error: 'err' undeclared (first use in this function)
       xenbus_dev_error(info->dev, err,
                                   ^~~
   drivers//xen/xen-scsiback.c:1032:32: note: each undeclared identifier is reported only once for each function it appears in

vim +/err +1032 drivers//xen/xen-scsiback.c

  1009	
  1010	static void scsiback_do_add_lun(struct vscsibk_info *info, const char *state,
  1011					char *phy, struct ids_tuple *vir, int try)
  1012	{
  1013		struct v2p_entry *entry;
  1014		unsigned long flags;
  1015	
  1016		if (try) {
  1017			spin_lock_irqsave(&info->v2p_lock, flags);
  1018			entry = scsiback_chk_translation_entry(info, vir);
  1019			spin_unlock_irqrestore(&info->v2p_lock, flags);
  1020			if (entry)
  1021				return;
  1022		}
  1023		if (!scsiback_add_translation_entry(info, phy, vir)) {
  1024			if (xenbus_printf(XBT_NIL, info->dev->nodename, state,
  1025					  "%d", XenbusStateInitialised)) {
  1026				pr_err("xenbus_printf error %s\n", state);
  1027				scsiback_del_translation_entry(info, vir);
  1028			}
  1029		} else if (!try) {
  1030			if (xenbus_printf(XBT_NIL, info->dev->nodename, state,
  1031				      "%d", XenbusStateClosed))
> 1032				xenbus_dev_error(info->dev, err,
  1033					"%s: writing %s", __func__, state);
  1034		}
  1035	}
  1036	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32088 bytes --]

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

* [PATCH v3] xen/scsiback: add error handling for xenbus_printf
  2018-06-12  3:46 [PATCH] xen/scsiback: add error handling for xenbus_printf Zhouyang Jia
  2018-06-15 17:06 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-16  0:14 ` Zhouyang Jia
  2018-06-19 12:52   ` Juergen Gross
  2018-06-19 13:01   ` Juergen Gross
  1 sibling, 2 replies; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-16  0:14 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky, xen-devel,
	linux-scsi, 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:
- Use xenbus_dev_error to report errors.
v2->v3:
- Fix compilation errors.
---
 drivers/xen/xen-scsiback.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 7bc88fd..e2f3e8b 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1012,6 +1012,7 @@ static void scsiback_do_add_lun(struct vscsibk_info *info, const char *state,
 {
 	struct v2p_entry *entry;
 	unsigned long flags;
+	int err;
 
 	if (try) {
 		spin_lock_irqsave(&info->v2p_lock, flags);
@@ -1027,8 +1028,11 @@ static void scsiback_do_add_lun(struct vscsibk_info *info, const char *state,
 			scsiback_del_translation_entry(info, vir);
 		}
 	} else if (!try) {
-		xenbus_printf(XBT_NIL, info->dev->nodename, state,
+		err = xenbus_printf(XBT_NIL, info->dev->nodename, state,
 			      "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 	}
 }
 
@@ -1067,8 +1071,11 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	snprintf(str, sizeof(str), "vscsi-devs/%s/p-dev", ent);
 	val = xenbus_read(XBT_NIL, dev->nodename, str, NULL);
 	if (IS_ERR(val)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
+		err = xenbus_printf(XBT_NIL, dev->nodename, state,
 			      "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 		return;
 	}
 	strlcpy(phy, val, VSCSI_NAMELEN);
@@ -1079,8 +1086,11 @@ static void scsiback_do_1lun_hotplug(struct vscsibk_info *info, int op,
 	err = xenbus_scanf(XBT_NIL, dev->nodename, str, "%u:%u:%u:%u",
 			   &vir.hst, &vir.chn, &vir.tgt, &vir.lun);
 	if (XENBUS_EXIST_ERR(err)) {
-		xenbus_printf(XBT_NIL, dev->nodename, state,
+		err = xenbus_printf(XBT_NIL, dev->nodename, state,
 			      "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(info->dev, err,
+				"%s: writing %s", __func__, state);
 		return;
 	}
 
-- 
2.7.4


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

* Re: [PATCH v3] xen/scsiback: add error handling for xenbus_printf
  2018-06-16  0:14 ` [PATCH v3] " Zhouyang Jia
@ 2018-06-19 12:52   ` Juergen Gross
  2018-06-19 13:01   ` Juergen Gross
  1 sibling, 0 replies; 6+ messages in thread
From: Juergen Gross @ 2018-06-19 12:52 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Boris Ostrovsky, xen-devel, linux-scsi, linux-kernel

On 16/06/18 02:14, 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: Juergen Gross <jgross@suse.com>


Juergen

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

* Re: [PATCH v3] xen/scsiback: add error handling for xenbus_printf
  2018-06-16  0:14 ` [PATCH v3] " Zhouyang Jia
  2018-06-19 12:52   ` Juergen Gross
@ 2018-06-19 13:01   ` Juergen Gross
  1 sibling, 0 replies; 6+ messages in thread
From: Juergen Gross @ 2018-06-19 13:01 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: Boris Ostrovsky, xen-devel, linux-scsi, linux-kernel

On 16/06/18 02:14, 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] 6+ messages in thread

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  3:46 [PATCH] xen/scsiback: add error handling for xenbus_printf Zhouyang Jia
2018-06-15 17:06 ` [PATCH v2] " Zhouyang Jia
2018-06-15 19:22   ` kbuild test robot
2018-06-16  0:14 ` [PATCH v3] " Zhouyang Jia
2018-06-19 12:52   ` Juergen Gross
2018-06-19 13:01   ` 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).