From patchwork Wed Nov 23 18:01:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 25113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2942217wrr; Wed, 23 Nov 2022 10:05:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ptrWQQDV6iYOkBv8d/jTpOrzRDW0LM7wkM0JvAzlq2eolkqBLXm4D6GHQvXreWEadtPCC X-Received: by 2002:a17:906:38a:b0:7a7:1d4f:c7d9 with SMTP id b10-20020a170906038a00b007a71d4fc7d9mr13099405eja.402.1669226729145; Wed, 23 Nov 2022 10:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669226729; cv=none; d=google.com; s=arc-20160816; b=w0O+W0tK+NthQupbBIiMHFjS1eq5AHdix3TQTP46cVfv8yk1FtWFV9tFJjfpIhfs1D qM6kTT5yvAsliArkdUxp67h1Sp4bJ3ADHjd+q98CeMpFoTdT0hFsGNZErfcX4VA9Q5R5 JEunQim9fAlBgVXUjEN9boEhx3KiC98hDCJnGHj5C3mctoK/slCBOBiR3JSTKIr1PyIB 5XWETEYx0RlBUD2PzHVorRRkgmKioDvhIqqXT+ZJIvLqRDMORL2BdMrmGpQebCyjAlvS xPEy21L1tnyxASKwThyW8sJcAiGDbLunOH3QJq8dG+vgoxv3PKErI5wkJcqrgrCvZ5w9 DBnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Q1MoPTERuwNbtl93gSheDb+IydkaPiCC1imB+guf7A=; b=xkeOzRWg3BfMED+1Z+495nvj/n0O5p7l9Jzld0qABUczbBd7ZI0UBc+PjXgrfI3v0H XKHJYo12OkyK6PAvJRVO6UdzMwaBvRZMIoW/FTJHgwGnZ1c/DGXFSG+NK3s8fgHPLstu rbIIFwKYsgteq8lHaB/nFYLH70P1S1opb2ojybh+q9rqNcu5l/gTq7Z2xxP2jLx0dIod 7JsLUGjv6ilNb0Fv6etIebshaEU7ihhJYPOyvANSX4oB1NMTnnzgKg1/zlUwNtvfaJC8 9s9YW28f3FT/8FmkP9hbVnvuiJvrRBdoXdV+tDLIrtgAGWVARmYgCamoPW1FI5Xe2czi X1mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=O40PtDLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js13-20020a17090797cd00b0078e1e77f443si314759ejc.418.2022.11.23.10.05.00; Wed, 23 Nov 2022 10:05:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=O40PtDLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239221AbiKWSDp (ORCPT + 99 others); Wed, 23 Nov 2022 13:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239183AbiKWSCZ (ORCPT ); Wed, 23 Nov 2022 13:02:25 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81FA93700; Wed, 23 Nov 2022 10:02:22 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id C83B93A7F; Wed, 23 Nov 2022 19:02:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1669226540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Q1MoPTERuwNbtl93gSheDb+IydkaPiCC1imB+guf7A=; b=O40PtDLf1PHHYXCdyXG0dEe/l1T4hU/5ZadCAMY9NuJx9Nz4/lYbJnzCO1AtiW05WhVzwf a55BRAkXHsw8LnQkXpMUwGXTZ2PL3RwDGxxhgAEGyaNjkfvPfJf0DHYORI2G0yI4/J9P/S eucSBEC02A58rfUCU4Pr4K19BXqwQgoHoojCGzY1/8tVFy9AvbF8Bst8W7BwL7aoLr+Exc id2EZlndNwiSPCAP689VEAzrmPxcm3q5XfDLEX7wXgcvyQYmngmhlmNlOu0Rxd3jlsejnt 0YbRN7zF3K2JCHHqlNCZZbVoye7hdxAyL9ue7eVxDhxx6uzLxnjRjZwiCGWYdw== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand , Sascha Hauer Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Michael Walle Subject: [PATCH v4 05/20] nvmem: core: fix device node refcounting Date: Wed, 23 Nov 2022 19:01:36 +0100 Message-Id: <20221123180151.2160033-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123180151.2160033-1-michael@walle.cc> References: <20221123180151.2160033-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750311087010795913?= X-GMAIL-MSGID: =?utf-8?q?1750311087010795913?= In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This will decrement the refcount on cell_np, but cell_np is still used later in the code. Use of_get_parent() instead and of_node_put() in the appropriate places. Signed-off-by: Michael Walle --- changes since v3: - none changes since v2: - new patch drivers/nvmem/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 321d7d63e068..205a427f564d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1242,16 +1242,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) if (!cell_np) return ERR_PTR(-ENOENT); - nvmem_np = of_get_next_parent(cell_np); - if (!nvmem_np) + nvmem_np = of_get_parent(cell_np); + if (!nvmem_np) { + of_node_put(cell_np); return ERR_PTR(-EINVAL); + } nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); - if (IS_ERR(nvmem)) + if (IS_ERR(nvmem)) { + of_node_put(cell_np); return ERR_CAST(nvmem); + } cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); + of_node_put(cell_np); if (!cell_entry) { __nvmem_device_put(nvmem); return ERR_PTR(-ENOENT);