From patchwork Fri Jun 15 17:05:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhouyang Jia X-Patchwork-Id: 10467125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B2A8601C2 for ; Fri, 15 Jun 2018 17:05:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D29C28DA3 for ; Fri, 15 Jun 2018 17:05:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10AC328E13; Fri, 15 Jun 2018 17:05:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98DE28DA3 for ; Fri, 15 Jun 2018 17:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756224AbeFORFJ (ORCPT ); Fri, 15 Jun 2018 13:05:09 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38636 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756180AbeFORFI (ORCPT ); Fri, 15 Jun 2018 13:05:08 -0400 Received: by mail-pf0-f195.google.com with SMTP id b74-v6so5153952pfl.5; Fri, 15 Jun 2018 10:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HRlDkwHHqxiBFNaR3UHGoZzqGBCJcg/h6N1jAZn2fd8=; b=InADBVIA48QTGwONCDb9uDZP37ztZTPC8x6fxFu+78xjhX2ycmKclsYc5YFas02m7x P0Vpkd1BSYItnAA3EkiI9ft450/9xjVGmgh/hSaidYRaQd41Rdsl8k4r078Z3xUsnE3U TE7kugEQrS5hTYwoThnNvMSucg+QYJwZ/jT9vyVkP+q0Zgo3tGZcThMaHaDjoLXf3fEH oCJHV29rpfK/xIi8GSzihvmLcRHQFvj1O3aRrUZQsPNJ1wX+HACUdkXGHFwKcEf+gkxF 4PF9PiIXm75wUUpk9VJHED49LaZx+HYO2i/QG1/EUtbBXWKoYoxVFQ95/MvqyGvQhzWZ qy8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HRlDkwHHqxiBFNaR3UHGoZzqGBCJcg/h6N1jAZn2fd8=; b=TNWLIiHrw9KP2i6bPu/+U5ETqV/pvWhdZguUpyE5zO8LTEO85OHV+5Crq4l9dTL5qu 6A5rgduViTU76jBptHImnRAG6dEkk6UQR+jXrJVkHofnrr1155cQbO4KfkAK/5jFa+sI K8pzEP7HBGnVo47NlyO85C7Nn6AXHSL8sqnfV18dPofuJwEA6pNioIaSgAFTjb9ChXWw G0sme9l+o4f/TFEPMAYGCeNPz8wUolj0q5HfkPMU4wcjoh1yl8P6yai8xGXC3iMn/v3e ZYgKLwK/UV6u5flNKD68j9QIL1g6Y4xbKnrRoigchd0gMKJA0NyYXWtG+CQsIHICLwOx Uh1Q== X-Gm-Message-State: APt69E0VZM41Quh1F3Z54bqci8L7ZNFGtUCgaYz7zEGT8xdsioQ0+smr n1pA4Mg+YjO2LRvy/mo+KEA= X-Google-Smtp-Source: ADUXVKK2mfXxDxhFSOU2FYq71iqtPGeENX6KRERhrd/dSAYzO/1PKj26IgJgtzv6Zvn6R5s3GWFw6Q== X-Received: by 2002:a63:61d6:: with SMTP id v205-v6mr2364353pgb.432.1529082307601; Fri, 15 Jun 2018 10:05:07 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id f3-v6sm12130362pfn.149.2018.06.15.10.05.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jun 2018 10:05:06 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Juergen Gross , Boris Ostrovsky , "James E.J. Bottomley" , "Martin K. Petersen" , xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5] scsi: xen-scsifront: add error handling for xenbus_printf Date: Sat, 16 Jun 2018 01:05:01 +0800 Message-Id: <1529082301-59038-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528774962-39173-1-git-send-email-jiazhouyang09@gmail.com> References: <1528774962-39173-1-git-send-email-jiazhouyang09@gmail.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 v1->v2: - Fix dereferencing before checking. v2->v3: - Use xenbus_dev_error to report errors. v3->v4: - Fix compilation errors. v4->v5: - Fix compilation errors. Reviewed-by: Juergen Gross --- drivers/scsi/xen-scsifront.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c index 36f59a1..61389bd 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); + 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) { + xenbus_dev_error(info->dev, err, + "%s: writing dev_state_path", __func__); + 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); + 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); + if (err) + xenbus_dev_error(info->dev, err, + "%s: writing dev_state_path", __func__); + } } static struct scsi_host_template scsifront_sht = { @@ -1003,9 +1015,12 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op) if (scsi_add_device(info->host, chn, tgt, lun)) { dev_err(&dev->dev, "scsi_add_device\n"); - xenbus_printf(XBT_NIL, dev->nodename, + err = xenbus_printf(XBT_NIL, dev->nodename, info->dev_state_path, "%d", XenbusStateClosed); + if (err) + xenbus_dev_error(dev, err, + "%s: writing dev_state_path", __func__); } break; case VSCSIFRONT_OP_DEL_LUN: @@ -1019,10 +1034,14 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt_info *info, int op) } break; case VSCSIFRONT_OP_READD_LUN: - if (device_state == XenbusStateConnected) - xenbus_printf(XBT_NIL, dev->nodename, + if (device_state == XenbusStateConnected) { + err = xenbus_printf(XBT_NIL, dev->nodename, info->dev_state_path, "%d", XenbusStateConnected); + if (err) + xenbus_dev_error(dev, err, + "%s: writing dev_state_path", __func__); + } break; default: break;