Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5317303imm; Tue, 19 Jun 2018 08:30:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL9xazndUs3bGiv9izUzhvcyGxuxDYeEDuchEzlpcCYLdlJCw72nu28F4aYBTkuO1FXQZID X-Received: by 2002:a63:7a07:: with SMTP id v7-v6mr15195720pgc.444.1529422217763; Tue, 19 Jun 2018 08:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529422217; cv=none; d=google.com; s=arc-20160816; b=E2aHD+Styjms4o6mB9IwsFUrUXijaN4NdblBvAPG3v7UQJd8TnacAGVhgmpW9ddfSE LcZk9FnWVblnzG+9dzNTWKztZJC+1tOOrb1YCEfQVq6fa4vH10BzUxJhpreCNUiKmr/L WNC3REJPT79BTreTdjtK/n5+r0peyh+8WtkFRapqHicK2F3N/IfXiHt13sfC/52JOTVy Bht/W9n/RLzjJNl0jGZBRRAMJfB0+e6NcUPxxbuV/hT0wjgjjKZFvCPyFhzbpMTrlzii 0Owc+/L0kJebw6/jQiqzh3Kg+bVgrFE/Ftyg5xuuRiLbOXViKqgJlwG36Iw02PABC4yJ IDrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:arc-authentication-results; bh=3VMOT6Jseh8RLLSuROfmHbPAXUj6wlINIoihM8/Jk6E=; b=lR+3WVxtD3/1VsSGIwHlzZ6Gv//jZiAwosh9VqTgXT2P2esr90zyjRPGMA/j90wihv VAUA5fzUIdi7NUouMlE+pIUfLEAA8albpVShopGvqlh7DPgNDZZz/SOr7HYNHRHZlr/J dF2Bu0EIlWcvbKo0zCqXxHMoukZRilstkcE25RmiQvOFITRfvL+6iy/fB/4ChcRFpVP1 mAc3YlnJGAopLIOollZwkFt6SocSlJwHZT5iXuNyqS/7eJjtRkKskd5dydmUKzQFU14v bfinfoIhneguwDixb1pQjwsfcX0X/wUTr0hxvW30Q7+7gKtFJ6azbC8sQV5WBYkHnWKF plVw== 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 c8-v6si14189754pgv.443.2018.06.19.08.30.04; Tue, 19 Jun 2018 08:30:17 -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 S966694AbeFSP3I (ORCPT + 99 others); Tue, 19 Jun 2018 11:29:08 -0400 Received: from bran.ispras.ru ([83.149.199.196]:10430 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965953AbeFSP3F (ORCPT ); Tue, 19 Jun 2018 11:29:05 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 568ED203B2; Tue, 19 Jun 2018 10:02:09 +0300 (MSK) From: Anton Vasilyev To: Dan Carpenter Cc: Anton Vasilyev , Greg Kroah-Hartman , Andy Shevchenko , Sinan Kaya , Johannes Thumshirn , Gaurav Pathak , Hannes Reinecke , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH v4] staging: rts5208: add error handling into rtsx_probe Date: Tue, 19 Jun 2018 18:25:24 +0300 Message-Id: <20180619152524.6080-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619074248.ssu5kza6wdwhzdqi@mwanda> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If rtsx_probe() fails to allocate dev->chip, then release_everything() will crash on uninitialized dev->cmnd_ready complete Patch adds error handling into rtsx_probe. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- v4: rename labels baced on Dan Carpenter's recommendation v3: fix subject and commit message v2: Add error handling into rtsx_probe based on Dan Carpenter's comment. I do not have corresponding hardware, so patch was tested by compilation only. I faced with inaccuracy at rtsx_remove() and original rtsx_probe(): there is quiesce_and_remove_host() call with scsi_remove_host() inside, whereas release_everything() calls scsi_host_put() after this scsi_remove_host() call. This is strange for me. Also I do not know is it require to check result value of rtsx_init_chip() call on rtsx_probe(). --- drivers/staging/rts5208/rtsx.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/staging/rts5208/rtsx.c b/drivers/staging/rts5208/rtsx.c index 70e0b8623110..233026ee5dd4 100644 --- a/drivers/staging/rts5208/rtsx.c +++ b/drivers/staging/rts5208/rtsx.c @@ -879,7 +879,7 @@ static int rtsx_probe(struct pci_dev *pci, if (!dev->remap_addr) { dev_err(&pci->dev, "ioremap error\n"); err = -ENXIO; - goto errout; + goto err_chip_free; } /* @@ -894,7 +894,7 @@ static int rtsx_probe(struct pci_dev *pci, if (!dev->rtsx_resv_buf) { dev_err(&pci->dev, "alloc dma buffer fail\n"); err = -ENXIO; - goto errout; + goto err_addr_unmap; } dev->chip->host_cmds_ptr = dev->rtsx_resv_buf; dev->chip->host_cmds_addr = dev->rtsx_resv_buf_addr; @@ -915,7 +915,7 @@ static int rtsx_probe(struct pci_dev *pci, if (rtsx_acquire_irq(dev) < 0) { err = -EBUSY; - goto errout; + goto err_disable_msi; } pci_set_master(pci); @@ -935,14 +935,14 @@ static int rtsx_probe(struct pci_dev *pci, if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start control thread\n"); err = PTR_ERR(th); - goto errout; + goto err_rtsx_release; } dev->ctl_thread = th; err = scsi_add_host(host, &pci->dev); if (err) { dev_err(&pci->dev, "Unable to add the scsi host\n"); - goto errout; + goto err_complete_control_thread; } /* Start up the thread for delayed SCSI-device scanning */ @@ -950,18 +950,16 @@ static int rtsx_probe(struct pci_dev *pci, if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start the device-scanning thread\n"); complete(&dev->scanning_done); - quiesce_and_remove_host(dev); err = PTR_ERR(th); - goto errout; + goto err_stop_host; } /* Start up the thread for polling thread */ th = kthread_run(rtsx_polling_thread, dev, "rtsx-polling"); if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start the device-polling thread\n"); - quiesce_and_remove_host(dev); err = PTR_ERR(th); - goto errout; + goto err_stop_host; } dev->polling_thread = th; @@ -970,9 +968,25 @@ static int rtsx_probe(struct pci_dev *pci, return 0; /* We come here if there are any problems */ +err_stop_host: + quiesce_and_remove_host(dev); +err_complete_control_thread: + complete(&dev->cmnd_ready); + wait_for_completion(&dev->control_exit); +err_rtsx_release: + free_irq(dev->irq, (void *)dev); + rtsx_release_chip(dev->chip); +err_disable_msi: + dev->chip->host_cmds_ptr = NULL; + dev->chip->host_sg_tbl_ptr = NULL; + if (dev->chip->msi_en) + pci_disable_msi(dev->pci); +err_addr_unmap: + iounmap(dev->remap_addr); +err_chip_free: + kfree(dev->chip); errout: dev_err(&pci->dev, "%s failed\n", __func__); - release_everything(dev); return err; } -- 2.17.1