From patchwork Tue Dec 14 04:00:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12696026 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: , 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