From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECC6D3F39C2 for ; Tue, 9 Jun 2026 09:52:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780998770; cv=none; b=Qme8kaJryWwC/Uv/gND4Uw/vVPRPSbFsfWJj+Pplddk+UMHX7G+C0VNE4273O71jVEu0Thi3xtQkMO4SSIxhnlRNFdR2D/bWX1nx6izJpNgLCJ5KEiCX4WoSzJpGJNPPacSHRCr2zWQbS+/vzQj36RIdWm+5buEtCt4MBB2zlzs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780998770; c=relaxed/simple; bh=sg9uFcDrc2z3pcrwd6sZYiegogyRF9VxALB/8gGABwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TsvVLmEyy/grToy+j8e2hFhIkezDKdo11Ep3AJOv349YSnHtIm0Kl288t8Bmvl1BWRZFVXrHaY7ceExlXGRZv13vrCtMXY8hxxaOA9A72QsbwJ0wC9qeDmRDQb3m2i9yHVBEMIvfv907pmPBiXTka32xzZ9RfyGcnE8uypFOXeQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gEgk3re1; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gEgk3re1" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-37474afe908so709939a91.1 for ; Tue, 09 Jun 2026 02:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780998767; x=1781603567; darn=vger.kernel.org; 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=A73y2Pg16zM1/WvH9t48h/2ALu7N8J70iHXokd8IsZ0=; b=gEgk3re1Vf1E15C4hSUNAyGMyZi5ekcwq5XN40ECfW8IBou49MVbbgmThAct98/h6d 3xrHyIuJ0xqrFboNUAseR8p+5nUF9qrIRv9w1rPTXF5svk0oNJ3HGY7eUcK9HGCN3TNJ R9w/oaa94qh5DYeb/PRvkH/t9hZMv4IPPCcPLAymzszRKJEosIFR+3wan5JmyIEled70 2HwBKbb3y4OFavJkR5/n4HinU2fTlsSAuR5H84oL/w0kQZWfBb7sBrNCzXAA2PUgzmAK 9L/O18kQr1SiahcQWdnYDWkfa2Y6PPJRqfhD7NYoyo5lnhQOOzloiqL/Nyh2A4QJLRGC tgFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780998767; x=1781603567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=A73y2Pg16zM1/WvH9t48h/2ALu7N8J70iHXokd8IsZ0=; b=GRp0NI++Il2UpcaLXl6emUIXXq4CsSWW6GlxHbhABW6mCl6awJu9Qed7yIg7LWjyfF qBDCw6ykfy43pppEVEGzf/woSBEW2iK7lkZ2i11b7AU0GeqGPQA98Y7z5UvFtEusD0Vu KvubVmWEi0UX5mFHqK4Ly5Axcb3I7/LvALdubsqE21zEMdZ3efjU8NOarkhA99Ju5m+c LovR+Okl2aRFzMC58fliH9sJXwMGyKSFp9MOI1IymY3d/5ZpSTa7xtbXTXCd9E9WZLLV OrCX22FTLHr6ExwLt6e2WPSLcORgA3VTO5cUEpdMyqNT2k2+eqZ0RSM0SZITwTywe4ix Rgxg== X-Forwarded-Encrypted: i=1; AFNElJ/QW7R4q/wPAi3CBKqW1R1C2Q/6nfzop9xg69A0HPyoyHBkygjnPvXldqiNltp1c6GVKO/Vgfo4BOtUDL0=@vger.kernel.org X-Gm-Message-State: AOJu0YzY4yVQ0WWHWhjYn53hXqNjxMMkXhtaVNHyo/GKs+wVKLV8DhFH CCo0EZtPc58FnFs38QGDBrE6X68pkTnFiNeL6lUZsGw4IuTg5V6CjGf6 X-Gm-Gg: Acq92OG3a1xKWiNST7Jeoxg5ytDp6/HPuQSkebpEufHdOjl8kvq9Zdtj2Y1xkmgJ62/ m77Ddn4YM5yOygv+Rq/CT7wu8Wo9F1x3sAtB2KhPd85iE42e2un33r3+lu/QFv4AWEAGwOG9LIh Q2BSKqIjylkIkN6hSRoooeM+lKFsstqxMxhpTHCVPGtmRpm5lfeB1AVyfRD6mGda/1c/u80sPWF iINeZxyaRtceMH3734O4ZdvAit8dHTotCh0Ka1N3ZKXPZuVze2Pvau1YOX0H9p/JHgzTIerwovp DinA6bFAXYmqeAiHnxKsJNceYMJANVwSwzJQ9nqqCCqOUm/1B++kRWR5dVLEhPtOej/ahDIKwds OnItWddN/SjQL5DDf9+UuypWK/p+Qo+ek9TAI1QfIcuHu7LUTGngcZYaw2xcPskH+ZSE60eWW+6 gRWc7NzK5HwCmG3Q03quM85jEnRD6Z9Jcc/48Pi1A8nJ3+RgG/aaRdz6GrBZ6FZTmYYtjH0Fozb 4fSzBtV0UkfEiX/Y70c9+WvkNfco4nq4knTjxGt7+819dUv1xqcnQ== X-Received: by 2002:a17:90b:5210:b0:36a:1ed8:6fe6 with SMTP id 98e67ed59e1d1-370f0b58cefmr18409046a91.24.1780998767310; Tue, 09 Jun 2026 02:52:47 -0700 (PDT) Received: from localhost.localdomain (n49-176-80-106.mas22.nsw.optusnet.com.au. [49.176.80.106]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3713346cd9fsm13185172a91.2.2026.06.09.02.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 02:52:46 -0700 (PDT) From: geoffrey To: Krzysztof Kozlowski Cc: Alim Akhtar , Marek Szyprowski , Tomasz Figa , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Weigang He Subject: [PATCH 2/2] soc: samsung: exynos-pmu: refactor PMU regmap lookup helpers Date: Tue, 9 Jun 2026 19:52:24 +1000 Message-ID: <20260609095224.1706036-3-geoffreyhe2@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260609095224.1706036-1-geoffreyhe2@gmail.com> References: <20260609095224.1706036-1-geoffreyhe2@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Weigang He With the of_node leak in exynos_get_pmu_regmap() now fixed, the remaining reference handling is still awkward: exynos_get_pmu_regmap() obtains the PMU node by passing NULL to exynos_get_pmu_regmap_by_phandle(), which then treats its np argument as the PMU node directly. Factor the common PMU-node lookup into a helper, exynos_get_pmu_regmap_by_node(), which only borrows the node. Each public function then owns and releases the node it acquired: the node from of_find_matching_node() in exynos_get_pmu_regmap(), and the node from of_parse_phandle() in exynos_get_pmu_regmap_by_phandle(). exynos_get_pmu_regmap_by_phandle() now rejects propname == NULL with -EINVAL. Passing NULL was never a documented use of this interface, which looks up a PMU node through a phandle property; the only in-tree user of that form is exynos_get_pmu_regmap(), which no longer needs it. Document the requirement in the kerneldoc. No functional change for the supported callers. Signed-off-by: Weigang He --- drivers/soc/samsung/exynos-pmu.c | 57 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c index a5da2741852b4..ab19ad265aeb1 100644 --- a/drivers/soc/samsung/exynos-pmu.c +++ b/drivers/soc/samsung/exynos-pmu.c @@ -157,6 +157,28 @@ static const struct mfd_cell exynos_pmu_devs[] = { { .name = "exynos-clkout", }, }; +/* + * Look up the regmap of an already-probed exynos-pmu device. The caller + * retains ownership of @pmu_np; this helper does not take a reference. + */ +static struct regmap *exynos_get_pmu_regmap_by_node(struct device_node *pmu_np) +{ + struct device *dev; + + /* + * Determine if exynos-pmu device has probed and therefore regmap + * has been created and can be returned to the caller. Otherwise we + * return -EPROBE_DEFER. + */ + dev = driver_find_device_by_of_node(&exynos_pmu_driver.driver, pmu_np); + if (!dev) + return ERR_PTR(-EPROBE_DEFER); + + put_device(dev); + + return syscon_node_to_regmap(pmu_np); +} + /** * exynos_get_pmu_regmap() - Obtain pmureg regmap * @@ -174,7 +196,7 @@ struct regmap *exynos_get_pmu_regmap(void) if (!np) return ERR_PTR(-ENODEV); - regmap = exynos_get_pmu_regmap_by_phandle(np, NULL); + regmap = exynos_get_pmu_regmap_by_node(np); of_node_put(np); return regmap; @@ -184,44 +206,31 @@ EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); /** * exynos_get_pmu_regmap_by_phandle() - Obtain pmureg regmap via phandle * @np: Device node holding PMU phandle property - * @propname: Name of property holding phandle value + * @propname: Name of property holding phandle value (must not be NULL) * * Find the pmureg regmap previously configured in probe() and return regmap * pointer. * - * Return: A pointer to regmap if found or ERR_PTR error value. + * Return: A pointer to regmap on success or an ERR_PTR() error value; + * -EINVAL if @propname is NULL. */ struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np, const char *propname) { struct device_node *pmu_np; - struct device *dev; + struct regmap *regmap; - if (propname) - pmu_np = of_parse_phandle(np, propname, 0); - else - pmu_np = np; + if (!propname) + return ERR_PTR(-EINVAL); + pmu_np = of_parse_phandle(np, propname, 0); if (!pmu_np) return ERR_PTR(-ENODEV); - /* - * Determine if exynos-pmu device has probed and therefore regmap - * has been created and can be returned to the caller. Otherwise we - * return -EPROBE_DEFER. - */ - dev = driver_find_device_by_of_node(&exynos_pmu_driver.driver, - (void *)pmu_np); + regmap = exynos_get_pmu_regmap_by_node(pmu_np); + of_node_put(pmu_np); - if (propname) - of_node_put(pmu_np); - - if (!dev) - return ERR_PTR(-EPROBE_DEFER); - - put_device(dev); - - return syscon_node_to_regmap(pmu_np); + return regmap; } EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap_by_phandle); -- 2.43.0