From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796329333; b=ZU6w+4bN5UatijYn3ezrN6J8M2PzJkHssRfmKQ85vrd4GLvQIaFK8THhfHIjucpkxD9A tXJBb+zZcgnwyYmZrDiZk+jzm1v18iOyXlX+dwZlHzQiSw/Ee4AT6sy+09gxqiOa2lbte HntWpyv7uJICnTQbE8NrVRKt3Ya7jDAdPsPcGfkk8Wdsbr1/XLfyK5su5JiOcSEsXdpJS BuwTMhaXVNpUS9V/FqUZzhs9PBoN2uTRvafEzSUMB94+pP5UjuimYtLD4H8E9OoDhqqzu tnO5AC8j2a2Yhe0loh7kY+1XLNOk1igEzMJUPPLwlY9OSHDPOnR526vtN2xl89KzXHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329333; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=VQ+/9XePajxTsN6haX2j33Pw5kpmHbKZVE8IMAVir1Y=; b=BwQMN9864f4wYhfDn66TYhdTNAvpwVAGAeCuG8BZjkOSnoxH414TCqqbm9cETARlNoAL lPJUf3NtZ5z47lNAUh3N7LEklKzukjm68E2PbB9bCDh0VoXW0DCCAK3HsJk/9QwUZ7OnX pjma3Uq2uTdegCR1iFYjIsPLc9DZuAAvad7sEAZ5DjUlmnUV8FucaVfUJSxpmPUr+wMn2 7cC4wKNHv5eubQMiQ0vsncHaZNkW4CzOHBD4zOyfAnXOIpoPdN/dWC/VX0mp6k8X+bBy+ GC0dE5D08tBTFf1Zgpw+UJlZ3jVMFdAYZLyBkmTeojgLDF+EDQEJ8LRD47Nc5sQk0gw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="m/p54yv7"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A309606A688; Thu, 3 Dec 2026 20:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m/p54yv7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D34F91F00936; Thu, 3 Dec 2026 20:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329333; bh=VQ+/9XePajxTsN6haX2j33Pw5kpmHbKZVE8IMAVir1Y=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=m/p54yv7FAbmrkhJkE8w9aaaZv9x8P6f1J59l28lh555xqO01Vdwxh5gy/jXuZtOS YLobqyPchC7XwvKAX47BZE79RdG1sZ5B/+oW1mFfEYEAXFeLm/r2hZeCAqPbQNt70K sGsMg8Db/BctQ1/uerWPOkKCTQpUPBNJsg9yO37CUyM1mfIY0+CrrulkOBdeSgMq7V QHvL3SgykfrBgJoCG5E2ujJ8Wh3lrpcS5dD97PKC8KnqWU5lTu+y/doj3w/bXuvVkX zKuKt3DtjtTEFJ3f2IKG0A0CWaqN++p70JDN+KxrBDzj5pWth7NaiyHA+YlkeM51Dn BmNBfjHVRUrJQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver Reply-To: sashiko-reviews@lists.linux.dev To: "Alex Elder" Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203200948.1595470-4-elder@riscstar.com> References: <20261203200948.1595470-1-elder@riscstar.com> <20261203200948.1595470-4-elder@riscstar.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:22:12 +0000 X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] clk: tc9564: reversed devres order frees aux_data before aux device destroy - [Medium] clk: tc9564: memory leak of aux_data on ida_alloc() failure - [Medium] clk: tc9564: rate-based parent lookup breaks orphan clocks and probe order - [Low] clk: tc9564: duplicate of_clk_hw_onecell_get() and unused clock_data slots -- commit f8b60dd77f8cd8c579ca740b036d26f6d05abd3d Author: Alex Elder clk: toshiba: introduce a TC9564 clock driver This commit adds a platform clock driver for the Toshiba TC9564 SoC that registers a PLL, fixed-rate divider clocks, and gate clocks controlled by two MMIO registers. It also creates an auxiliary device for the embedded reset controller. > diff --git a/drivers/clk/clk-tc9564.c b/drivers/clk/clk-tc9564.c > new file mode 100644 > index 0000000000000..fb429d2ffe039 > --- /dev/null > +++ b/drivers/clk/clk-tc9564.c > @@ -0,0 +1,326 @@ [ ... ] > +/* Return the clk_hw pointer for a fixed clock having the given rate */ > +static struct clk_hw *fixed_hw_find_by_rate(struct clk_hw **fixed_hws, > + unsigned long rate) > +{ > + for (u32 i =3D 0; i < FIXED_COUNT; i++) > + if (clk_hw_get_rate(fixed_hws[i]) =3D=3D rate) > + return fixed_hws[i]; > + > + return NULL; > +} > + > +static struct clk_hw *gate_clock_register(struct device *dev, > + struct clk_hw **fixed_hws, > + const struct gate_init *ginit, > + void __iomem *regs) > +{ > + const char *name __free(kfree) =3D clock_name_alloc(dev, ginit->name); > + unsigned long flags =3D ginit->critical ? CLK_IS_CRITICAL : 0; > + void __iomem *reg =3D regs + ginit->offset; > + struct clk_hw *parent_hw; > + > + if (!name) > + return ERR_PTR(-ENOMEM); > + > + /* Each gate clock's parent is one of the fixed rate clocks */ > + parent_hw =3D fixed_hw_find_by_rate(fixed_hws, ginit->parent_rate); > + if (!parent_hw) { > + dev_err(dev, "failed to find %lu parent\n", ginit->parent_rate); > + > + return ERR_PTR(-EINVAL); > + } [Severity: Medium] Can fixed_hw_find_by_rate() permanently fail probe when the input clock provider has not registered yet or runs at a rate other than 25 MHz? If the input clock provider at index 0 is not yet registered, pll_register() succeeds with pll_hw orphaned at rate 0 instead of deferring probe. Each fixed clock inherits rate 0, so fixed_hw_find_by_rate() returns NULL and tc9564_clk_probe() fails permanently with -EINVAL. clk_hw_get_rate() also reads core->parent and core->rate without prepare_lock, racing with clk_core_reparent_orphans() if the input clock registers concurrently. Selecting each gate's parent statically by index into fixed_init[] avoids both problems and supports any input frequency. [ ... ] > +static struct clk_hw * > +gate_of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data) > +{ > + struct clk_hw **gate_hws =3D data; > + u32 id =3D clkspec->args[0]; > + > + if (id < GATE_COUNT) > + return gate_hws[id]; > + > + pr_err("%s: invalid clock ID %u\n", __func__, id); > + > + return ERR_PTR(-EINVAL); > +} [Severity: Low] As reported by Jerome Brunet on v4 [1], gate_of_clk_hw_onecell_get() duplicates of_clk_hw_onecell_get() only because clock_data prepends pll_hw and fixed_hws slots that are never read after probe. Keeping fixed_hws in a local array during probe and sizing clock_data to GATE_COUNT allows passing of_clk_hw_onecell_get and clock_data directly to devm_of_clk_add_hw_provider(). > +static void reset_adev_free(void *data) > +{ > + struct auxiliary_device *adev =3D data; > + > + ida_free(&reset_ids, adev->id); > + kfree(dev_get_platdata(&adev->dev)); > +} > + > +/* Create the TC9564 reset auxiliary device; called by probe */ > +static int devm_reset_register(struct device *dev, void __iomem *regs) > +{ > + struct tc9564_aux_data *aux_data; > + struct auxiliary_device *adev; > + int id; > + > + aux_data =3D kzalloc_obj(*aux_data); > + if (!aux_data) > + return -ENOMEM; > + aux_data->regs =3D regs; > + > + id =3D ida_alloc(&reset_ids, GFP_KERNEL); > + if (id < 0) > + return dev_err_probe(dev, id, "failed to get reset id\n"); [Severity: Medium] Does this return leak aux_data when ida_alloc() fails? > + adev =3D __devm_auxiliary_device_create(dev, TC9564_CLK_MODNAME, > + TC9564_RESET_DEV_NAME, > + aux_data, id); > + if (!adev) { > + ida_free(&reset_ids, id); > + kfree(aux_data); > + return -ENOMEM; > + } > + > + return devm_add_action_or_reset(dev, reset_adev_free, adev); > +} [Severity: Medium] Can reset_adev_free() free aux_data while the reset auxiliary device is still registered and cause a use-after-free in tc9564_reset_probe()? __devm_auxiliary_device_create() registers auxiliary_device_destroy() as a devres action before devm_add_action_or_reset() registers reset_adev_free(). Because devres runs actions in LIFO order, unbinding the clock device frees aux_data and releases adev->id before adev is removed from the bus: CPU0 CPU1 devres_release_all() reset_adev_free(adev) ida_free(&reset_ids, adev->id) kfree(aux_data) tc9564_reset_probe() aux_data =3D dev_get_platdata(dev) reset->regs =3D aux_data->regs <-- use-after-free auxiliary_device_destroy(adev) Freeing adev->id before adev is deleted also allows a concurrent probe of another TC9564 instance to reuse the ID and fail with -EEXIST. Allocating aux_data with devm_kzalloc_obj() and registering an IDA-release devres action before __devm_auxiliary_device_create() keeps the teardown order saf= e. [1] https://lore.kernel.org/r/179631464066.3767986.13287406761565723851.b4-= reply@b4 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203200948.1595= 470-1-elder@riscstar.com?part=3D3