linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf
@ 2018-06-12  3:42 Zhouyang Jia
  2018-06-13 10:09 ` Finn Thain
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Zhouyang Jia @ 2018-06-12  3:42 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, 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/scsi/xen-scsifront.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 36f59a1..3d858ac 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -654,10 +654,17 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
 static int scsifront_sdev_configure(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	struct xenbus_device *dev = info->dev;
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateConnected);
+		if (err) {
+			dev_err(&dev->dev, "writing dev_state_path\n");
+			return err;
+		}
+	}
 
 	return 0;
 }
@@ -665,10 +672,15 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
 static void scsifront_sdev_destroy(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	struct xenbus_device *dev = info->dev;
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateClosed);
+		if (err)
+			dev_err(&dev->dev, "writing dev_state_path\n");
+	}
 }
 
 static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1015,11 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 
 			if (scsi_add_device(info->host, chn, tgt, lun)) {
 				dev_err(&dev->dev, "scsi_add_device\n");
-				xenbus_printf(XBT_NIL, dev->nodename,
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateClosed);
+				if (err)
+					dev_err(&dev->dev, "writing dev_state_path\n");
 			}
 			break;
 		case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1033,13 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 			}
 			break;
 		case VSCSIFRONT_OP_READD_LUN:
-			if (device_state == XenbusStateConnected)
-				xenbus_printf(XBT_NIL, dev->nodename,
+			if (device_state == XenbusStateConnected) {
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateConnected);
+				if (err)
+					dev_err(&dev->dev, "writing dev_state_path\n");
+			}
 			break;
 		default:
 			break;
-- 
2.7.4


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

* Re: [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
@ 2018-06-13 10:09 ` Finn Thain
  2018-06-14 16:08 ` [PATCH v2] " Zhouyang Jia
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Finn Thain @ 2018-06-13 10:09 UTC (permalink / raw)
  To: Zhouyang Jia
  Cc: Juergen Gross, Boris Ostrovsky, James E.J. Bottomley,
	Martin K. Petersen, xen-devel, linux-scsi, linux-kernel

On Tue, 12 Jun 2018, 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/scsi/xen-scsifront.c | 31 ++++++++++++++++++++++++-------
>  1 file changed, 24 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index 36f59a1..3d858ac 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -654,10 +654,17 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
>  static int scsifront_sdev_configure(struct scsi_device *sdev)
>  {
>  	struct vscsifrnt_info *info = shost_priv(sdev->host);
> +	struct xenbus_device *dev = info->dev;
> +	int err;
>  
> -	if (info && current == info->curr)
> -		xenbus_printf(XBT_NIL, info->dev->nodename,
> +	if (info && current == info->curr) {
> +		err = xenbus_printf(XBT_NIL, info->dev->nodename,
>  			      info->dev_state_path, "%d", XenbusStateConnected);

The existing code checks whether 'info' is NULL before dereferencing it. 
But your patch checks for NULL after dereferencing.

> +		if (err) {
> +			dev_err(&dev->dev, "writing dev_state_path\n");
> +			return err;
> +		}
> +	}
>  
>  	return 0;
>  }
> @@ -665,10 +672,15 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
>  static void scsifront_sdev_destroy(struct scsi_device *sdev)
>  {
>  	struct vscsifrnt_info *info = shost_priv(sdev->host);
> +	struct xenbus_device *dev = info->dev;
> +	int err;
>  
> -	if (info && current == info->curr)
> -		xenbus_printf(XBT_NIL, info->dev->nodename,
> +	if (info && current == info->curr) {
> +		err = xenbus_printf(XBT_NIL, info->dev->nodename,
>  			      info->dev_state_path, "%d", XenbusStateClosed);

Same here.

> +		if (err)
> +			dev_err(&dev->dev, "writing dev_state_path\n");
> +	}
>  }
>  
>  static struct scsi_host_template scsifront_sht = {

-- 

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

* [PATCH v2] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
  2018-06-13 10:09 ` Finn Thain
@ 2018-06-14 16:08 ` Zhouyang Jia
  2018-06-14 21:54   ` Boris Ostrovsky
  2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Zhouyang Jia @ 2018-06-14 16:08 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, 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:
- Fix dereferencing before checking
---
 drivers/scsi/xen-scsifront.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 36f59a1..a7f6111 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -654,10 +654,16 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
 static int scsifront_sdev_configure(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateConnected);
+		if (err) {
+			dev_err(&info->dev->dev, "writing dev_state_path\n");
+			return err;
+		}
+	}
 
 	return 0;
 }
@@ -665,10 +671,14 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
 static void scsifront_sdev_destroy(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateClosed);
+		if (err)
+			dev_err(&info->dev->dev, "writing dev_state_path\n");
+	}
 }
 
 static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1013,11 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 
 			if (scsi_add_device(info->host, chn, tgt, lun)) {
 				dev_err(&dev->dev, "scsi_add_device\n");
-				xenbus_printf(XBT_NIL, dev->nodename,
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateClosed);
+				if (err)
+					dev_err(&dev->dev, "writing dev_state_path\n");
 			}
 			break;
 		case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1031,13 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 			}
 			break;
 		case VSCSIFRONT_OP_READD_LUN:
-			if (device_state == XenbusStateConnected)
-				xenbus_printf(XBT_NIL, dev->nodename,
+			if (device_state == XenbusStateConnected) {
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateConnected);
+				if (err)
+					dev_err(&dev->dev, "writing dev_state_path\n");
+			}
 			break;
 		default:
 			break;
-- 
2.7.4


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

* Re: [PATCH v2] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-14 16:08 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-14 21:54   ` Boris Ostrovsky
  0 siblings, 0 replies; 14+ messages in thread
From: Boris Ostrovsky @ 2018-06-14 21:54 UTC (permalink / raw)
  To: Zhouyang Jia
  Cc: Juergen Gross, James E.J. Bottomley, Martin K. Petersen,
	xen-devel, linux-scsi, linux-kernel

On 06/14/2018 12:08 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>
> ---
> v1->v2:
> - Fix dereferencing before checking
> ---
>  drivers/scsi/xen-scsifront.c | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index 36f59a1..a7f6111 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -654,10 +654,16 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
>  static int scsifront_sdev_configure(struct scsi_device *sdev)
>  {
>  	struct vscsifrnt_info *info = shost_priv(sdev->host);
> +	int err;
>  
> -	if (info && current == info->curr)
> -		xenbus_printf(XBT_NIL, info->dev->nodename,
> +	if (info && current == info->curr) {
> +		err = xenbus_printf(XBT_NIL, info->dev->nodename,
>  			      info->dev_state_path, "%d", XenbusStateConnected);
> +		if (err) {
> +			dev_err(&info->dev->dev, "writing dev_state_path\n");

These errors should be reported using xenbus_dev_error().

And the second patch too.

-boris



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

* [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
  2018-06-13 10:09 ` Finn Thain
  2018-06-14 16:08 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-14 22:59 ` Zhouyang Jia
  2018-06-14 23:50   ` kbuild test robot
                     ` (2 more replies)
  2018-06-15  1:48 ` [PATCH v4] " Zhouyang Jia
  2018-06-15 17:05 ` [PATCH v5] " Zhouyang Jia
  4 siblings, 3 replies; 14+ messages in thread
From: Zhouyang Jia @ 2018-06-14 22:59 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, 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:
- Fix dereferencing before checking
v2->v3:
- Use xenbus_dev_error to report errors.
---
 drivers/scsi/xen-scsifront.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 36f59a1..644d1ce 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -654,10 +654,17 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
 static int scsifront_sdev_configure(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateConnected);
+		if (err) {
+			xenbus_dev_error(&info->dev->dev, err,
+				"%s: writing dev_state_path", __func__);
+			return err;
+		}
+	}
 
 	return 0;
 }
@@ -665,10 +672,15 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
 static void scsifront_sdev_destroy(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(&info->dev->dev, err,
+				"%s: writing dev_state_path", __func__);
+	}
 }
 
 static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1015,12 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 
 			if (scsi_add_device(info->host, chn, tgt, lun)) {
 				dev_err(&dev->dev, "scsi_add_device\n");
-				xenbus_printf(XBT_NIL, dev->nodename,
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateClosed);
+				if (err)
+					xenbus_dev_error(&dev->dev, err,
+						"%s: writing dev_state_path", __func__);
 			}
 			break;
 		case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1034,14 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 			}
 			break;
 		case VSCSIFRONT_OP_READD_LUN:
-			if (device_state == XenbusStateConnected)
-				xenbus_printf(XBT_NIL, dev->nodename,
+			if (device_state == XenbusStateConnected) {
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateConnected);
+				if (err)
+					xenbus_dev_error(&dev->dev, err,
+						"%s: writing dev_state_path", __func__);
+			}
 			break;
 		default:
 			break;
-- 
2.7.4


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

* Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
@ 2018-06-14 23:50   ` kbuild test robot
  2018-06-15  2:32   ` kbuild test robot
  2018-06-15  5:44   ` kbuild test robot
  2 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2018-06-14 23:50 UTC (permalink / raw)
  To: linux-scsi-owner
  Cc: kbuild-all, Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, xen-devel, linux-scsi,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3792 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-20180614]
[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-scsi-owner-vger-kernel-org/scsi-xen-scsifront-add-error-handling-for-xenbus_printf/20180615-070404
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
config: i386-randconfig-x010-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/scsi/xen-scsifront.c: In function 'scsifront_sdev_configure':
>> drivers/scsi/xen-scsifront.c:663:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c: In function 'scsifront_sdev_destroy':
   drivers/scsi/xen-scsifront.c:681:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c: In function 'scsifront_do_lun_hotplug':
   drivers/scsi/xen-scsifront.c:1022:23: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c:1042:23: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/xenbus_dev_error +663 drivers/scsi/xen-scsifront.c

   653	
   654	static int scsifront_sdev_configure(struct scsi_device *sdev)
   655	{
   656		struct vscsifrnt_info *info = shost_priv(sdev->host);
   657		int err;
   658	
   659		if (info && current == info->curr) {
   660			err = xenbus_printf(XBT_NIL, info->dev->nodename,
   661				      info->dev_state_path, "%d", XenbusStateConnected);
   662			if (err) {
 > 663				xenbus_dev_error(&info->dev->dev, err,
   664					"%s: writing dev_state_path", __func__);
   665				return err;
   666			}
   667		}
   668	
   669		return 0;
   670	}
   671	

---
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: 30075 bytes --]

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

* [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
                   ` (2 preceding siblings ...)
  2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
@ 2018-06-15  1:48 ` Zhouyang Jia
  2018-06-15  6:04   ` kbuild test robot
  2018-06-15 11:59   ` kbuild test robot
  2018-06-15 17:05 ` [PATCH v5] " Zhouyang Jia
  4 siblings, 2 replies; 14+ messages in thread
From: Zhouyang Jia @ 2018-06-15  1:48 UTC (permalink / raw)
  Cc: Zhouyang Jia, Boris Ostrovsky, Juergen Gross,
	James E.J. Bottomley, Martin K. Petersen, 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:
- Fix dereferencing before checking.
v2->v3:
- Use xenbus_dev_error to report errors.
v3->v4:
- Fix compilation errors.
---
 drivers/scsi/xen-scsifront.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 36f59a1..be576cb 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -654,10 +654,17 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
 static int scsifront_sdev_configure(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateConnected);
+		if (err) {
+			xenbus_dev_error(&info->dev, err,
+				"%s: writing dev_state_path", __func__);
+			return err;
+		}
+	}
 
 	return 0;
 }
@@ -665,10 +672,15 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
 static void scsifront_sdev_destroy(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(&info->dev, err,
+				"%s: writing dev_state_path", __func__);
+	}
 }
 
 static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1015,12 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 
 			if (scsi_add_device(info->host, chn, tgt, lun)) {
 				dev_err(&dev->dev, "scsi_add_device\n");
-				xenbus_printf(XBT_NIL, dev->nodename,
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateClosed);
+				if (err)
+					xenbus_dev_error(dev, err,
+						"%s: writing dev_state_path", __func__);
 			}
 			break;
 		case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1034,14 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 			}
 			break;
 		case VSCSIFRONT_OP_READD_LUN:
-			if (device_state == XenbusStateConnected)
-				xenbus_printf(XBT_NIL, dev->nodename,
+			if (device_state == XenbusStateConnected) {
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateConnected);
+				if (err)
+					xenbus_dev_error(dev, err,
+						"%s: writing dev_state_path", __func__);
+			}
 			break;
 		default:
 			break;
-- 
2.7.4


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

* Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
  2018-06-14 23:50   ` kbuild test robot
@ 2018-06-15  2:32   ` kbuild test robot
  2018-06-15  5:44   ` kbuild test robot
  2 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2018-06-15  2:32 UTC (permalink / raw)
  To: linux-scsi-owner
  Cc: kbuild-all, Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, xen-devel, linux-scsi,
	linux-kernel

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

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on xen-tip/linux-next]
[also build test WARNING on v4.17 next-20180614]
[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-scsi-owner-vger-kernel-org/scsi-xen-scsifront-add-error-handling-for-xenbus_printf/20180615-070404
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
config: i386-randconfig-sb0-06140922 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   drivers//scsi/xen-scsifront.c: In function 'scsifront_sdev_configure':
>> drivers//scsi/xen-scsifront.c:663:21: warning: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^
   drivers//scsi/xen-scsifront.c: In function 'scsifront_sdev_destroy':
   drivers//scsi/xen-scsifront.c:681:21: warning: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^
   drivers//scsi/xen-scsifront.c: In function 'scsifront_do_lun_hotplug':
   drivers//scsi/xen-scsifront.c:1022:23: warning: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^
   drivers//scsi/xen-scsifront.c:1042:23: warning: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^

vim +/xenbus_dev_error +663 drivers//scsi/xen-scsifront.c

   653	
   654	static int scsifront_sdev_configure(struct scsi_device *sdev)
   655	{
   656		struct vscsifrnt_info *info = shost_priv(sdev->host);
   657		int err;
   658	
   659		if (info && current == info->curr) {
   660			err = xenbus_printf(XBT_NIL, info->dev->nodename,
   661				      info->dev_state_path, "%d", XenbusStateConnected);
   662			if (err) {
 > 663				xenbus_dev_error(&info->dev->dev, err,
   664					"%s: writing dev_state_path", __func__);
   665				return err;
   666			}
   667		}
   668	
   669		return 0;
   670	}
   671	

---
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: 32162 bytes --]

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

* Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
  2018-06-14 23:50   ` kbuild test robot
  2018-06-15  2:32   ` kbuild test robot
@ 2018-06-15  5:44   ` kbuild test robot
  2 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2018-06-15  5:44 UTC (permalink / raw)
  To: linux-scsi-owner
  Cc: kbuild-all, Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, xen-devel, linux-scsi,
	linux-kernel

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on xen-tip/linux-next]
[also build test WARNING on v4.17 next-20180614]
[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-scsi-owner-vger-kernel-org/scsi-xen-scsifront-add-error-handling-for-xenbus_printf/20180615-070404
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   drivers/scsi/xen-scsifront.c:267:21: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:440:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:440:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:473:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:473:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:474:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:474:33: sparse: expression using sizeof(void)
>> drivers/scsi/xen-scsifront.c:663:47: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:663:47:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:663:47:    got struct device *<noident>
   drivers/scsi/xen-scsifront.c:681:47: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:681:47:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:681:47:    got struct device *<noident>
   drivers/scsi/xen-scsifront.c:1022:59: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:1022:59:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:1022:59:    got struct device *<noident>
   drivers/scsi/xen-scsifront.c:1042:59: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:1042:59:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:1042:59:    got struct device *<noident>
   drivers/scsi/xen-scsifront.c:1063:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:1064:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:1065:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c: In function 'scsifront_sdev_configure':
   drivers/scsi/xen-scsifront.c:663:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c: In function 'scsifront_sdev_destroy':
   drivers/scsi/xen-scsifront.c:681:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c: In function 'scsifront_do_lun_hotplug':
   drivers/scsi/xen-scsifront.c:1022:23: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c:1042:23: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
         xenbus_dev_error(&dev->dev, err,
                          ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct device *'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +663 drivers/scsi/xen-scsifront.c

   653	
   654	static int scsifront_sdev_configure(struct scsi_device *sdev)
   655	{
   656		struct vscsifrnt_info *info = shost_priv(sdev->host);
   657		int err;
   658	
   659		if (info && current == info->curr) {
   660			err = xenbus_printf(XBT_NIL, info->dev->nodename,
   661				      info->dev_state_path, "%d", XenbusStateConnected);
   662			if (err) {
 > 663				xenbus_dev_error(&info->dev->dev, err,
   664					"%s: writing dev_state_path", __func__);
   665				return err;
   666			}
   667		}
   668	
   669		return 0;
   670	}
   671	

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

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

* Re: [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-15  1:48 ` [PATCH v4] " Zhouyang Jia
@ 2018-06-15  6:04   ` kbuild test robot
  2018-06-15 11:59   ` kbuild test robot
  1 sibling, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2018-06-15  6:04 UTC (permalink / raw)
  To: linux-kernel-owner
  Cc: kbuild-all, Zhouyang Jia, Boris Ostrovsky, Juergen Gross,
	James E.J. Bottomley, Martin K. Petersen, xen-devel, linux-scsi,
	linux-kernel

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on xen-tip/linux-next]
[also build test WARNING on v4.17 next-20180614]
[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/scsi-xen-scsifront-add-error-handling-for-xenbus_printf/20180615-094919
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   drivers/scsi/xen-scsifront.c:267:21: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:440:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:440:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:473:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:473:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:474:33: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:474:33: sparse: expression using sizeof(void)
>> drivers/scsi/xen-scsifront.c:663:43: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got sstruct xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:663:43:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:663:43:    got struct xenbus_device **<noident>
   drivers/scsi/xen-scsifront.c:681:43: sparse: incorrect type in argument 1 (different base types) @@    expected struct xenbus_device *dev @@    got sstruct xenbus_device *dev @@
   drivers/scsi/xen-scsifront.c:681:43:    expected struct xenbus_device *dev
   drivers/scsi/xen-scsifront.c:681:43:    got struct xenbus_device **<noident>
   drivers/scsi/xen-scsifront.c:1063:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:1064:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c:1065:19: sparse: expression using sizeof(void)
   drivers/scsi/xen-scsifront.c: In function 'scsifront_sdev_configure':
   drivers/scsi/xen-scsifront.c:663:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct xenbus_device **'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers/scsi/xen-scsifront.c: In function 'scsifront_sdev_destroy':
   drivers/scsi/xen-scsifront.c:681:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev, err,
                        ^
   In file included from drivers/scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct xenbus_device **'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +663 drivers/scsi/xen-scsifront.c

   653	
   654	static int scsifront_sdev_configure(struct scsi_device *sdev)
   655	{
   656		struct vscsifrnt_info *info = shost_priv(sdev->host);
   657		int err;
   658	
   659		if (info && current == info->curr) {
   660			err = xenbus_printf(XBT_NIL, info->dev->nodename,
   661				      info->dev_state_path, "%d", XenbusStateConnected);
   662			if (err) {
 > 663				xenbus_dev_error(&info->dev, err,
   664					"%s: writing dev_state_path", __func__);
   665				return err;
   666			}
   667		}
   668	
   669		return 0;
   670	}
   671	

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

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

* Re: [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-15  1:48 ` [PATCH v4] " Zhouyang Jia
  2018-06-15  6:04   ` kbuild test robot
@ 2018-06-15 11:59   ` kbuild test robot
  1 sibling, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2018-06-15 11:59 UTC (permalink / raw)
  To: linux-kernel-owner
  Cc: kbuild-all, Zhouyang Jia, Boris Ostrovsky, Juergen Gross,
	James E.J. Bottomley, Martin K. Petersen, xen-devel, linux-scsi,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2698 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/scsi-xen-scsifront-add-error-handling-for-xenbus_printf/20180615-094919
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git linux-next
config: x86_64-fedora-25 (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=x86_64 

All errors (new ones prefixed by >>):

   drivers//scsi/xen-scsifront.c: In function 'scsifront_sdev_configure':
>> drivers//scsi/xen-scsifront.c:663:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev, err,
                        ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct xenbus_device **'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   drivers//scsi/xen-scsifront.c: In function 'scsifront_sdev_destroy':
   drivers//scsi/xen-scsifront.c:681:21: error: passing argument 1 of 'xenbus_dev_error' from incompatible pointer type [-Werror=incompatible-pointer-types]
       xenbus_dev_error(&info->dev, err,
                        ^
   In file included from drivers//scsi/xen-scsifront.c:50:0:
   include/xen/xenbus.h:224:6: note: expected 'struct xenbus_device *' but argument is of type 'struct xenbus_device **'
    void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
         ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/xenbus_dev_error +663 drivers//scsi/xen-scsifront.c

   653	
   654	static int scsifront_sdev_configure(struct scsi_device *sdev)
   655	{
   656		struct vscsifrnt_info *info = shost_priv(sdev->host);
   657		int err;
   658	
   659		if (info && current == info->curr) {
   660			err = xenbus_printf(XBT_NIL, info->dev->nodename,
   661				      info->dev_state_path, "%d", XenbusStateConnected);
   662			if (err) {
 > 663				xenbus_dev_error(&info->dev, err,
   664					"%s: writing dev_state_path", __func__);
   665				return err;
   666			}
   667		}
   668	
   669		return 0;
   670	}
   671	

---
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: 47744 bytes --]

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

* [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
                   ` (3 preceding siblings ...)
  2018-06-15  1:48 ` [PATCH v4] " Zhouyang Jia
@ 2018-06-15 17:05 ` Zhouyang Jia
  2018-06-19 12:53   ` Juergen Gross
  2018-06-19 13:02   ` Juergen Gross
  4 siblings, 2 replies; 14+ messages in thread
From: Zhouyang Jia @ 2018-06-15 17:05 UTC (permalink / raw)
  Cc: Zhouyang Jia, Juergen Gross, Boris Ostrovsky,
	James E.J. Bottomley, Martin K. Petersen, 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:
- Fix dereferencing before checking.
v2->v3:
- Use xenbus_dev_error to report errors.
v3->v4:
- Fix compilation errors.
v4->v5:
- Fix compilation errors.
---
 drivers/scsi/xen-scsifront.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 36f59a1..61389bd 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -654,10 +654,17 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
 static int scsifront_sdev_configure(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateConnected);
+		if (err) {
+			xenbus_dev_error(info->dev, err,
+				"%s: writing dev_state_path", __func__);
+			return err;
+		}
+	}
 
 	return 0;
 }
@@ -665,10 +672,15 @@ static int scsifront_sdev_configure(struct scsi_device *sdev)
 static void scsifront_sdev_destroy(struct scsi_device *sdev)
 {
 	struct vscsifrnt_info *info = shost_priv(sdev->host);
+	int err;
 
-	if (info && current == info->curr)
-		xenbus_printf(XBT_NIL, info->dev->nodename,
+	if (info && current == info->curr) {
+		err = xenbus_printf(XBT_NIL, info->dev->nodename,
 			      info->dev_state_path, "%d", XenbusStateClosed);
+		if (err)
+			xenbus_dev_error(info->dev, err,
+				"%s: writing dev_state_path", __func__);
+	}
 }
 
 static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1015,12 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 
 			if (scsi_add_device(info->host, chn, tgt, lun)) {
 				dev_err(&dev->dev, "scsi_add_device\n");
-				xenbus_printf(XBT_NIL, dev->nodename,
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateClosed);
+				if (err)
+					xenbus_dev_error(dev, err,
+						"%s: writing dev_state_path", __func__);
 			}
 			break;
 		case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1034,14 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
 			}
 			break;
 		case VSCSIFRONT_OP_READD_LUN:
-			if (device_state == XenbusStateConnected)
-				xenbus_printf(XBT_NIL, dev->nodename,
+			if (device_state == XenbusStateConnected) {
+				err = xenbus_printf(XBT_NIL, dev->nodename,
 					      info->dev_state_path,
 					      "%d", XenbusStateConnected);
+				if (err)
+					xenbus_dev_error(dev, err,
+						"%s: writing dev_state_path", __func__);
+			}
 			break;
 		default:
 			break;
-- 
2.7.4


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

* Re: [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-15 17:05 ` [PATCH v5] " Zhouyang Jia
@ 2018-06-19 12:53   ` Juergen Gross
  2018-06-19 13:02   ` Juergen Gross
  1 sibling, 0 replies; 14+ messages in thread
From: Juergen Gross @ 2018-06-19 12:53 UTC (permalink / raw)
  To: Zhouyang Jia
  Cc: Boris Ostrovsky, James E.J. Bottomley, Martin K. Petersen,
	xen-devel, linux-scsi, linux-kernel

On 15/06/18 19:05, 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] 14+ messages in thread

* Re: [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf
  2018-06-15 17:05 ` [PATCH v5] " Zhouyang Jia
  2018-06-19 12:53   ` Juergen Gross
@ 2018-06-19 13:02   ` Juergen Gross
  1 sibling, 0 replies; 14+ messages in thread
From: Juergen Gross @ 2018-06-19 13:02 UTC (permalink / raw)
  To: Zhouyang Jia
  Cc: Boris Ostrovsky, James E.J. Bottomley, Martin K. Petersen,
	xen-devel, linux-scsi, linux-kernel

On 15/06/18 19:05, 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] 14+ messages in thread

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

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
2018-06-13 10:09 ` Finn Thain
2018-06-14 16:08 ` [PATCH v2] " Zhouyang Jia
2018-06-14 21:54   ` Boris Ostrovsky
2018-06-14 22:59 ` [PATCH v3] " Zhouyang Jia
2018-06-14 23:50   ` kbuild test robot
2018-06-15  2:32   ` kbuild test robot
2018-06-15  5:44   ` kbuild test robot
2018-06-15  1:48 ` [PATCH v4] " Zhouyang Jia
2018-06-15  6:04   ` kbuild test robot
2018-06-15 11:59   ` kbuild test robot
2018-06-15 17:05 ` [PATCH v5] " Zhouyang Jia
2018-06-19 12:53   ` Juergen Gross
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).