Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp450249imm; Wed, 13 Jun 2018 03:10:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIETCC7wb2esRHyFo1UTDlorLAvU4yY74M+lY7A8rvzXxjJfelDEN6FVnxrwJ9gvxdkK3AY X-Received: by 2002:a62:8202:: with SMTP id w2-v6mr4304188pfd.32.1528884650029; Wed, 13 Jun 2018 03:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528884650; cv=none; d=google.com; s=arc-20160816; b=hNK/B5Oxpsj37/hlaCcuEIJFHr1NGTFemUuFRqlp6xAt79VUER6zYG10h2aFLndjRy aeOJHG8g11/ogBAt0vUr3tPfca+LZiQUjwjFCupEfjSQtuqxIubGLROXfAUp0GXROZHS V4QvNEEvtR4TC5dtHGycx7IwAwM8XVZiqqbLQ0pKInVou0rFK3UgNoluD7HqIUuxCIGt OVjQz9OYZ9c77+/1bYMQJ9YxQMWAESd7WmpJakRBxCh2AQLmFqrh/NGHmgOztSUfctaI vBIogqwigijtYwPwPLR7XQg2aPLcDKo92UoEN99Fbcs2ReAjcRr+awf1zM5smk4jg2rw KMBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date:arc-authentication-results; bh=QfCyIzqWKu+RtCs+iYPuyol8OgbXF0oyzrT1iYwz9xE=; b=KVPKyGIFd2uigLVMPaRaHkSSwTq09Jyd3/kn4Z3B3+ke+BiuCm6KM+tpVz9gOfL6a5 7CsSQZqGVvdC4dVRlIJPk3gESaPD50TbSg8fVqkdLcG0RPO0S8judl2m8H2ksndYFSJB htgz1/EDs9c3RasZ8WtaVgTFSviL+6F1/BKUuN7KIwmoNUHrM5CD2T37wtga3czzzLFJ GaqWNr6mVYBqQ2lM2+0njrzbaLtloEZf8Zn5OUxPft/MJahpobyWFTx/VOaaOwLZY57O VjJjjIGxofowS4X1yPg8hC3Zt3+CCxM07eKztL48OdNdP5xMgkSpbn3rw4UZDCp85nVa PQlg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o26-v6si1955986pge.307.2018.06.13.03.10.35; Wed, 13 Jun 2018 03:10:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935132AbeFMKJT (ORCPT + 99 others); Wed, 13 Jun 2018 06:09:19 -0400 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47426 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934978AbeFMKJS (ORCPT ); Wed, 13 Jun 2018 06:09:18 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by kvm5.telegraphics.com.au (Postfix) with ESMTP id 5918824672; Wed, 13 Jun 2018 06:09:16 -0400 (EDT) Date: Wed, 13 Jun 2018 20:09:51 +1000 (AEST) From: Finn Thain To: Zhouyang Jia cc: 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: Re: [PATCH] scsi: xen-scsifront: add error handling for xenbus_printf In-Reply-To: <1528774962-39173-1-git-send-email-jiazhouyang09@gmail.com> Message-ID: References: <1528774962-39173-1-git-send-email-jiazhouyang09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Jun 2018, 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 > --- > drivers/scsi/xen-scsifront.c | 31 ++++++++++++++++++++++++------- > 1 file changed, 24 insertions(+), 7 deletions(-) > > diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c > index 36f59a1..3d858ac 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); > + struct xenbus_device *dev = info->dev; > + 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); The existing code checks whether 'info' is NULL before dereferencing it. But your patch checks for NULL after dereferencing. > + if (err) { > + dev_err(&dev->dev, "writing dev_state_path\n"); > + 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); > + struct xenbus_device *dev = info->dev; > + 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); Same here. > + if (err) > + dev_err(&dev->dev, "writing dev_state_path\n"); > + } > } > > static struct scsi_host_template scsifront_sht = { --