From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEAB1C433EF for ; Tue, 14 Dec 2021 04:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=GhCtRbsiI+rR06tvJbGM/yYhZv/vLAycFsh3ekAamek=; b=tAT hiY9hlTLWfsAlThWt4ZwPmUvhRkPursOyP+eW4K8wVQYHd+8Ip407753ghg5DIlPxQVtShw9Wn2+V BFxV8VMKKZ6EbmKqi+7Tz8T68O0v1xJQ4c9KY+cwwLWGIYb+zPOVo71HIn3Qb2/UrQ8mzF+SeDuBj K+iSVIN6ngmJ/whj8KiDuurVRpPfCTIlJ2s2yUctQdF0aWhFc7EbsIEEvmYZsbRi2AxCOxGwVVccO oIhk2mdchAfOGkN9bZPJ3aciPZqqnSAbPIeQZmZhb8D9mJZMk3kHdXQLNitXGUq+hGbUTqEFsucK8 JzNx94MA9CUakNeMrvbIWhBmIDHzByA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwyzk-00CTyU-RF; Tue, 14 Dec 2021 04:00:52 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwyzg-00CTvM-LY for linux-mediatek@lists.infradead.org; Tue, 14 Dec 2021 04:00:50 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id t1-20020a5b03c1000000b005f6ee3e97easo33863040ybp.16 for ; Mon, 13 Dec 2021 20:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=KUYS2WNmggkO20Zmll03I/4/wpE7LncoJnK+g8c522aQ0VOShYg1J2Zo7mtzyNtyfZ 7O1vdzMeRIzfVqbNOx79k5MrU00AsFWLDP+xAhU/26ztWIzyuPUDq6okL56jpphkJO64 /k5O16IEiN8GX4DB+CuYBrEW5FWA0XkheykantgllsCRhOcKIm564bkQ57pEyMbVAJ49 UZyN/It4QGdOC/f9Suqq/S2kqJ1BWqGM+9eU3eeVORznoO7+N3x7fdE0WoWptYJklfyH dliehqZjJWM8NEXPHDlGSmxOKD7qClfbSeSVgiXVFXQtEvTWF+2bQx1YT1QOevXM9s7h +I0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=yz0wk+btQ3d9/3UCcu1O1NWTas+pPEFJeELSu30lACAlYU43DhRFoqc44SpvxaPkdb thUzI+5qNkmoR8UnFW66xlcx7B6XqyNxbDWA5IwxsPpoHqnICcODIhFvo324C0t2iwJc 8fNY7rCW2vAI8biUjVoObBeZQLy2SdEbB9z+rTgUKkn0wUceaSkk/lbvcIJw154/ETGZ oMZdMl7fM4TNbZd+MBANfZSo5SxFoI/UVLI4e3f0AnM6R0iKxdBADoeU4dtvF1/U5ptC nlqaWY7PKlyxag4OoKWK/xkpUOcNAt8SLAoaVVzFnvpFVF+8xpK6nL3FOI9fuApQc+9g mdqQ== X-Gm-Message-State: AOAM533YN9PVtvGK/2wTrRFH36ufAzaKYQApJsZoHZp5OneTqoUG5H9z XL2lgACZMbqV++zMwW0qEe/MDZNuxHlF X-Google-Smtp-Source: ABdhPJyJ+gRaNjgJGy9E0cHpu//789P5n3ECAFBUIUMkhGjSQmSpj9Wx6BMCctlIoRSkXsyJkLWIz/+9b8rK X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:16cc:acbf:e9c5:6393]) (user=tzungbi job=sendgmr) by 2002:a25:7489:: with SMTP id p131mr3067762ybc.339.1639454446238; Mon, 13 Dec 2021 20:00:46 -0800 (PST) Date: Tue, 14 Dec 2021 12:00:28 +0800 Message-Id: <20211214040028.2992627-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak From: Tzung-Bi Shih To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com Cc: alsa-devel@alsa-project.org, tzungbi@google.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_200048_732456_BE4EA114 X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The of_parse_phandle() document: >>> Use of_node_put() on it when done. The driver didn't call of_node_put(). Fixes the leak. Signed-off-by: Tzung-Bi Shih --- Hi maintainers, Need your comments. The patch is one of the partial fixes that I think it makes the most sense. Option 1. Machine driver makes sure the object is valid until registered This patch adopts the option. It needs snd_soc_register_card() to call of_node_get() somewhere to hold the reference count of of_node. However, I failed to find similar logic in soc-core.c. Option 2. Machine driver borrows the reference count This is what [1] adopts. Decreasing the reference count in device's remove() to make sure the object is valid for whole sound card's lifecycle. [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065 In fact, in my test environment, CONFIG_OF_DYNAMIC is not set. The implementation is empty[2]. Per [3]: >>> Hardly any platforms need this [2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125 [3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55 I am not sure if it is worthy to find somewhere to hold the reference count in soc-core.c but I think option 1 makes it more clear to drivers. sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c index a606133951b7..24a5d0adec1b 100644 --- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c @@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev) return ret; } - return devm_snd_soc_register_card(&pdev->dev, card); + ret = devm_snd_soc_register_card(&pdev->dev, card); + + of_node_put(platform_node); + of_node_put(hdmi_codec); + return ret; } #ifdef CONFIG_OF -- 2.34.1.173.g76aa8bc2d0-goog _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DAFCEC433F5 for ; Tue, 14 Dec 2021 04:01:55 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1A3A51EFF; Tue, 14 Dec 2021 05:01:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1A3A51EFF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1639454513; bh=+a2K0mhOGV9B7ALoF+9dJOTW0UNz6Me/1lgKth87Cw4=; h=Date:Subject:From:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=csOhmiJe8j/5VIKb3UB9bpuCEYsCWzLEpaCyFvtbO1A5+kM6GK0D5AbeBe5Wox6ek z/wKjjQGWw/SO8NRiQBoVHNZfY69eXs5csaOy2rUbZGvQPCLR0BIV8bvsf8VWr6oY5 Pu99zOFKXzvAmb737cEc8yOuAN9YHDXcYrgZFffI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9702DF801EC; Tue, 14 Dec 2021 05:01:02 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9870BF80246; Tue, 14 Dec 2021 05:01:00 +0100 (CET) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 14C4CF8016A for ; Tue, 14 Dec 2021 05:00:49 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 14C4CF8016A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KUYS2WNm" Received: by mail-yb1-xb49.google.com with SMTP id h5-20020a255f45000000b005ffd939127bso33974163ybm.10 for ; Mon, 13 Dec 2021 20:00:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=KUYS2WNmggkO20Zmll03I/4/wpE7LncoJnK+g8c522aQ0VOShYg1J2Zo7mtzyNtyfZ 7O1vdzMeRIzfVqbNOx79k5MrU00AsFWLDP+xAhU/26ztWIzyuPUDq6okL56jpphkJO64 /k5O16IEiN8GX4DB+CuYBrEW5FWA0XkheykantgllsCRhOcKIm564bkQ57pEyMbVAJ49 UZyN/It4QGdOC/f9Suqq/S2kqJ1BWqGM+9eU3eeVORznoO7+N3x7fdE0WoWptYJklfyH dliehqZjJWM8NEXPHDlGSmxOKD7qClfbSeSVgiXVFXQtEvTWF+2bQx1YT1QOevXM9s7h +I0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=29cloTRKlk8q09dAozEHvSB2Khp0RxTuIBb8pfxGgBtq3vDPJFZeP/5Py0TCx9Cdhh kvgU2W0i3cPWT8VbIdiZEB64zGZXTc+Kzm2MXw11c8Tmnfmlnzag4Imr7nVB4JkuHX9W +3ZRfNuuVRPdxMZhpXwgGkffvUB5u5+Ma4AfRBfcFpKXQYd+ac5Ene5gjEWOiyYyDTam ppJjkkCWkY9dy9lQSQwqkp2Aji6Y9nQ4SYmjPOL/qlbhns3ZJctZ1plVfNxqdGjH5Fz+ Br3hRstaloYizoC81UHYXq0oscKSe8tJD5obybLPiS1gU71d7vTfdvnkibUGckc2GLzW 4zbw== X-Gm-Message-State: AOAM530opmzZcYBXJiEoQeIp8/9GiR+vbrca7xKiwRmZjVC4AQMa77Tn 9hTTJfcB4enx/KNjOj+kwOKrS1EAb8xa X-Google-Smtp-Source: ABdhPJyJ+gRaNjgJGy9E0cHpu//789P5n3ECAFBUIUMkhGjSQmSpj9Wx6BMCctlIoRSkXsyJkLWIz/+9b8rK X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:16cc:acbf:e9c5:6393]) (user=tzungbi job=sendgmr) by 2002:a25:7489:: with SMTP id p131mr3067762ybc.339.1639454446238; Mon, 13 Dec 2021 20:00:46 -0800 (PST) Date: Tue, 14 Dec 2021 12:00:28 +0800 Message-Id: <20211214040028.2992627-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak From: Tzung-Bi Shih To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com Content-Type: text/plain; charset="UTF-8" Cc: tzungbi@google.com, alsa-devel@alsa-project.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The of_parse_phandle() document: >>> Use of_node_put() on it when done. The driver didn't call of_node_put(). Fixes the leak. Signed-off-by: Tzung-Bi Shih --- Hi maintainers, Need your comments. The patch is one of the partial fixes that I think it makes the most sense. Option 1. Machine driver makes sure the object is valid until registered This patch adopts the option. It needs snd_soc_register_card() to call of_node_get() somewhere to hold the reference count of of_node. However, I failed to find similar logic in soc-core.c. Option 2. Machine driver borrows the reference count This is what [1] adopts. Decreasing the reference count in device's remove() to make sure the object is valid for whole sound card's lifecycle. [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065 In fact, in my test environment, CONFIG_OF_DYNAMIC is not set. The implementation is empty[2]. Per [3]: >>> Hardly any platforms need this [2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125 [3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55 I am not sure if it is worthy to find somewhere to hold the reference count in soc-core.c but I think option 1 makes it more clear to drivers. sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c index a606133951b7..24a5d0adec1b 100644 --- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c @@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev) return ret; } - return devm_snd_soc_register_card(&pdev->dev, card); + ret = devm_snd_soc_register_card(&pdev->dev, card); + + of_node_put(platform_node); + of_node_put(hdmi_codec); + return ret; } #ifdef CONFIG_OF -- 2.34.1.173.g76aa8bc2d0-goog From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C1E4C433F5 for ; Tue, 14 Dec 2021 04:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=zLRxoRmOl+YKGI7id1d2bMEsYYY9GZbCaykwsyuNx8I=; b=0QP pOV0jA5FDL35OFnMyISgV42UULhoEY//Isx1kRMpepPkm4U6o+9IW2wB7haZwLZnprN5rSM/KHBMD AOSWyTCM/kEpfmPtDJ3s5gTUIKBe0FIxrNLNm3scmqk48A93TkcAINA4UMoc2ix1YsQwvx9s19kqo WdIrxKRd7Yh7WS4c1Qhi8BWqZOPTVkjWtn38TASO0JN+kc46aAqZHWCg235cYORhdQ0SJuDcsE2No aktp4mR4cvQ2leA5Tuttd8qrrkIgGKA5aTjhgNLbm6nkTKt/nkeftUgVm3xwNpTDf4aAI4I3t0BPP WRFIKDJKerrr3gO9Jo2WoBKDUyz2nbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwyzs-00CTzt-MV; Tue, 14 Dec 2021 04:01:04 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwyzg-00CTvJ-F9 for linux-arm-kernel@lists.infradead.org; Tue, 14 Dec 2021 04:00:50 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id w5-20020a25ac05000000b005c55592df4dso34508365ybi.12 for ; Mon, 13 Dec 2021 20:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=KUYS2WNmggkO20Zmll03I/4/wpE7LncoJnK+g8c522aQ0VOShYg1J2Zo7mtzyNtyfZ 7O1vdzMeRIzfVqbNOx79k5MrU00AsFWLDP+xAhU/26ztWIzyuPUDq6okL56jpphkJO64 /k5O16IEiN8GX4DB+CuYBrEW5FWA0XkheykantgllsCRhOcKIm564bkQ57pEyMbVAJ49 UZyN/It4QGdOC/f9Suqq/S2kqJ1BWqGM+9eU3eeVORznoO7+N3x7fdE0WoWptYJklfyH dliehqZjJWM8NEXPHDlGSmxOKD7qClfbSeSVgiXVFXQtEvTWF+2bQx1YT1QOevXM9s7h +I0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=gH6VytNCcR/663SuXLz//aT5v81QXOOZ77y3idOPjPI=; b=WQHjyvgeZs74B8i+jkUCWL0INMyaSWRC892Zy+1qh7Qph50xaJTTTwC2DbR6AwHIlz marhkncGqjFe7CeCe2Ij5eL1QQUhHySDK02QovsumbcJMNDmxBV0Buz2SeEZ0kppIb8L xHM4tmYgWjf/3bze0/0cPbRpYAKTzVAuZ/fFeHq/dL7LM2IgND4IJ9OCl3B0Mvt9hR4F p32r8FEiSBLqzyQdDsaAayRBlNWeVW+fN1ViOd1wrjXjVip3rgYMBvEwqRZWgA733GII FzWiPltT6gCCQERNfnlibe0SxT3fEF16Wo+HfVf5EFiJopj73qdDra5ltjKulda1pFR/ DsCg== X-Gm-Message-State: AOAM530YfoJrhZstlrCLnsdckdfaIlOcmpBhc1SZRFgrUk/fbWCgFIG3 tbmXTemEtyUuPFd+KTXc0alA9uHh0W4m X-Google-Smtp-Source: ABdhPJyJ+gRaNjgJGy9E0cHpu//789P5n3ECAFBUIUMkhGjSQmSpj9Wx6BMCctlIoRSkXsyJkLWIz/+9b8rK X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:16cc:acbf:e9c5:6393]) (user=tzungbi job=sendgmr) by 2002:a25:7489:: with SMTP id p131mr3067762ybc.339.1639454446238; Mon, 13 Dec 2021 20:00:46 -0800 (PST) Date: Tue, 14 Dec 2021 12:00:28 +0800 Message-Id: <20211214040028.2992627-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak From: Tzung-Bi Shih To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com Cc: alsa-devel@alsa-project.org, tzungbi@google.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_200048_554912_58E16152 X-CRM114-Status: GOOD ( 15.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The of_parse_phandle() document: >>> Use of_node_put() on it when done. The driver didn't call of_node_put(). Fixes the leak. Signed-off-by: Tzung-Bi Shih --- Hi maintainers, Need your comments. The patch is one of the partial fixes that I think it makes the most sense. Option 1. Machine driver makes sure the object is valid until registered This patch adopts the option. It needs snd_soc_register_card() to call of_node_get() somewhere to hold the reference count of of_node. However, I failed to find similar logic in soc-core.c. Option 2. Machine driver borrows the reference count This is what [1] adopts. Decreasing the reference count in device's remove() to make sure the object is valid for whole sound card's lifecycle. [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065 In fact, in my test environment, CONFIG_OF_DYNAMIC is not set. The implementation is empty[2]. Per [3]: >>> Hardly any platforms need this [2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125 [3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55 I am not sure if it is worthy to find somewhere to hold the reference count in soc-core.c but I think option 1 makes it more clear to drivers. sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c index a606133951b7..24a5d0adec1b 100644 --- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c @@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev) return ret; } - return devm_snd_soc_register_card(&pdev->dev, card); + ret = devm_snd_soc_register_card(&pdev->dev, card); + + of_node_put(platform_node); + of_node_put(hdmi_codec); + return ret; } #ifdef CONFIG_OF -- 2.34.1.173.g76aa8bc2d0-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel