lkml.org 
[lkml]   [2018]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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 <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 = {

--

\
 
 \ /
  Last update: 2018-06-13 12:10    [W:0.043 / U:2.680 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site