From patchwork Mon Jun 3 09:22:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 10972633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1133F13AD for ; Mon, 3 Jun 2019 09:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0150D28438 for ; Mon, 3 Jun 2019 09:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E96D628928; Mon, 3 Jun 2019 09:23:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9132B28438 for ; Mon, 3 Jun 2019 09:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727161AbfFCJXN (ORCPT ); Mon, 3 Jun 2019 05:23:13 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:18071 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726684AbfFCJXN (ORCPT ); Mon, 3 Jun 2019 05:23:13 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A676135D6334608C5412; Mon, 3 Jun 2019 17:23:11 +0800 (CST) Received: from localhost (10.133.213.239) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Mon, 3 Jun 2019 17:23:03 +0800 From: YueHaibing To: , , , , CC: , , YueHaibing Subject: [PATCH] scsi: fcoe: Fix possible memleak in fcoe_if_init Date: Mon, 3 Jun 2019 17:22:18 +0800 Message-ID: <20190603092218.15064-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.133.213.239] X-CFilter-Loop: Reflected Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If it fails to alloc fcoe_vport_scsi_transport in fcoe_if_init, we should check the err and free allocted fcoe_nport_scsi_transport. Also return ENOMEM instead of ENODEV. Fixes: 8ca86f84dd5f ("[SCSI] fcoe: prepare fcoe for using fcoe transport") Signed-off-by: YueHaibing --- drivers/scsi/fcoe/fcoe.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c index 8ba8862..12ca0b7 100644 --- a/drivers/scsi/fcoe/fcoe.c +++ b/drivers/scsi/fcoe/fcoe.c @@ -1262,12 +1262,17 @@ static int __init fcoe_if_init(void) /* attach to scsi transport */ fcoe_nport_scsi_transport = fc_attach_transport(&fcoe_nport_fc_functions); + if (!fcoe_nport_scsi_transport) + return -ENOMEM; + fcoe_vport_scsi_transport = fc_attach_transport(&fcoe_vport_fc_functions); - if (!fcoe_nport_scsi_transport) { - printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); - return -ENODEV; + if (!fcoe_vport_scsi_transport) { + pr_err("fcoe: Failed to attach to the FC transport\n"); + fc_release_transport(fcoe_nport_scsi_transport); + fcoe_nport_scsi_transport = NULL; + return -ENOMEM; } return 0;