Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4185816rwl; Mon, 3 Apr 2023 00:51:28 -0700 (PDT) X-Google-Smtp-Source: AKy350b3YB/dmqEzLA2oULc80FEU+hsgqiyMTbC0URtxMd9GQd5TFz9ChuexH6MD6iLL5MjHUPUj X-Received: by 2002:a17:906:2db2:b0:92b:f0d9:15f3 with SMTP id g18-20020a1709062db200b0092bf0d915f3mr16084901eji.37.1680508288634; Mon, 03 Apr 2023 00:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680508288; cv=none; d=google.com; s=arc-20160816; b=W5x8R+HGvjZFDKGUX2VbhEZiYt057t9ZlL+NQ7U9LgRXAR9ZPiJGr1tx1ZiHs7ZuNb 2yTfTxGAk0MKA0vQ3ddrOKHGZCwL7xUJEpxH7p7NyxEWTdHjPYZuLRukIpfTr8nIXNza BiGK0tmPFRTgNieENOmQ+50WuYYIKpQBhyC3SJ+ursZeXnbVXjuouLVw21VeAkR1+qzd u+UKnOvdh+rDUozru367W1hiJQgsiF7ieNk6C8c8wfqbz6OOuextGJcSUEa/v49kDTdY gGmNfkkZJCFAVFqqg8SpbzjR6f/lK2lTke/erJvDvVkQwwHG23p0w464ieMRIrA1cJAw a68A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=FjjirENKwYNiiOp3jk4lYHoYmxLtvNmJuimFgjP20FE=; b=fjiQhtlr9vNDn9hQG7Odm7gCPdlO1g2xf5QrWIPIZ2QeClRHQ3dVA8D/ixWFLSH9KB 2RKct6Y8s8vhlh+/SvGE/z0uC4AKRpesEmtU3aeM/idyAEDcIx0BcZON4xX0MnIrRujz DGyJomv1DlDsv6PjVbxljsh4ZCqzRNt5vEdi8Vfu3U7HPM5fr8cFX1UP6/1NAux8EY/r YRFGpAxFgIWfQ62VRr62j/VXtEmAGZBFslTPo6Zq1HMt/UE07tjyPvCfMdoi+TFnBEws Om/F30Gle1q4NyztxeOzDo7J5qQ3suEzFtp3GpZz/xaXaNhwaaS0haKj9fgXB2uQ9lsE 47Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020a17090632da00b009333705a9edsi6390868ejk.746.2023.04.03.00.51.03; Mon, 03 Apr 2023 00:51:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbjDCHtI (ORCPT + 99 others); Mon, 3 Apr 2023 03:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231678AbjDCHtB (ORCPT ); Mon, 3 Apr 2023 03:49:01 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BA844AE; Mon, 3 Apr 2023 00:48:59 -0700 (PDT) Received: from DESKTOP-7O4H7L3.localdomain ([10.12.183.64]) (user=lishuchang@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 3337mgo2026190-3337mgo3026190 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 3 Apr 2023 15:48:42 +0800 From: lishuchang@hust.edu.cn To: James Smart , Dick Kennedy , "James E.J. Bottomley" , "Martin K. Petersen" Cc: hust-os-kernel-patches@googlegroups.com, Shuchang Li , Dongliang Mu , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup' Date: Mon, 3 Apr 2023 15:48:21 +0800 Message-Id: <20230403074821.5121-1-lishuchang@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: lishuchang@hust.edu.cn X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shuchang Li When if_type equals to zero and pci_resource_start(pdev, PCI_64BIT_BAR4) returns false, drbl_regs_memmap_p is not remapped. However, in the code it goes to out_iounmap_all, where drbl_regs_memmap_p is unmapped. This may cause some problems. When if_type equals to six and pci_resource_start(pdev, PCI_64BIT_BAR4) returns true, drbl_regs_memmap_p may has been remapped and ctrl_regs_memmap_p is not remapped. However in the code it goes to out_iounmap_ctrl, where ctrl_regs_memmap_p is unmapped and drbl_regs_memmap_p is not unmapped. This may cause a leak and some other problems. To fix these issues, we need to add null checks before iounmap(), and change some goto lables. Signed-off-by: Shuchang Li Reviewed-by: Dongliang Mu --- drivers/scsi/lpfc/lpfc_init.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 4f7485958c49..bd5e734487e3 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12026,7 +12026,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) goto out_iounmap_all; } else { error = -ENOMEM; - goto out_iounmap_all; + goto out_iounmap_ctrl; } } @@ -12044,7 +12044,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) dev_err(&pdev->dev, "ioremap failed for SLI4 HBA dpp registers.\n"); error = -ENOMEM; - goto out_iounmap_ctrl; + goto out_iounmap_all; } phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; } @@ -12069,9 +12069,11 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) return 0; out_iounmap_all: - iounmap(phba->sli4_hba.drbl_regs_memmap_p); + if (!phba->sli4_hba.drbl_regs_memmap_p) + iounmap(phba->sli4_hba.drbl_regs_memmap_p); out_iounmap_ctrl: - iounmap(phba->sli4_hba.ctrl_regs_memmap_p); + if (!phba->sli4_hba.ctrl_regs_memmap_p) + iounmap(phba->sli4_hba.ctrl_regs_memmap_p); out_iounmap_conf: iounmap(phba->sli4_hba.conf_regs_memmap_p); -- 2.25.1