Skip to content

Commit 93efbd3

Browse files
ZhouyangJiajgross1
authored andcommitted
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]> Reviewed-by: Juergen Gross <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 6e3cc2a commit 93efbd3

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

drivers/scsi/xen-scsifront.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,21 +654,33 @@ static int scsifront_dev_reset_handler(struct scsi_cmnd *sc)
654654
static int scsifront_sdev_configure(struct scsi_device *sdev)
655655
{
656656
struct vscsifrnt_info *info = shost_priv(sdev->host);
657+
int err;
657658

658-
if (info && current == info->curr)
659-
xenbus_printf(XBT_NIL, info->dev->nodename,
659+
if (info && current == info->curr) {
660+
err = xenbus_printf(XBT_NIL, info->dev->nodename,
660661
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+
}
661668

662669
return 0;
663670
}
664671

665672
static void scsifront_sdev_destroy(struct scsi_device *sdev)
666673
{
667674
struct vscsifrnt_info *info = shost_priv(sdev->host);
675+
int err;
668676

669-
if (info && current == info->curr)
670-
xenbus_printf(XBT_NIL, info->dev->nodename,
677+
if (info && current == info->curr) {
678+
err = xenbus_printf(XBT_NIL, info->dev->nodename,
671679
info->dev_state_path, "%d", XenbusStateClosed);
680+
if (err)
681+
xenbus_dev_error(info->dev, err,
682+
"%s: writing dev_state_path", __func__);
683+
}
672684
}
673685

674686
static struct scsi_host_template scsifront_sht = {
@@ -1003,9 +1015,12 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
10031015

10041016
if (scsi_add_device(info->host, chn, tgt, lun)) {
10051017
dev_err(&dev->dev, "scsi_add_device\n");
1006-
xenbus_printf(XBT_NIL, dev->nodename,
1018+
err = xenbus_printf(XBT_NIL, dev->nodename,
10071019
info->dev_state_path,
10081020
"%d", XenbusStateClosed);
1021+
if (err)
1022+
xenbus_dev_error(dev, err,
1023+
"%s: writing dev_state_path", __func__);
10091024
}
10101025
break;
10111026
case VSCSIFRONT_OP_DEL_LUN:
@@ -1019,10 +1034,14 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op)
10191034
}
10201035
break;
10211036
case VSCSIFRONT_OP_READD_LUN:
1022-
if (device_state == XenbusStateConnected)
1023-
xenbus_printf(XBT_NIL, dev->nodename,
1037+
if (device_state == XenbusStateConnected) {
1038+
err = xenbus_printf(XBT_NIL, dev->nodename,
10241039
info->dev_state_path,
10251040
"%d", XenbusStateConnected);
1041+
if (err)
1042+
xenbus_dev_error(dev, err,
1043+
"%s: writing dev_state_path", __func__);
1044+
}
10261045
break;
10271046
default:
10281047
break;

0 commit comments

Comments
 (0)