Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp985520rwb; Fri, 18 Nov 2022 10:55:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Rlz9G7wD1Q4S4yYZ6D+pZ+rkvnDqAT1a9FEVsev16owRhw4Bb7VV/4nfJa+1LVm007KH4 X-Received: by 2002:aa7:d5d6:0:b0:459:4e32:e1b5 with SMTP id d22-20020aa7d5d6000000b004594e32e1b5mr7185836eds.424.1668797758821; Fri, 18 Nov 2022 10:55:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668797758; cv=none; d=google.com; s=arc-20160816; b=0o8NDHYCzs9mUMHGNrgoTzllw1ssf9292AjPuS6cSD5uLGyOWW16XkgZbZxnVT9k/M iCgIJjtBl/hz15URUTVmVuqYJzJ8Xy+cqmERuefKXXhvSBhSzqjCxzz3XY/PGMirljJW b0y2i8g7vKGbTvzt4AK83Ye0WTVwghCXNsNZstBpUY2tWVWmjEFw8tV7I+1plfPaEUVS Pl2Bp5kfGwBkreMXNENzyKGhKSOs5ROnWCDFHqy/CaO5su3YEmG9jJVa8mVVlcgTutYg 45Yj6rmPU0HtGqtTusshbxIkZVMOFR25CuxrPrQ/41KUCXztCumzjV6qQ2nZS+GD9gQR Fg4w== 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=T8O2KQMPE2O01M8v+SA8VCZdDXPSXBpYyoavVmhy8dQ=; b=w0DAvLDVtjn/ed2bKVW/AWvZby0GhFNQwoxqz1yNeHExN0ohzTzxny0nXBKefnjhk9 /XM9cdVdkYLWJqzeNPstKK58EvOodu41akvvPEHxQQV4Vo/yySBH7z9b9l7ZFxHGCNUR 7cMpwQ/4yX8aYR2hlLSoRGk1mXhmP5vih8Q4bvKqr0QdltoXM9etTURScBFP0qacxhtn bIoeO7/f17wzXxokdcgURO0BZa4pjqHBl0fDTeDJRtSgiRYFbwOgXyqV2VEJNnOxFS94 NW7HjnIljGeP2iZc9Rw58OQUpuUB2iFDZo/ePXzzaROuuPeLorXJqYdGN1vXTfkszSjY 7rjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="Qee//rjR"; 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 nc27-20020a1709071c1b00b00783c42d2da1si3817056ejc.425.2022.11.18.10.55.22; Fri, 18 Nov 2022 10:55:58 -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="Qee//rjR"; 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 S242836AbiKRSwQ (ORCPT + 90 others); Fri, 18 Nov 2022 13:52:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242801AbiKRSvm (ORCPT ); Fri, 18 Nov 2022 13:51:42 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7215F93CDE; Fri, 18 Nov 2022 10:51:28 -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 6A0D71D3E; Fri, 18 Nov 2022 19:51:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1668797486; 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=T8O2KQMPE2O01M8v+SA8VCZdDXPSXBpYyoavVmhy8dQ=; b=Qee//rjRncNfbLFAxm3ewFj+I//0OcA9y80MhumWzUPQEQB9x1Acvl4IFFqChpXqAl3fmm Bv4ipBpOjzB9rfy58nQ8V2AoP5xFI6d1PbL8OUuomKjsEXRIPyBxWsMNmJklWg4F61AP+h JqDXbbJQt7oNiUc9TwuHGUdphPd+DIB8kB5Yt08tf4VDEXl+jNFxYwAXE78ZBVCrHq2Dg9 4LVFYoh+DRfmjvIFWN4/yiGj+1b2tQeIDazBgg6Iu2de+dbencTUHPz81vfzvJC04RLpCQ g6fY/RFz8s4yDskD8NFLf18C0bfOGPb4jWVR0bEMiWQ+3DpfP5LVnexpLGIYPQ== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand 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 v3 03/18] nvmem: core: fix device node refcounting Date: Fri, 18 Nov 2022 19:51:03 +0100 Message-Id: <20221118185118.1190044-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221118185118.1190044-1-michael@walle.cc> References: <20221118185118.1190044-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 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