Re: [Xen-devel] [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf

2018-06-14 Thread Zhouyang Jia
Hi,

Sorry for the mistakes, I'll fix this in v2.

Best,
Zhouyang

2018-06-13 18:09 GMT+08:00 Finn Thain :

> 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 
> > ---
> >  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 = {
>
> --
>
___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf

2018-06-13 Thread Finn Thain
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 
> ---
>  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 = {

-- 

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel