[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.21.1806132002180.45@nippy.intranet>
Date: Wed, 13 Jun 2018 20:09:51 +1000 (AEST)
From: Finn Thain <fthain@...egraphics.com.au>
To: Zhouyang Jia <jiazhouyang09@...il.com>
cc: Juergen Gross <jgross@...e.com>,
Boris Ostrovsky <boris.ostrovsky@...cle.com>,
"James E.J. Bottomley" <jejb@...ux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
xen-devel@...ts.xenproject.org, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org
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 <jiazhouyang09@...il.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 = {
--
Powered by blists - more mailing lists