From patchwork Thu Nov 3 12:59:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 622005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F267BC433FE for ; Thu, 3 Nov 2022 13:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbiKCNBg (ORCPT ); Thu, 3 Nov 2022 09:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231571AbiKCNB0 (ORCPT ); Thu, 3 Nov 2022 09:01:26 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91AF11C27 for ; Thu, 3 Nov 2022 06:01:16 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N33fR149nzRnsb; Thu, 3 Nov 2022 20:56:15 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 3 Nov 2022 21:01:14 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 3 Nov 2022 21:01:14 +0800 From: Yang Yingliang To: CC: Yang Yingliang , Karan Tilak Kumar , Sesidhar Baddela , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH 1/2] scsi: snic: fix possible memory leak in snic_tgt_create() Date: Thu, 3 Nov 2022 20:59:37 +0800 Message-ID: <20221103125938.124819-2-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103125938.124819-1-yangyingliang@huawei.com> References: <20221103125938.124819-1-yangyingliang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The device name allocated by dev_set_name() in snic_tgt_create() needs be freed if device_add(&tgt->dev) returns error, as comment of device_add() says, it should call put_device() to drop the reference on error. Fix it by calling put_device(&rc->dev), so that the name can be freed in kobject_cleanup(). The 'tgt' is freed in snic_tgt_dev_release(), so kfree() in error path can be removed. Fixes: c8806b6c9e82 ("snic: driver for Cisco SCSI HBA") Cc: Karan Tilak Kumar Cc: Sesidhar Baddela Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Signed-off-by: Yang Yingliang --- drivers/scsi/snic/snic_disc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c index 9b2b5f8c23b9..031c27d8510f 100644 --- a/drivers/scsi/snic/snic_disc.c +++ b/drivers/scsi/snic/snic_disc.c @@ -304,10 +304,8 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid) ret); put_device(&snic->shost->shost_gendev); - kfree(tgt); - tgt = NULL; - - return tgt; + put_device(&tgt->dev); + return NULL; } SNIC_HOST_INFO(snic->shost, "Scanning %s.\n", dev_name(&tgt->dev)); From patchwork Thu Nov 3 12:59:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 621333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6358C4321E for ; Thu, 3 Nov 2022 13:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231771AbiKCNB4 (ORCPT ); Thu, 3 Nov 2022 09:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbiKCNBu (ORCPT ); Thu, 3 Nov 2022 09:01:50 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C9B14D10 for ; Thu, 3 Nov 2022 06:01:22 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N33hx0nXwzJnL5; Thu, 3 Nov 2022 20:58:25 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 3 Nov 2022 21:01:20 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 3 Nov 2022 21:01:19 +0800 From: Yang Yingliang To: CC: Yang Yingliang , Karan Tilak Kumar , Sesidhar Baddela , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH 2/2] scsi: snic: fix refcount leak of shost_gendev in normal path Date: Thu, 3 Nov 2022 20:59:38 +0800 Message-ID: <20221103125938.124819-3-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103125938.124819-1-yangyingliang@huawei.com> References: <20221103125938.124819-1-yangyingliang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The refcount of shost_gendev is get snic_tgt_create(), but it has never been put while module exiting in normal path, so add put_device() in snic_tgt_dev_release() to avoid refcount leak. Fixes: c8806b6c9e82 ("snic: driver for Cisco SCSI HBA") Cc: Karan Tilak Kumar Cc: Sesidhar Baddela Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Signed-off-by: Yang Yingliang --- drivers/scsi/snic/snic_disc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c index 031c27d8510f..d0759391ed1e 100644 --- a/drivers/scsi/snic/snic_disc.c +++ b/drivers/scsi/snic/snic_disc.c @@ -198,6 +198,7 @@ snic_tgt_dev_release(struct device *dev) dev_name(dev)); SNIC_BUG_ON(!list_empty(&tgt->list)); + put_device(dev->parent); kfree(tgt); } @@ -303,7 +304,6 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid) "Snic Tgt: device_add, with err = %d\n", ret); - put_device(&snic->shost->shost_gendev); put_device(&tgt->dev); return NULL; }