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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D6D1C38142 for ; Fri, 27 Jan 2023 10:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbjA0KlB (ORCPT ); Fri, 27 Jan 2023 05:41:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbjA0Kkk (ORCPT ); Fri, 27 Jan 2023 05:40:40 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047C11F5EB for ; Fri, 27 Jan 2023 02:40:33 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id f12-20020a7bc8cc000000b003daf6b2f9b9so5099292wml.3 for ; Fri, 27 Jan 2023 02:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sr6CA9xjZwvud8xzQyK6dmW2Ra23HBqhT3DLj1X0by0=; b=rWfW+A9+dX4D+Iqs4/ibFCmB7czEciSj0MHxvMw1Tmmmyw5Kc/22/Ocevvr8+ZlUmS CY7oYhz9T5650eWArL6xtD2IM+VJz5FGEg/MsKDQ5OnTyr2nyOe0nu7rSUhLUlgytMAT PrfBnWL90QlVpCPVPv3neli5edKk+ZWj2Xmus07O4IL7LXRMlITk8Tp31Fu+RgYEqprM nPGzcF9MOywEqrEg3F/WFs635W/g/CnO5YhldqA488+ThVoWyCxEBjW/rGjDUf4VN2kE hcKoaD+FwLjW2xn2medwVmGCEpLwuy2PM12ACAfk9/v1kF6PjP9kw8xP3LRSOQ5AYMZ0 vTBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sr6CA9xjZwvud8xzQyK6dmW2Ra23HBqhT3DLj1X0by0=; b=NC5qygAysWUZbDlGaI3goOcL4CREsFmbYXy7jAbt8wA7ZiuOoMe/vSgUToAr5sovdD so8nKKDgAGE6/uBzBgKBzXavlW12DdcL+1pSl4SYZmpae2LXKaCqaMpsgATzEE1pCgQM g9ttiyLBjvlo741HJOhihH3rZvMQv4S4M3RkdAldc4JlN1DFHZ7jv/Hbg8jMaGWbNqRy z69JumnrQe7XCttrGgUCkn4x104GOlvlG2+fGpMyUJnE4GJOctDQumeII73CyVKdas5X BKK0xEGPHyBelkzNsTgnbyIH1AgifAUahiauZUlA1QoJNJ/YrXG38+EnsYwbVSo6kV9c +nMQ== X-Gm-Message-State: AO0yUKV/bioOBNY9uEWi+2Y0PuOXs5S04sYuzpp9h38zmLNcRaTCyDP+ V3N38jcwdUAX6bx62yLdphO9WA== X-Google-Smtp-Source: AK7set+tOtiGVim8zUWkNPhRPkneuLmW0MBPeqbl6VpXdZ8WBbsM96M8ldJ0TjdGk3S0caS1RL/wKA== X-Received: by 2002:a05:600c:1e0d:b0:3dc:3f1b:6757 with SMTP id ay13-20020a05600c1e0d00b003dc3f1b6757mr728908wmb.15.1674816031564; Fri, 27 Jan 2023 02:40:31 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id q9-20020a1ce909000000b003dc34edacf8sm1619787wmc.31.2023.01.27.02.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 02:40:30 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Michael Walle , stable@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 07/10] nvmem: core: fix device node refcounting Date: Fri, 27 Jan 2023 10:40:12 +0000 Message-Id: <20230127104015.23839-8-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230127104015.23839-1-srinivas.kandagatla@linaro.org> References: <20230127104015.23839-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Walle 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. Cc: stable@vger.kernel.org Fixes: 69aba7948cbe("nvmem: Add a simple NVMEM framework for consumers") Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation") Signed-off-by: Michael Walle Signed-off-by: Srinivas Kandagatla --- 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 e92c6f1aadbb..cbe5df99db82 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1237,16 +1237,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.25.1