public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Zhouyang Jia <jiazhouyang09@gmail.com>
Cc: Juergen Gross <jgross@suse.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf
Date: Wed, 13 Jun 2018 20:09:51 +1000 (AEST)	[thread overview]
Message-ID: <alpine.LNX.2.21.1806132002180.45@nippy.intranet> (raw)
In-Reply-To: <1528774962-39173-1-git-send-email-jiazhouyang09@gmail.com>

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 = {

-- 

  reply	other threads:[~2018-06-13 10:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12  3:42 [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf Zhouyang Jia
2018-06-13 10:09 ` Finn Thain [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.21.1806132002180.45@nippy.intranet \
    --to=fthain@telegraphics.com.au \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jgross@suse.com \
    --cc=jiazhouyang09@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox