From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27015155C87 for ; Wed, 18 Dec 2024 19:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734551375; cv=none; b=ajPK6MMrNkEZBfkTLYxflOTHqzrtlaEQ6kw0l0tqfFD7A33K7QDYMGg6QgQAjLrcObNTtQohrabtrmvV3+Oh6nJSeBN0S7BSldmdX0p9BmxzKP81Efwb+vzVFt3a04FuwMlMc23W0dr2ZlLQltYu7rb09BNjXi4Ssj0KkJSqNhU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734551375; c=relaxed/simple; bh=e4kWhQ/vqOVCugeZwisV6WwmhQyrpVRlRWMpA9Xgymk=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=DXaM5JLajTChCSKgxGieE/hcnyOb6FMkP7nK61SyzxmfyFg2tLV4OZFYrGexc3cK/KrMkEcyk3BQZyFGYCzJ3Tqoz/TIIw+pVdJS2IHeHxHRCI39WUwgYhkFAqcayKSP8ShGTz2bIZzvPNs9uw5wLdPJ8lIjOy/79kiKD241iDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rVeyWMh9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rVeyWMh9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E954C4CECD; Wed, 18 Dec 2024 19:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734551374; bh=e4kWhQ/vqOVCugeZwisV6WwmhQyrpVRlRWMpA9Xgymk=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=rVeyWMh9oYG4zAJ3WK0UbfOxP8mqU2raveVAp71TBOS6BSLmJT08qmYo4v2z2Ar4I bE4mU4Zge+whaqrQSEvnAQ0hFPUcdDAspLtrTtkzxY1QUQc9vBkbT4GtA4h070kiT9 bDhiRLm/mk2Qz9hltHvGBVUAHr4a6ClYfEj3DmUVj0vkaw2+HiKc0srODFzySTDi28 sa9/iCndYi9QgXM7BboGdzsQmmuxHWZFvaHKIqIgiyed7IhdB59Z1YHZcUatE8v5Ki yxOYhU+tdlu7NCYeSieZFLvat0YJ0LGu+88JxN3Y9QYSS4YXIzdbLn5sadPs76AOQt Vd0bM51wfPGwA== Message-ID: Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20241218033954.940888-1-joe@pf.is.s.u-tokyo.ac.jp> References: <20241218033954.940888-1-joe@pf.is.s.u-tokyo.ac.jp> Subject: Re: [PATCH v2] spmi: hisi-spmi-controller: manage the OF node reference in device initialization and cleanup From: Stephen Boyd Cc: linux-kernel@vger.kernel.org, krzk@kernel.org, Joe Hattori To: Joe Hattori , mchehab+huawei@kernel.org Date: Wed, 18 Dec 2024 11:49:32 -0800 User-Agent: alot/0.12.dev1+gaa8c22fdeedb Quoting Joe Hattori (2024-12-17 19:39:54) > spmi_controller_probe() increments the refcount of an OF node, but does > not release it. Instead, call of_node_get() in spmi_controller_alloc() > and release it in spmi_ctrl_release() to avoid the reference leak. Also > remove the lines in spmi_pmic_arb_bus_init() and spmi_controller_probe() > where a pdev's of_node is stored after spmi_controller_alloc() is > called. That last sentence says what is done but doesn't explain why. Please explain why stashing the of_node in the two drivers are removed. >=20 > This bug was found by an experimental static analysis tool that I am > developing. >=20 > Fixes: e562cf3aea3e ("spmi: hisi-spmi-controller: move driver from stagin= g") > Signed-off-by: Joe Hattori [...] > diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c > index fb0101da1485..e662a7a78df2 100644 > --- a/drivers/spmi/spmi.c > +++ b/drivers/spmi/spmi.c > @@ -36,6 +36,7 @@ static void spmi_ctrl_release(struct device *dev) > struct spmi_controller *ctrl =3D to_spmi_controller(dev); > =20 > ida_free(&ctrl_ida, ctrl->nr); > + of_node_put(dev->of_node); > kfree(ctrl); > } > =20 > @@ -458,7 +459,7 @@ struct spmi_controller *spmi_controller_alloc(struct = device *parent, > ctrl->dev.type =3D &spmi_ctrl_type; > ctrl->dev.bus =3D &spmi_bus_type; > ctrl->dev.parent =3D parent; > - ctrl->dev.of_node =3D parent->of_node; > + ctrl->dev.of_node =3D of_node_get(parent->of_node); Do we need to use device_set_node() here? > spmi_controller_set_drvdata(ctrl, &ctrl[1]); >