From patchwork Sun Apr 3 12:19:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaoqian Lin X-Patchwork-Id: 12799532 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 6541AC433EF for ; Sun, 3 Apr 2022 12:20:49 +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=NsLCBY9LsCXqXZ9eV9yTBgGtLwl1xWAPBzW9/YjGwbw=; b=42W2sN0obJZLz8 8jXS6tq/SKxIC8r8FUglNlOJgVtAU3hBVb+0n8HMgcSr7tbWBt/tjS3ml56JBlQ11t2DR9QxCD35/ 1us2THxj9OiOoORef1gnkeyvX35DhTauoOdmj+92MIDH0zRcBhgp11DfO8Vn1UkSGNjYo4xypDlix f5PUcnqwILXS6QI9BZOEyufNMza4amJgFl4Y75RVXsfoyL7APRjLUxT1U+WMBcrxSEWYYjyqbr8gA pUFhB7RT5b3TfO+DPGaiziTPxa4gpM7ZxYp7HFJ5VlviUD4DaYBB4NIy8rBwtkOIX9n7RIc3599Ty SCoaFCdbGNcEtYroMyUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nazCj-00BLHK-IT; Sun, 03 Apr 2022 12:19:37 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nazCg-00BLEm-2m for linux-arm-kernel@lists.infradead.org; Sun, 03 Apr 2022 12:19:35 +0000 Received: by mail-pj1-x102b.google.com with SMTP id u14so2481539pjj.0 for ; Sun, 03 Apr 2022 05:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=RShXJBNVQcxmpPDml0HJbk+LkoGJyZhOEELj1lVtbec=; b=ASJ/uTPqb3VVSeNcAbp/2MzxUbyvy50wiLrqZDmqGEYwccN7mrIFuq2OD45vQ6Cqd0 5/SUkAf4QGZVRDwJhnFc6AR4Akd8JgP1Ri6SOd3GBHlqUzmn2nf0Wlm5E89DqxKOj7nn xKQdTmz/c/hKXtQ5BBsbm6DFU3CrpLDR9JfyWF4TOZonwBgKWNJUBVIFudEUScJgqto9 1XFMuZhYlgHUvGg9TJne/FGV94UscJRufy3/bxlHDtcmRqnQ9vAPsdVlBR7aA694Ih57 xqYbPEwz8xW0aoOWmbIF3In4VdnwmUsK03Tkj6Tk9AhUZny1MpIRAukpUqhxDp9kxkWO dw9A== 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=RShXJBNVQcxmpPDml0HJbk+LkoGJyZhOEELj1lVtbec=; b=j//8SMM3y/QIBoojq1HvSxQ3+1ukcr/OEr1JnEsyK9adEgkuM742M+599rfZ7BUZm8 c3oLiMoEHcq2PGbJM72u4HF/KhxF0rBh/UyoKJNZcSaIGhBoAm9SiKZ8QxWjVkB7ByiF UfjnCPYZ4f+dFuPhz0ocIA/qJGENeOzyFQFh/Np8kKZO9DrBd0BoGbgbuL/TCwAeB6DM bkKLiUPYVvOP452Y/dXTPPiOgCvuOHn/+CsbMQhva0mPV6UR9wwd7KMjTg/S21W7/+i2 cDB26LLP4r3G6O7qfgfbOY7TKPYoL7V0/P72vmENYQfCgIgG7W0PcINKU2jPAXeSF4bx H5+Q== X-Gm-Message-State: AOAM533+kiJGkwAIkj0x9bpgJlS6Y3iT8jga7iPhwfhojisnbW086qLf Pu/PC/9xI+MSOwERvxPzXFk= X-Google-Smtp-Source: ABdhPJzJ180xuZCo6a/vyAI5wNXF0oUceznq7n1YZj4xX5GZFmrnqYFXuyvtiBLWAo0hSxO/XJ2jTg== X-Received: by 2002:a17:90a:7403:b0:1ca:7de0:8cf9 with SMTP id a3-20020a17090a740300b001ca7de08cf9mr3869047pjg.74.1648988367280; Sun, 03 Apr 2022 05:19:27 -0700 (PDT) Received: from localhost.localdomain ([159.226.95.43]) by smtp.googlemail.com with ESMTPSA id o14-20020a056a0015ce00b004fab49cd65csm8604019pfu.205.2022.04.03.05.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Apr 2022 05:19:26 -0700 (PDT) From: Miaoqian Lin To: Qiang Zhao , Li Yang , Paul Mackerras , Shlomi Gridish , Kim Phillips , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linmq006@gmail.com Subject: [PATCH] soc: fsl: qe: Fix refcount leak in par_io_of_config Date: Sun, 3 Apr 2022 12:19:20 +0000 Message-Id: <20220403121920.4788-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-20220403_051934_163254_D534D718 X-CRM114-Status: GOOD ( 12.13 ) 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 path. Fixes: 986585385131 ("[POWERPC] Add QUICC Engine (QE) infrastructure") Signed-off-by: Miaoqian Lin --- drivers/soc/fsl/qe/qe_io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/soc/fsl/qe/qe_io.c b/drivers/soc/fsl/qe/qe_io.c index a5e2d0e5ab51..9f5f746bea88 100644 --- a/drivers/soc/fsl/qe/qe_io.c +++ b/drivers/soc/fsl/qe/qe_io.c @@ -159,12 +159,12 @@ int par_io_of_config(struct device_node *np) pio_map = of_get_property(pio, "pio-map", &pio_map_len); if (pio_map == NULL) { printk(KERN_ERR "pio-map is not set!\n"); - return -1; + goto err_node_put; } pio_map_len /= sizeof(unsigned int); if ((pio_map_len % 6) != 0) { printk(KERN_ERR "pio-map format wrong!\n"); - return -1; + goto err_node_put; } while (pio_map_len > 0) { @@ -182,5 +182,9 @@ int par_io_of_config(struct device_node *np) } of_node_put(pio); return 0; + +err_node_put: + of_node_put(pio); + return -1; } EXPORT_SYMBOL(par_io_of_config);