Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp90253imm; Thu, 14 Jun 2018 16:00:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLmhmAIfk1n1Dj5kv2XyvmlffOjn8alMHyoEYRYKOEWDeB0REMUjcT7GJIFYW1wlpqMwTZv X-Received: by 2002:a62:1bc2:: with SMTP id b185-v6mr11416521pfb.225.1529017237035; Thu, 14 Jun 2018 16:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529017237; cv=none; d=google.com; s=arc-20160816; b=iD6cdFCOGgYJhbRJNDOy1IR3kdwlpspw5cFhbZNq7vJhWQ47Bp2OppvmwUZ07+0/BR s5A4MLkOeXKznABHxc5YfEIB356N+iUu1cjk23Az6HQWGjaeOE6ywQtBAVhPgp/6Xygw 4qSwM0A/4R62vKlPxavaH3U7js45Ofk9iu1j14v96TrqW8Bm4yBGqY3BiL+YHsS9jsso FKkobaX6jpYkJaiMMx4zYkrlqd0HJ0Efkz/sPzgvA1TfWWKc0TFtyKATnFRh3ufp0XBh cy7Ofa7hmP9T7mAwHJUDJWBbdEpXicjGQNuQ5DlQVnXyauuHC9fYCFsLma4PC9FJprzb /Clg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature:arc-authentication-results; bh=8fAUVQ4DeolZcnrng4lwqlH6/zv84TJiAWY8EFRywiw=; b=qniAjwBuWMJ/Y0UeCIk5NVmnxIF+ZToWHmEIL3FnPhuf9Bv+4pNu/K6UXQrx3GHd0H 2qnLItEGYZVEbF1BSP/5xPZQO8Lvjx2jIQ6MJvSAfLtcWhnmRhFWy8fYK9d98pp8m6Fk 8orVspJi+LdTukgEE8h15t8a6Jpqpb1oyLP4JXFLK2oI8pr77yTvPxfnKfoRFP53rXwS yncSIDEXVN9o3GOljtWqjXYqokylxePsVh4IOM7baprshDRGGUXwgxDxi+zNxMbQZLQ7 +texxeqpmc3CW42WFPb3AE/jqVc3ybHBlc+Lwx2xbdB0hhOnHUr/3cMKk0YwUezhj1lG Tj/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="m/kuTaYX"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17-v6si6147528plo.355.2018.06.14.16.00.22; Thu, 14 Jun 2018 16:00:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="m/kuTaYX"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965130AbeFNW71 (ORCPT + 99 others); Thu, 14 Jun 2018 18:59:27 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:35138 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965006AbeFNW7Z (ORCPT ); Thu, 14 Jun 2018 18:59:25 -0400 Received: by mail-pl0-f66.google.com with SMTP id k1-v6so4336370plt.2; Thu, 14 Jun 2018 15:59:25 -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=8fAUVQ4DeolZcnrng4lwqlH6/zv84TJiAWY8EFRywiw=; b=m/kuTaYXhgRoiUihJGFnw/lzPkOZqpiO5ynJ9mxE0HgdBkW1a/9soKzgLjsa7/igBG 7fm/1sh3OKZAGVUZqBf71TxfpiRY+2HrCwAPhlnLKzaGbxe8BChQnXfa8gddZAlBegp4 xuOvuMafO8A8CiwnptL99+/pwx3hGXroKooeGS6egeD7faSojE70xnHzVyzNJ02qZegO ut6whoDnw0wiW/RhFfJJ+5tL0aXiqhzzaN4wh7izgH5plJCtuPOGil/9slP+IsVIGTut uHHc718wADBvklt4VXXdzGFYDD5XVHhPX5Qu55ehsWTmX5QwwYKELGQ59RBzKOxOro4i ea1g== 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=8fAUVQ4DeolZcnrng4lwqlH6/zv84TJiAWY8EFRywiw=; b=eN5y0QuTgk6rYcjvNCcIhR1crQJkREUDOu6iOHfimCz/R/gJ6qYOPaCwTUKHm9smh4 2w22vtCjOR/EQVAuuUuWlS/arY8fPbssjnfZQOWnga2N10mjOw1W/c9ZCPhChvJPMnGk b3szcn4lD7pbxEqkJltW1YJH1Wh8qbBh/7tf/1/ncqcHQN8quNUbi4ApdOoOr/34/CT5 bdPioxD/kQqFoGCLAPCLmxgvKTAcKvgE0Uknujf/+eS9VXSPSOYp8QFfmjHzIjiZa8J7 6qOZSvXg9jcYVRKIUQynoovsYR2istg91bbxEsyex8TLFtwT05KSEoT+BkCXakpfeNhb dAfw== X-Gm-Message-State: APt69E02ODRTdXB117gz2TXSlHt9AWXchFxwfWz1xjDMp/4s2nTN+h1w M0bHv9W2BT/WsMGdVs2KBhRkqRQ/h/4= X-Received: by 2002:a17:902:321:: with SMTP id 30-v6mr5206747pld.122.1529017165139; Thu, 14 Jun 2018 15:59:25 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id b72-v6sm12671743pfj.56.2018.06.14.15.59.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 15:59:24 -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 v3] scsi: xen-scsifront: add error handling for xenbus_printf Date: Fri, 15 Jun 2018 06:59:14 +0800 Message-Id: <1529017154-54719-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. --- 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..644d1ce 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->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->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->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->dev, err, + "%s: writing dev_state_path", __func__); + } break; default: break; -- 2.7.4