From: Alex Elder <elder@riscstar.com>
To: Haylen Chu <heylenay@4d2.org>,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
mturquette@baylibre.com, sboyd@kernel.org,
p.zabel@pengutronix.de, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
dlan@gentoo.org
Cc: inochiama@outlook.com, guodong@riscstar.com,
devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
spacemit@lists.linux.dev, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
Date: Thu, 8 May 2025 15:17:56 -0500 [thread overview]
Message-ID: <ec118fe2-00c3-47d0-957d-cbd7a8ecfbb1@riscstar.com> (raw)
In-Reply-To: <dcc42499-4c6b-450e-8449-414501d6ab62@riscstar.com>
On 5/8/25 3:04 PM, Alex Elder wrote:
> On 5/7/25 11:46 PM, Haylen Chu wrote:
>> On Tue, May 06, 2025 at 04:06:34PM -0500, Alex Elder wrote:
>>> Add a new reset_name field to the spacemit_ccu_data structure. If it is
>>> non-null, the CCU implements a reset controller, and the name will be
>>> used as the name for the auxiliary device that implements it.
>>>
>>> Define a new type to hold an auxiliary device as well as the regmap
>>> pointer that will be needed by CCU reset controllers. Set up code to
>>> initialize and add an auxiliary device for any CCU that implements reset
>>> functionality.
>>>
>>> Make it optional for a CCU to implement a clock controller. This
>>> doesn't apply to any of the existing CCUs but will for some new ones
>>> that will be added soon.
>>>
>>> Signed-off-by: Alex Elder <elder@riscstar.com>
>>> ---
>>> drivers/clk/spacemit/ccu-k1.c | 85 +++++++++++++++++++++++++++++++----
>>> include/soc/spacemit/ccu_k1.h | 12 +++++
>>> 2 files changed, 89 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/
>>> ccu-k1.c
>>> index 9545cfe60b92b..6b1845e899e5f 100644
>>> --- a/drivers/clk/spacemit/ccu-k1.c
>>> +++ b/drivers/clk/spacemit/ccu-k1.c
>>
>> ...
>>
>>> +static void spacemit_cadev_release(struct device *dev)
>>> +{
>>> + struct auxiliary_device *adev = to_auxiliary_dev(dev);
>>> +
>>> + kfree(to_spacemit_ccu_adev(adev));
>>> +}
>>
>> spacemit_ccu_adev structures are allocated with devm_kzalloc() in
>> spacemit_ccu_reset_register(), which means its lifetime is bound to the
>> driver and it'll be automatically released after driver removal; won't
>> there be a possibility of double-free? I think the release callback
>> could be simply dropped.
>
> You are correct. And unfortunately I didn't include the fix
> for this in the patches I just posted, because somehow this
> message was not included with the group in my mail program.
>
> I'm going to send v8 after I fix this and verify it again.
To be clear, the fix is to use kzalloc(), rather than calling
devm_kzalloc() with the parent device as first argument.
I'll also include <linux/slab.h> to avoid the warning
reported by the kernel test robot.
-Alex
>
> -Alex
>
>
>> ...
>>
>>> +static int spacemit_ccu_reset_register(struct device *dev,
>>> + struct regmap *regmap,
>>> + const char *reset_name)
>>> +{
>>> + struct spacemit_ccu_adev *cadev;
>>> + struct auxiliary_device *adev;
>>> + static u32 next_id;
>>> + int ret;
>>> +
>>> + /* Nothing to do if the CCU does not implement a reset
>>> controller */
>>> + if (!reset_name)
>>> + return 0;
>>> +
>>> + cadev = devm_kzalloc(dev, sizeof(*cadev), GFP_KERNEL);
>>
>> Here spacemit_ccu_adev is allocated.
>>
>>> + if (!cadev)
>>> + return -ENOMEM;
>>> + cadev->regmap = regmap;
>>> +
>>> + adev = &cadev->adev;
>>> + adev->name = reset_name;
>>> + adev->dev.parent = dev;
>>> + adev->dev.release = spacemit_cadev_release;
>>> + adev->dev.of_node = dev->of_node;
>>> + adev->id = next_id++;
>>> +
>>> + ret = auxiliary_device_init(adev);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + ret = auxiliary_device_add(adev);
>>> + if (ret) {
>>> + auxiliary_device_uninit(adev);
>>> + return ret;
>>> + }
>>> +
>>> + return devm_add_action_or_reset(dev, spacemit_adev_unregister,
>>> adev);
>>> +}
>>> +
>>
>> Best regards,
>> Haylen Chu
>
next prev parent reply other threads:[~2025-05-08 20:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
2025-05-07 22:35 ` Yixun Lan
2025-05-08 2:19 ` Alex Elder
2025-05-08 12:02 ` Krzysztof Kozlowski
2025-05-08 12:17 ` Alex Elder
2025-05-08 12:36 ` Krzysztof Kozlowski
2025-05-08 12:42 ` Alex Elder
2025-05-08 12:40 ` Yixun Lan
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
2025-05-08 4:16 ` Haylen Chu
2025-05-08 11:40 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
2025-05-08 4:09 ` kernel test robot
2025-05-08 4:46 ` Haylen Chu
2025-05-08 20:04 ` Alex Elder
2025-05-08 20:17 ` Alex Elder [this message]
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
2025-05-08 5:38 ` Haylen Chu
2025-05-08 11:55 ` Alex Elder
2025-05-08 12:47 ` Haylen Chu
2025-05-08 9:01 ` Philipp Zabel
2025-05-08 12:05 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
2025-05-08 9:11 ` Philipp Zabel
2025-05-08 12:29 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec118fe2-00c3-47d0-957d-cbd7a8ecfbb1@riscstar.com \
--to=elder@riscstar.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlan@gentoo.org \
--cc=guodong@riscstar.com \
--cc=heylenay@4d2.org \
--cc=inochiama@outlook.com \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mturquette@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=spacemit@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox