From patchwork Mon Mar 7 13:04:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaoqian Lin X-Patchwork-Id: 12771834 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 6727EC433EF for ; Mon, 7 Mar 2022 13:05:53 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From: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=OzMtwxNV0MZkg1bAxpOkGjLgO50yIjiMSWmVQCJSevI=; b=g0wpIJym+caxOe GkzMaxfBAa1jCnRsUag/qBG2M4+XEkUWkKdnoNP1JnVU6EzW/kzp852Cw0g8TjsiKpOuyBvzNgz/J TVjC7Zme5o/2dEbcaPsT1oXkYpWuOVPLcFTciD8fVYaUPfXMe7DGhs4lXTB6P+qWwiKF3U3gptGeh uSQuyVSrm1gG+dj3kn4VpBCUm0DnhEFDeZL1gMYppc0/tAD6MLH1rzh8BHj+NyfzIcc5jNoSCkRjz disfEwZTRsB11RdPE25WapQ6jARa5KG8I/Be8cCXNoGOhte708vS+kDNzu2Nc2L1f2oY8B7eGZMgK 6afYeNqgMTuEoT91EZEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRD2V-000C6y-EX; Mon, 07 Mar 2022 13:04:39 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRD2E-000C04-Dx for linux-arm-kernel@lists.infradead.org; Mon, 07 Mar 2022 13:04:23 +0000 Received: by mail-pj1-x102f.google.com with SMTP id m22so13455186pja.0 for ; Mon, 07 Mar 2022 05:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=JXzVQ2ZdweQIJEbxKcie2X+tclhUtVN1X52+YVLb9ho=; b=hNqgxl7RZ8Mz040Am5Mimahm0M96u9CqSIyWge99EgmYicdlsy6/4yXWTt1VRmYceo a4Qx+jCcdhcD4oOshOyNqiez1FjjwI5PR/N0MGQma0EtRXD/jxchdtQwxKc8Uyqff6/c 1F+WlFB0HjdbdxqwPArIWmStkvMUZkgeGFd/MIsPiMbGjAXCPfWMmYihRs3P1/6b5RVv 0DAtxY4e0C/FFcFDzaNu3mqIQSpe/GTuJVvJI7jyjjfYqe59p7Oc2JUpKxbP3HeOsaLf RW9cLtWOiUMqgj54p7Gp2ozGtg1sm3RlITsynlUdPdUfXQ+D8g9AlbHGjROY4NxISx2s Fwwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JXzVQ2ZdweQIJEbxKcie2X+tclhUtVN1X52+YVLb9ho=; b=bWVK7/Mdqrrgx9wsSmmxEzQKolY8jCEXGioF08B5JHMj3kDsjnplQ6Dz05WdInZ06q WgcYl8J5jq86hL2Z4NggeOgx/FwFRYR6RqehKXKj0UNSU3ycr3IfgL0b1iDbAYHs1Bul yYEtc/ii9hKifuOwQqFvPv6icJM+yBf5fMR0vW/KO87Otaq7gRlaINqENpp08DA5tTiU bT65uW73j5Iey8uH16GewDO8LnO6DikKF4ergzt2dWF4UvnwHsoAa7Nn6Q3TJYPqJbRT EyWmWy/vHd2Zrspun2jEX7rKO7seXenQQKdo1S3CxNBKwivUS+l9gAjgFv78bm6fl6Hg Mb9A== X-Gm-Message-State: AOAM531LKgoA7zRxyfculal6OkzmN8e/6Ofoht9i8N5AWDM6KiMNrsb0 JZhJzcpWBiJxhxnkrJnQVkU= X-Google-Smtp-Source: ABdhPJxyQZKjSR7O+jwWjm2Gm0nSCiz028BLT0JG5cVW38JeaVoEIj4UC0qg9LQoFwz0NAFzxiPbHw== X-Received: by 2002:a17:90a:1941:b0:1bf:3918:d49e with SMTP id 1-20020a17090a194100b001bf3918d49emr12833754pjh.136.1646658261409; Mon, 07 Mar 2022 05:04:21 -0800 (PST) Received: from localhost.localdomain ([159.226.95.43]) by smtp.googlemail.com with ESMTPSA id y12-20020a62640c000000b004f104f0ee75sm15099513pfb.185.2022.03.07.05.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 05:04:21 -0800 (PST) From: Miaoqian Lin To: Codrin Ciubotariu , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Florian Meier , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linmq006@gmail.com Subject: [PATCH] ASoC: atmel: Fix error handling in snd_proto_probe Date: Mon, 7 Mar 2022 13:04:14 +0000 Message-Id: <20220307130415.5720-1-linmq006@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220307_050422_500958_0019F9E2 X-CRM114-Status: GOOD ( 14.60 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The device_node pointer is returned by of_parse_phandle() with refcount incremented. We should use of_node_put() on it when done. This function only calls of_node_put() in the regular path. And it will cause refcount leak in error paths. Fix this by calling of_node_put() in error handling too. Fixes: a45f8853a5f9 ("ASoC: Add driver for PROTO Audio CODEC (with a WM8731)") Signed-off-by: Miaoqian Lin Reviewed-by: Codrin Ciubotariu --- sound/soc/atmel/mikroe-proto.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sound/soc/atmel/mikroe-proto.c b/sound/soc/atmel/mikroe-proto.c index 627564c18c27..9ed634ee9dfc 100644 --- a/sound/soc/atmel/mikroe-proto.c +++ b/sound/soc/atmel/mikroe-proto.c @@ -115,7 +115,8 @@ static int snd_proto_probe(struct platform_device *pdev) cpu_np = of_parse_phandle(np, "i2s-controller", 0); if (!cpu_np) { dev_err(&pdev->dev, "i2s-controller missing\n"); - return -EINVAL; + ret = -EINVAL; + goto put_codec_node; } dai->cpus->of_node = cpu_np; dai->platforms->of_node = cpu_np; @@ -125,7 +126,8 @@ static int snd_proto_probe(struct platform_device *pdev) &bitclkmaster, &framemaster); if (bitclkmaster != framemaster) { dev_err(&pdev->dev, "Must be the same bitclock and frame master\n"); - return -EINVAL; + ret = -EINVAL; + goto put_cpu_node; } if (bitclkmaster) { if (codec_np == bitclkmaster) @@ -136,18 +138,21 @@ static int snd_proto_probe(struct platform_device *pdev) dai_fmt |= snd_soc_daifmt_parse_clock_provider_as_flag(np, NULL); } - of_node_put(bitclkmaster); - of_node_put(framemaster); - dai->dai_fmt = dai_fmt; - of_node_put(codec_np); - of_node_put(cpu_np); + dai->dai_fmt = dai_fmt; ret = snd_soc_register_card(&snd_proto); if (ret) dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n"); + +put_cpu_node: + of_node_put(bitclkmaster); + of_node_put(framemaster); + of_node_put(cpu_np); +put_codec_node: + of_node_put(codec_np); return ret; }