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

From: Boris Ostrovsky
Date: Thu Jun 14 2018 - 17:57:30 EST


On 06/14/2018 12:08 PM, 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@xxxxxxxxx>
> ---
> v1->v2:
> - Fix dereferencing before checking
> ---
> drivers/scsi/xen-scsifront.c | 29 ++++++++++++++++++++++-------
> 1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
> index 36f59a1..a7f6111 100644
> --- a/drivers/scsi/xen-scsifront.c
> +++ b/drivers/scsi/xen-scsifront.c
> @@ -654,10 +654,16 @@ 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);
> + 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);
> + if (err) {
> + dev_err(&info->dev->dev, "writing dev_state_path\n");

These errors should be reported using xenbus_dev_error().

And the second patch too.

-boris