From patchwork Thu Nov 10 02:55:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 13038257 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 E397DC43217 for ; Thu, 10 Nov 2022 02:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbiKJC5F (ORCPT ); Wed, 9 Nov 2022 21:57:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232635AbiKJC5E (ORCPT ); Wed, 9 Nov 2022 21:57:04 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C4623E8D for ; Wed, 9 Nov 2022 18:57:03 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N75yH6NvMzJnZf; Thu, 10 Nov 2022 10:53:59 +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; Thu, 10 Nov 2022 10:57:00 +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, 10 Nov 2022 10:57:00 +0800 From: Yang Yingliang To: CC: , Subject: [PATCH v4 1/2] mmc: sdio: fix of node refcount leak in sdio_add_func() Date: Thu, 10 Nov 2022 10:55:29 +0800 Message-ID: <20221110025530.4106568-2-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221110025530.4106568-1-yangyingliang@huawei.com> References: <20221110025530.4106568-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-mmc@vger.kernel.org If device_add() returns error in sdio_add_func(), sdio function is not presented, so the node refcount that hold in sdio_set_of_node() can not be put in sdio_remove_func() which is called from error path. Fix this by moving of_node_put() before present check in remove() function. Fixes: 25185f3f31c9 ("mmc: Add SDIO function devicetree subnode parsing") Signed-off-by: Yang Yingliang --- drivers/mmc/core/sdio_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c index babf21a0adeb..266639504a94 100644 --- a/drivers/mmc/core/sdio_bus.c +++ b/drivers/mmc/core/sdio_bus.c @@ -377,11 +377,11 @@ int sdio_add_func(struct sdio_func *func) */ void sdio_remove_func(struct sdio_func *func) { + of_node_put(func->dev.of_node); if (!sdio_func_present(func)) return; device_del(&func->dev); - of_node_put(func->dev.of_node); put_device(&func->dev); }