Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp220822imm; Thu, 14 Jun 2018 18:49:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLf1bq31b2JnDRXygzRJm5ypRMcLCiiqITItiKQXRqU0P8vwr9Kq+3LaM1lHIkL2ZsbseYd X-Received: by 2002:a65:4545:: with SMTP id x5-v6mr4383307pgr.4.1529027360426; Thu, 14 Jun 2018 18:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529027360; cv=none; d=google.com; s=arc-20160816; b=FjU6QY3L0sG4jPJotiFI44HDHIqsZYaHe3EwDBWvY/yWAGqjTaGrRqoyCr+4dqoPNn PfcCQCUunKVLp46DrRpk69tS79ko6sMD33c5Gg+Bluh+gbK0szBkJenQLdQf5a6TqSWe QhGwhvESSfXPmo92aTAp0zqkZBEHa8mLZCmYc0Sy9Z102QsLTHLsCMQYqlNTAZNrfakN YKUtjVynITElmccHza3AiQ0HNuK/YsxvvoMQxV7Q3dTDpfEAXOg6NqQrNCI0Pye9zmrD AyjRKN/yYx1+YV08i/DGw8cOfYP8Z6wewlnXJaegUvibsUpK/1JTTcIZzWhC1YyfhWaG yHcg== 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=5IDqLLSuFvPXhP6vbXsap7z0cXiIu0GiqFE9AYSI/iw=; b=XztlymB88HHVv563ZVn5fsDqgBReU7AorSdwhNh2JGUI2goX88aDKZ+n3HGV/xNEAd sTHjWY62mttXoZErrI/7NHFrbph+yst414MolA3RLFzk1zsbip1fqsdMlTPYOgfwT67f rf41WMVmHvyos1UBLrkjX9iUJGcUCHudc7Z8wZ423Uxv4TQdrIZ5DX2eCu3IthZyFMOA 6/rNLQ4jhODE/y+mltYA7QBDsDNtdAXekqrdE9MlBm74GrjeEpLX+w1muLS4t92Seobj lUUmkhAYSV9JeQXGH6sb1TgLwYIeBA3Ik/yWAP+JD8RH6sHDGP7OaVVacOMkG/SrK/3a yCCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RN2huSvU; 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 n15-v6si5764920pgf.45.2018.06.14.18.49.04; Thu, 14 Jun 2018 18:49:20 -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=RN2huSvU; 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 S965296AbeFOBsk (ORCPT + 99 others); Thu, 14 Jun 2018 21:48:40 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:45536 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965018AbeFOBsi (ORCPT ); Thu, 14 Jun 2018 21:48:38 -0400 Received: by mail-pl0-f68.google.com with SMTP id c23-v6so4500460plz.12; Thu, 14 Jun 2018 18:48:38 -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=5IDqLLSuFvPXhP6vbXsap7z0cXiIu0GiqFE9AYSI/iw=; b=RN2huSvU6tZfODSlZFZ2GYMPFYleUx5sqeqkd2B/ap14hEBDeEyxXXJgI/62tgf70l lmDXW0u7GrSObmbJKBmS0wyHkJaFDizzA3+uk4qw70FJXYhgnO4MR/qn0HUvvKRChxNy TzxAONWXA3noXbDxHqeN7/4ro5AYK0QXuVy+IThVWQG/agJM1KpX2tJgtI1PwJtZM63H tQNNFNcyqYWJ1vt56lw/N5mgfORYCc8EXMNwL5eixQMHEpf1Rqa8xFd0x1d/7GlPNyvF winOfJAGdHji6MsZXYvrWEdoIjn6lYZOBa2evPnHkk+Lub/csc5T2r3c+CAHlb9atMOd 2aeg== 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=5IDqLLSuFvPXhP6vbXsap7z0cXiIu0GiqFE9AYSI/iw=; b=exSt9HDdsxJPABK79jb6sIF7ZYYXfTajGzQh3Mhy7ZXCGHRqWcHs5FBs7Bqa06lSLM dn+3CZsObnQinxjZB9PXgRmvvdnoRqESuf/aQycDzACt+VNXW0VIPW36ZR5LhJLESIl+ xB3TliOKUHV82aN9HYV6tJJXlM1xnMIaa04J79U8nf1PUYkRiNCwD4HWwYz8TZTrE5Us kClNnuQF6O2SW3Q605q6+Rarmoz1ltfNcTmXRHae1VKLRntxMCyQJPnP0YKReBSzt/Kh 9bXXCDjNHw4DHF0+Y88tGOW3o5LOc4fD6HS1i82jPKP4riAGendcD4psn2J/EjCf2Q3W phSA== X-Gm-Message-State: APt69E0i7LPsq6q5lsvRPD08TUTfmHC+HbBoPyFtHkmNNJOpIFyMyPFX gCd/84LYfHCnnr/F08kXeVM= X-Received: by 2002:a17:902:820a:: with SMTP id x10-v6mr5573426pln.179.1529027318258; Thu, 14 Jun 2018 18:48:38 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id g8-v6sm2229628pgq.69.2018.06.14.18.48.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 18:48:37 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Boris Ostrovsky , Juergen Gross , "James E.J. Bottomley" , "Martin K. Petersen" , xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] scsi: xen-scsifront: add error handling for xenbus_printf Date: Fri, 15 Jun 2018 09:48:31 +0800 Message-Id: <1529027312-56770-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. v3->v4: - Fix compilation 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..be576cb 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; -- 2.7.4