From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A43CEDEC04 for ; Wed, 4 Mar 2026 04:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=h4+RxyEzVVfMeQjameS7WuxM58R+fJWfpg/21/ewVWI=; b=ik+le8o4Lfgt99ZXxT8YlNt3Sp G+dkxs8r8Ka6JmssQUlWO0w9gW9FQ4Ch6zkY85bWxhf9vkEGH1SmDuRnt06Bvtb+iYlpzZ8YVHzTU PvoQZCv/bMnROHf799XZ1L8khdEPwbpoynrAh4LQUSv0m1yV/xi9wbUBCDzD3YMqRuD3hKxHMTCrH tnPS/OZUKQyUg9A6D+NWpRWX8XSaKxCBEegZoeoUSadWlmEoWEhCaQxRliSQXRqp2snG8yz74gG3W lP7vEoRkDw7wtvfNNBYwPJ2txz+sM8kUos+kGmamCFI56TF3SFpxxdW25GhxX+vFcjNUmMhNSm+Sp MWIn6oDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vxdwZ-0000000GRXr-0laX; Wed, 04 Mar 2026 04:34:43 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vxdwW-0000000GRWi-0lSc for linux-mediatek@lists.infradead.org; Wed, 04 Mar 2026 04:34:41 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2ae56f8776dso18834765ad.3 for ; Tue, 03 Mar 2026 20:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772598879; x=1773203679; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=h4+RxyEzVVfMeQjameS7WuxM58R+fJWfpg/21/ewVWI=; b=PBr+3alqtjI9o4M2o0t2FQyibJ6N627RvN2osXpue2FgvRsiJe+AjDc1isgodNIVp0 m+Y6+GLyOqrSzbftc7usUeIKfjI3I+XD25b/7AAx+ef5sLDK8qIx5yg+ivy2lrhUnAEr IG+vS0m4awtsnBs+bEpRWk6FKe6savkNaZd9fWO1Nr6LleeNPlpPj1AKt9Fql5nxUvSm XPGToCXUgdWyhFBXcDwetkfNYBvqu1Cp5cDwCmKqsRtWm4O6QvxbaHQc4WdYHUNZE2rE JVsk9FyPTwgZwp3NFauFQ3SSfYmw8j33RuZqy90V+7nCz5JWvsr2WYFsbeCYdNHNc6PA zLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772598879; x=1773203679; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h4+RxyEzVVfMeQjameS7WuxM58R+fJWfpg/21/ewVWI=; b=Ews0oeWLEK5DbgSmEVXSNxxCgnu9nDKuzR1NuLZ99jEptb9/E/BmIN0WzQBmqYRA8T 5rV+Mr2mY0oGPuySPSUm7Oix9g/7uBL9zCrMdxe0PY5XD85TIT4dCug1a7eDZb90PPfd haGXgfTAlVp/w2lAGqZKfUmkF8USDtoPimM8/eTVjcg903gFYfDqsqt/4qlXdsJdKR9K xe93Qn2m/zp2MGAHFKYGQUX9oWuPpAWx74D/45WnmkrfI8O3dCZzh5PeA6IEGkG1z8o/ p8cvV75oFEmgj6bLUgavfpUTezvQ9VQTDhH3EIyK4WoN9ElKpdGhjKGEZriyuUY3O6Zj thXA== X-Forwarded-Encrypted: i=1; AJvYcCU2u73yTFt6DiRyVbt/4xSemIJm0+Oa45BQfPt6bV3IEucGludcsZpEw8TmVZbL8nof52fa6uWXm/rLhk2TkA==@lists.infradead.org X-Gm-Message-State: AOJu0YzF8eLohZTEcIcAXyXJd6v0BDhQaOT0OCJXQmxpikC87K3Gb9kL 721ijSSH6M8EUik1xi7+eDphntPl69Y/cZIpAiOxpT2WDG79cuWJMgRw X-Gm-Gg: ATEYQzxedItxvoGe1pPCLpVeGOFpSkcUWFgTczvf5cUJCe1B0Dr3dHGvKB+vl2sCykT F8Gpl0ezX49uS5tcSDEEcNjBceDwvgoc/QhlL2a6ZU8FsNS72tnLrjxgTlp3IRp4M1MNF/x9BRB yflWg+wOOrbjiONkoDuCSeBD71lnkto1i25oUzHdG3NYURmlIxGthx4E/cAy5lM7Qffk+m7VX8a 82hJ0mAZY9DmypRmugsJccR85sgQ9JKbZEiV8GzeeyyDvPKkr80NQuoaM5n/rckOBUnlKS3Wu2Q HXsrfH/WvzBeZj4tEo6XsFDgS1AUFMnST+892WaMW82I8hqDQaSaiyihIIwlZCnF/At+Zv38Las 3HXFSq/qNzHLaGadDpFGfR1fmOrIEWA8pIaWZEBoiJL6PerFVAGQgAJVTS656k/ZQTrUDFdPvCN ukVzeBymAwoIfALdMDzy1ghoJc0kSfK7A775xj+lPp39etzFY9pT4GzC30vNrn0iBc X-Received: by 2002:a17:903:1a67:b0:2ae:57cc:63d7 with SMTP id d9443c01a7336-2ae6a9de1a3mr7732125ad.7.1772598878948; Tue, 03 Mar 2026 20:34:38 -0800 (PST) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae4651e409sm115173435ad.44.2026.03.03.20.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 20:34:38 -0800 (PST) From: Rosen Penev To: linux-phy@lists.infradead.org Cc: Chunfeng Yun , Vinod Koul , Neil Armstrong , Matthias Brugger , AngeloGioacchino Del Regno , Kees Cook , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek USB3 PHY DRIVER), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek USB3 PHY DRIVER), linux-kernel@vger.kernel.org (open list:ARM/Mediatek SoC support), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] phy: mediatek: xsphy: reduce main allocation Date: Tue, 3 Mar 2026 20:34:20 -0800 Message-ID: <20260304043420.14151-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260303_203440_228297_9CD812AB X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 --- 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); -- 2.53.0