Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7967259rwb; Tue, 6 Dec 2022 12:09:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CBaRi1YTpAeJuq5EHyxiMOKrum/rg3H/CovwuUR0K8GMLZ4vQHKPWISYmBbFzbj7VleMn X-Received: by 2002:a65:5543:0:b0:477:dc7f:bf24 with SMTP id t3-20020a655543000000b00477dc7fbf24mr51265683pgr.555.1670357375994; Tue, 06 Dec 2022 12:09:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357375; cv=none; d=google.com; s=arc-20160816; b=sJXjGCEtgGNuYDW15qthKStmG+IJQCFOAfo4YwCAqTa5HwHtaj779jpiE7psjI/Dyf t0r4PlxHyHq+wW3fJVVqWm4uHBDRSecrrKh9gwAVse/lUXxLJAb966OOBieumX8sWmMs OHEW2heBpRcGY1SH2w54sOIyo7xBVRoGb1d2bsJrx16aLdNpQMFS62lqVe7oJkHCrnM4 dmPMD26CHOlmwX8w6Omfw4+Cc8CaWclucBQTJINQCYwMj5hvVDhWH4ELzcbaI5lBvELA sM5X0/m9BhimSeLpWOufm5Y0X3diywgLh+Z/KrRnTIlfetaFeLowerZGVHANke3pVogW E+yg== 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=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=Js3dDbiUZQNTNTzeor+0NTBN9l32YkgbizxUoUeOrVIKuGxuDC2WUCc0uuzqLoirj6 mAJFX7990c5qrHGwZbZDKgldB5/DfD8q2Cj9SAneCthIXvqoqvSG/XqkjWRp0TChnV86 5gRXLY//nms+JC4BIP6tDn6e4FhPydFhT6EPVjVm9sAL+KtdCoWV5+IjMqITiIEP9aHa Q05HkkT129p7PXCQ53mKaqjfWqckJOvgW13f1sg0ULUAGNjkYa6SpNKpm2eJlK1qfNgk es3txGHly5V2yPRcxoWpDudx02XyYowIi8UK3P2eJVb0JWP6cF1e+qLqmtFhEYeK8ePy Y6jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=iPQL7UZp; 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 h11-20020a056a001a4b00b00547d55a4d3bsi18579580pfv.285.2022.12.06.12.09.25; Tue, 06 Dec 2022 12:09:35 -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=iPQL7UZp; 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 S229564AbiLFUIU (ORCPT + 78 others); Tue, 6 Dec 2022 15:08:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA9B3D2EA; Tue, 6 Dec 2022 12:07:51 -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 A50803B28; Tue, 6 Dec 2022 21:07:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357268; 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=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=iPQL7UZpEggmdZC21h8CNYAchb00M7jJP9hFmVO68NH1Aoq6L1DqOPUiUESa3QCM3RxOmS hFlxcjpPHoFyaDpHFiN+wNAOfsTegJ8zaQQFhyOB9GvgXodaEiX45QKf2YE6LN07P/5R7W PABgorR2RdBI9AehiU27bTuCKQvjUjddyoR2sRW0fimRHFOb4lqvg6PQ+UI5XtIDuHhV9t +ai38+f2GCPQfZfL0CDZLWJ6pBGy3PnSon/6XCBZGKDv9q9JaMxIaJSfnZnTqDTH5F+nOt c+VkbXs/fuWNayROQUe+T0OWzhqlOW0+Gi2BKvt8DRCH3WpqXoVbvO3HA5rzZQ== 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 , Dan Carpenter Subject: [PATCH v5 05/21] nvmem: core: fix device node refcounting Date: Tue, 6 Dec 2022 21:07:24 +0100 Message-Id: <20221206200740.3567551-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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 v4: - none 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