2018-06-12 04:05:00

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH] scsi: xen-scsifront: 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.

Signed-off-by: Zhouyang Jia <[email protected]>
---
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



2018-06-13 10:10:50

by Finn Thain

[permalink] [raw]
Subject: Re: [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf

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 <[email protected]>
> ---
> 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 = {

--

2018-06-14 16:09:40

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH v2] scsi: xen-scsifront: 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.

Signed-off-by: Zhouyang Jia <[email protected]>
---
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


2018-06-14 21:59:14

by Boris Ostrovsky

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: xen-scsifront: add error handling for xenbus_printf

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 <[email protected]>
> ---
> 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



2018-06-14 23:00:37

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH v3] scsi: xen-scsifront: 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.

Signed-off-by: Zhouyang Jia <[email protected]>
---
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


2018-06-14 23:53:30

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf

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


Attachments:
(No filename) (3.78 kB)
.config.gz (29.37 kB)
Download all attachments

2018-06-15 01:49:20

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH v4] scsi: xen-scsifront: 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.

Signed-off-by: Zhouyang Jia <[email protected]>
---
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


2018-06-15 02:34:03

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf

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


Attachments:
(No filename) (3.56 kB)
.config.gz (31.41 kB)
Download all attachments

2018-06-15 05:45:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3] scsi: xen-scsifront: add error handling for xenbus_printf

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

2018-06-15 06:06:16

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf

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

2018-06-15 12:01:32

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf

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


Attachments:
(No filename) (2.69 kB)
.config.gz (46.62 kB)
Download all attachments

2018-06-15 17:05:55

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH v5] scsi: xen-scsifront: 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.

Signed-off-by: Zhouyang Jia <[email protected]>
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


2018-06-19 12:56:47

by Juergen Gross

[permalink] [raw]
Subject: Re: [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf

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 <[email protected]>

Reviewed-by: Juergen Gross <[email protected]>


Juergen

2018-06-19 13:05:43

by Juergen Gross

[permalink] [raw]
Subject: Re: [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf

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 <[email protected]>

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


Juergen