* [PATCH] phy: mediatek: tphy: simplify main allocation
@ 2026-03-04 4:14 Rosen Penev
2026-08-12 13:32 ` Manivannan Sadhasivam
0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-03-04 4:14 UTC (permalink / raw)
To: linux-phy
Cc: Chunfeng Yun, Vinod Koul, Neil Armstrong, Matthias Brugger,
AngeloGioacchino Del Regno, Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
Use a flexible array member to replace kzalloc + kcalloc with a single
kzalloc.
Shuffled some code around as __counted_by requires the counting variable
to be assigned first.
Removed NULL check from of_get_match_data as it's never NULL per the
device table.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/phy/mediatek/phy-mtk-tphy.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
index acf506529507..3a6d61cf1cd0 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -340,10 +340,10 @@ struct mtk_tphy {
struct device *dev;
void __iomem *sif_base; /* only shared sif */
const struct mtk_phy_pdata *pdata;
- struct mtk_phy_instance **phys;
- int nphys;
int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
int src_coef; /* coefficient for slew rate calibrate */
+ int nphys;
+ struct mtk_phy_instance *phys[] __counted_by(nphys);
};
#if IS_ENABLED(CONFIG_DEBUG_FS)
@@ -1572,22 +1572,17 @@ static int mtk_tphy_probe(struct platform_device *pdev)
struct mtk_tphy *tphy;
struct resource res;
int port, ret;
+ size_t nphys;
- tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL);
+ nphys = of_get_child_count(np);
+ tphy = devm_kzalloc(dev, struct_size(tphy, phys, nphys), GFP_KERNEL);
if (!tphy)
return -ENOMEM;
+ tphy->nphys = nphys;
+ tphy->dev = dev;
tphy->pdata = of_device_get_match_data(dev);
- if (!tphy->pdata)
- return -EINVAL;
- tphy->nphys = of_get_child_count(np);
- tphy->phys = devm_kcalloc(dev, tphy->nphys,
- sizeof(*tphy->phys), GFP_KERNEL);
- if (!tphy->phys)
- return -ENOMEM;
-
- tphy->dev = dev;
platform_set_drvdata(pdev, tphy);
sif_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] phy: mediatek: tphy: simplify main allocation
2026-03-04 4:14 [PATCH] phy: mediatek: tphy: simplify main allocation Rosen Penev
@ 2026-08-12 13:32 ` Manivannan Sadhasivam
2026-08-12 18:15 ` Rosen Penev
0 siblings, 1 reply; 4+ messages in thread
From: Manivannan Sadhasivam @ 2026-08-12 13:32 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-phy, Chunfeng Yun, Vinod Koul, Neil Armstrong,
Matthias Brugger, AngeloGioacchino Del Regno, Kees Cook,
Gustavo A. R. Silva, moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
On Tue, Mar 03, 2026 at 08:14:00PM -0800, Rosen Penev wrote:
> Use a flexible array member to replace kzalloc + kcalloc with a single
> kzalloc.
>
> Shuffled some code around as __counted_by requires the counting variable
> to be assigned first.
>
> Removed NULL check from of_get_match_data as it's never NULL per the
> device table.
>
Please do not combine multiple fixes in a single patch. Also, the NULL check can
be kept for the case of sanity as it wouldn't hurt.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] phy: mediatek: tphy: simplify main allocation
2026-08-12 13:32 ` Manivannan Sadhasivam
@ 2026-08-12 18:15 ` Rosen Penev
2026-08-13 13:40 ` Manivannan Sadhasivam
0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-08-12 18:15 UTC (permalink / raw)
To: Manivannan Sadhasivam
Cc: linux-phy, Chunfeng Yun, Vinod Koul, Neil Armstrong,
Matthias Brugger, AngeloGioacchino Del Regno, Kees Cook,
Gustavo A. R. Silva, moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
On Wed, Aug 12, 2026 at 6:32 AM Manivannan Sadhasivam <mani@kernel.org> wrote:
>
> On Tue, Mar 03, 2026 at 08:14:00PM -0800, Rosen Penev wrote:
> > Use a flexible array member to replace kzalloc + kcalloc with a single
> > kzalloc.
> >
> > Shuffled some code around as __counted_by requires the counting variable
> > to be assigned first.
> >
> > Removed NULL check from of_get_match_data as it's never NULL per the
> > device table.
> >
>
> Please do not combine multiple fixes in a single patch. Also, the NULL check can
> be kept for the case of sanity as it wouldn't hurt.
hmm? There are no fixes here. Just a FAM conversion.
>
> - Mani
>
> --
> மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] phy: mediatek: tphy: simplify main allocation
2026-08-12 18:15 ` Rosen Penev
@ 2026-08-13 13:40 ` Manivannan Sadhasivam
0 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2026-08-13 13:40 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-phy, Chunfeng Yun, Vinod Koul, Neil Armstrong,
Matthias Brugger, AngeloGioacchino Del Regno, Kees Cook,
Gustavo A. R. Silva, moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
On Wed, Aug 12, 2026 at 11:15:43AM -0700, Rosen Penev wrote:
> On Wed, Aug 12, 2026 at 6:32 AM Manivannan Sadhasivam <mani@kernel.org> wrote:
> >
> > On Tue, Mar 03, 2026 at 08:14:00PM -0800, Rosen Penev wrote:
> > > Use a flexible array member to replace kzalloc + kcalloc with a single
> > > kzalloc.
> > >
> > > Shuffled some code around as __counted_by requires the counting variable
> > > to be assigned first.
> > >
> > > Removed NULL check from of_get_match_data as it's never NULL per the
> > > device table.
> > >
> >
> > Please do not combine multiple fixes in a single patch. Also, the NULL check can
> > be kept for the case of sanity as it wouldn't hurt.
> hmm? There are no fixes here. Just a FAM conversion.
Doesn't matter. A patch should do only one thing.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-13 13:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-04 4:14 [PATCH] phy: mediatek: tphy: simplify main allocation Rosen Penev
2026-08-12 13:32 ` Manivannan Sadhasivam
2026-08-12 18:15 ` Rosen Penev
2026-08-13 13:40 ` Manivannan Sadhasivam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®