Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7741127rwb; Wed, 23 Nov 2022 10:06:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5kewh5m45SI3j4L1xayX71TUHX2G/6YeiThvmHRSRdw0Jj6HkwgSKl+Fb/BLd1JhDMutrt X-Received: by 2002:a17:906:6c7:b0:78d:4061:5e1b with SMTP id v7-20020a17090606c700b0078d40615e1bmr16288789ejb.47.1669226811414; Wed, 23 Nov 2022 10:06:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669226811; cv=none; d=google.com; s=arc-20160816; b=CgRztoE43Awhyw8i1wVWoU1Qq3mOccXN3/ZgihcUZqT39EUvnhrnO2uIHZXT+40YZj wCCYRSB30S/w7Hmnp/3MIR7jR4QF1GgHdQW4E73hm8woRG2w73XS/SDwOMuXnN8seBvY g6BLB6Zy+34QgAMYpAIYxtJxzNScaRrlFjLpg/WUgP5A3lnqOyp8N6UJS+a7t/jc3v9c KN1yLVqFCl54LEE2ZkG8jad1U6Gf2kAcxyA0edSphCo+V2L+ImcraW6s8AT1BatBqLRH R35h6HxGYPiU51+1bArLiIei/EsX87xKskfdlrw1W8cWTi2ytWXjXz6wGu5o5T62KbHy npVQ== 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 Return-Path: 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.06.27; Wed, 23 Nov 2022 10:06:51 -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 + 89 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 Content-Transfer-Encoding: 8bit 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 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); -- 2.30.2