From patchwork Wed Nov 2 09:31:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 13027933 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 514B8C4332F for ; Wed, 2 Nov 2022 09:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229949AbiKBJcb (ORCPT ); Wed, 2 Nov 2022 05:32:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiKBJca (ORCPT ); Wed, 2 Nov 2022 05:32:30 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F95103A for ; Wed, 2 Nov 2022 02:32:29 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N2M9N6T24zHvV3; Wed, 2 Nov 2022 17:32:08 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 2 Nov 2022 17:32:27 +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; Wed, 2 Nov 2022 17:32:27 +0800 From: Yang Yingliang To: CC: Yang Yingliang , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH] scsi: raid_class: fix possible memory leak in raid_component_add() Date: Wed, 2 Nov 2022 17:31:12 +0800 Message-ID: <20221102093112.2678-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 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 Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array"), the name of device is allocated dynamically, it need be freed if device_add(&rc->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(). In raid_component_release(), it will put refcount of component_dev and free 'rc', so the release code of them in error path can be removed. Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array") Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Signed-off-by: Yang Yingliang --- drivers/scsi/raid_class.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c index 898a0bdf8df6..86ed1f66d749 100644 --- a/drivers/scsi/raid_class.c +++ b/drivers/scsi/raid_class.c @@ -250,8 +250,7 @@ int raid_component_add(struct raid_template *r,struct device *raid_dev, err_out: list_del(&rc->node); rd->component_count--; - put_device(component_dev); - kfree(rc); + put_device(&rc->dev); return err; } EXPORT_SYMBOL(raid_component_add);