From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) (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 6F4A521CC4F for ; Fri, 6 Mar 2026 19:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.202.169.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772824468; cv=none; b=tREkKpHFqlAM3kV+Mp8NQDdVaZjUyFTHSTTJSBf+gpQrh7aUo+8JEvxMhxIo4ysOWgEppg9Oe5kHsKbT1NJKJoK9VCY2IrzQmodX3J3kKQrIRv0CaDrtF/c/z1t8lY4Eyg/siP6B5K6KoOUNAIVMWH9LAbH1xjRo/0tPHsJvDbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772824468; c=relaxed/simple; bh=IDhr2Ebb2b2qZTLe5TRuCnNBOYcnVLmyAusvRz/t6es=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Nq6U5Bfaf2VvoFUKb6NAm28ZnK9gOvPXDcfCZPtKeyW0us24tJ1DYSMRfdWZS/9I2ZjEXoVVhddADZXD0gmb6vPhlEp9zxdQhXs6Y2jhh0Ql1jZNNkXEuh+ZonkQgp7/ba9/xh4kPX2q9+A7pasMKLUwhHeN2zIuoKf8TZNRoj0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com; spf=pass smtp.mailfrom=embeddedor.com; dkim=pass (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b=tscGF14g; arc=none smtp.client-ip=44.202.169.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=embeddedor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b="tscGF14g" Received: from eig-obgw-6001b.ext.cloudfilter.net ([10.0.30.143]) by cmsmtp with ESMTPS id yTqhvP5MZSkcfyad0vR6U8; Fri, 06 Mar 2026 19:14:26 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id yacpvk7Elcu11yacpv3wqe; Fri, 06 Mar 2026 19:14:15 +0000 X-Authority-Analysis: v=2.4 cv=bKYWIO+Z c=1 sm=1 tr=0 ts=69ab2792 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=k5Y5iPg+dmTXVWgYE/XtfQ==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=7T7KSl7uo7wA:10 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=4KyMBbRfhRQTWuXm2KoA:9 a=QEXdDO2ut3YA:10 a=2aFnImwKRvkU0tJ3nQRT:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UX70eqTPldRVlnp6TbQSbemdGWZN5RJN1ptIeYYKtG8=; b=tscGF14g6RrBEKmnC12nH+q23r Saqh4tVvRYVfYwGG4W9VhMRiHBWi0hqEEUGmgZC8Ukq0nxhBVO+eQTUWRCYyOkOkzBY86UKY7JmcT xeYajce0NP1LNBRReeW4AOK+oU5cHpOHowWYex2w0ckcKWT7blQZrrp2Sd7VuTPXM6/TKUcqvzsXG 9GT/bFcd2K8QFTC86ivNaAq+YrQrK2bZxAuXgqZQx+r/iSx35D+TU2Wur7+pnN99AWbYsBnUN9E8j 71MyrgfhpLgiq+QMZaG8wU73aJmO8mSCyREaynLGLrekKMTE6Ce01pPEMXZxukz7m4imiwkcpTuio Y5vRmDcA==; Received: from [177.238.16.13] (port=46342 helo=[192.168.0.21]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.99.1) (envelope-from ) id 1vyacn-000000018a0-0TQQ; Fri, 06 Mar 2026 13:14:13 -0600 Message-ID: <1b50b40e-6682-4156-a60a-c2725527d648@embeddedor.com> Date: Fri, 6 Mar 2026 13:13:43 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] phy: mediatek: xsphy: reduce main allocation To: Rosen Penev , linux-phy@lists.infradead.org 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" References: <20260304043420.14151-1-rosenp@gmail.com> Content-Language: en-US From: "Gustavo A. R. Silva" In-Reply-To: <20260304043420.14151-1-rosenp@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 177.238.16.13 X-Source-L: No X-Exim-ID: 1vyacn-000000018a0-0TQQ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.0.21]) [177.238.16.13]:46342 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 12 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfIspF0yu5vzUmyYEVZRVPZ2GIOrjdVRG66/o41wKSeASav6PbF7xGn0YbKIMoNWAoF0uXmrPfJjgARkotqFYP6gXOR8z+7VgCf9VPQxOLHG3/b+2bgdZ 08iXdS6okCMFKx/hNR6p5TkJhRStSgj4N/P+YE3LXnl+/PIf1nUmw/BrM2AQICPDBiT2KEeMH+qe56tgWMi345ryviFSHj4qs8D0S2IKAj0aQLd3lttTI3vl On 3/4/26 13:34, Rosen Penev wrote: > Instead of kzalloc and kcalloc, we can use a flex array to reduce to a > single allocation. > > Also added __counted_by() for extra possible analysis. > > Signed-off-by: Rosen Penev Reviewed-by: Gustavo A. R. Silva Thanks -Gustavo > --- > drivers/phy/mediatek/phy-mtk-xsphy.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c b/drivers/phy/mediatek/phy-mtk-xsphy.c > index c0ddb9273cc3..cc1d66954212 100644 > --- a/drivers/phy/mediatek/phy-mtk-xsphy.c > +++ b/drivers/phy/mediatek/phy-mtk-xsphy.c > @@ -112,10 +112,10 @@ struct xsphy_instance { > struct mtk_xsphy { > struct device *dev; > void __iomem *glb_base; /* only shared u3 sif */ > - struct xsphy_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 xsphy_instance *phys[] __counted_by(nphys); > }; > > static void u2_phy_slew_rate_calibrate(struct mtk_xsphy *xsphy, > @@ -515,18 +515,15 @@ static int mtk_xsphy_probe(struct platform_device *pdev) > struct resource *glb_res; > struct mtk_xsphy *xsphy; > struct resource res; > + size_t nphys; > int port; > > - xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL); > + nphys = of_get_child_count(np); > + xsphy = devm_kzalloc(dev, struct_size(xsphy, phys, nphys), GFP_KERNEL); > if (!xsphy) > return -ENOMEM; > > - xsphy->nphys = of_get_child_count(np); > - xsphy->phys = devm_kcalloc(dev, xsphy->nphys, > - sizeof(*xsphy->phys), GFP_KERNEL); > - if (!xsphy->phys) > - return -ENOMEM; > - > + xsphy->nphys = nphys; > xsphy->dev = dev; > platform_set_drvdata(pdev, xsphy); >