From nobody Thu Apr 2 12:33:35 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0428233B6EA for ; Sat, 28 Mar 2026 19:11:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774725080; cv=none; b=AdjLU9CTWrauBrVdWbEbK/uV6OKjFO+jllGUZw8D3RWgh9cJ/IrWzoV7XwLO5uxbYmg6ltnKzIuolX8+9jbLyd9pFPnLbmMKPTxkavZvFz8lyTHlH3SXfipFDjWXG3UNWxdB/6SyafMK5uQyOGfULbHSPWcf1F63CqZ09cUda+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774725080; c=relaxed/simple; bh=n0HQlw14mlBy8VD4FMqmG3MO5wp4QGqgD7K1F5YngUU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=etS3ziS7xZ/X+aFnscyLLM9hHxPBzCVjwWCD/bH7+0eEVZkHrgrgLKg54jfR1aQjz3mbhHe9kyZQ0cl+pdSC2SDZ3d5Ihie/gFXD6XPOa90Gh7gTFMoKKFs/ElP/2slaKtukevEbdeCL/XhHQ05R0x3gGJ+ZVbd9djnQ2Mxh8iU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aYDr6hm9; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aYDr6hm9" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-82418b0178cso1606440b3a.1 for ; Sat, 28 Mar 2026 12:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774725078; x=1775329878; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dKR1Fjg9EIN1soZ4AQdVbiBT3aVB1LqBRdnYJ6CyzyM=; b=aYDr6hm94XSdtRfAJ20EEnJopJox+LYqx1jpSc14wpHVeQe66/UhMuB+QkMEv9pYst gK17UU0o9WSzflSPwZtpw6XYNmHij3BviflHqmEU4PhE0oTTlqlPSF4OFWWxHkdkhpbL 94PF+DWF8XvI12YuSjKd0usIkrHlfaBQZ6DClmJxmF8S2cwkmvmQdI29R9P7mt2FtMGV N3aOmv1JHbKUqix3VAh4m2FS/cuzXnGF45GmVZ+DPqYteTdRFyh7pqKx4dSDt4+77k2W Pddnn9q+wL10rUPEXGAodx+WHZG+NnnN4USPPf5kGZVhpw3jeU+99JHlXXNc0CYjSbcw HcvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774725078; x=1775329878; 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=dKR1Fjg9EIN1soZ4AQdVbiBT3aVB1LqBRdnYJ6CyzyM=; b=QGMJBnBf/Uu5u2PPX1Hd+jUbd9SO3g+z/MCYVoYydRoBjMMXqiylCAdeYjlXBu9g6V gZZ2jHvTenyBP0QTuRcSeLRJtFH9EGGaX84iEdL4NI2FIzSqCDFVMEfnUGOTybJhhVCE NH+1yxAEWJhOeb6fem7VIf9lASfukPKOGQYf0mj00ymYk9oGofe8ItG0hmiXhPJzUGyr klPB6Uxp944BkMt31DhfESfi965KXJgk//+TKcA9Iuep0DpZtJ4h1o4GcA1zO+0FG6KY vgubGeB5d8MR4RYJlJ3vGuq2uPgcG+hJ6G1k6aMjAaea8DR7UGdnJJs6KJwxplA5tTX/ 1Yxg== X-Forwarded-Encrypted: i=1; AJvYcCWcLozoRkZW4yz4FAjZdvYGgwjdZ8XDus7fo91dB4EpadoAVGMK68EmcV8C2Fx8p0nUYBkxcjm4OURGWBo=@vger.kernel.org X-Gm-Message-State: AOJu0YzZ56tSvhoFP7HdEbmL1weSIrND7Njr3NZDu1Bjku53Ts3Jcv5w 4qGk1gWUZ0DSrob3JXSTD7AjMF/tWGUR4eE+biQWc4oGsX99cJ+/+L9u X-Gm-Gg: ATEYQzzLLjkieFo/GO5ti8wsSFHgXmmGX7Om3WjHUY7biNt0tsCnCHYz+kNRlH3kKAi 0IJsEtrnlQTTuokTXdGXC22eXoswy5EX70tXNnp2nwTNPr166/dKEPJoBCsN2Qsy0t8kz/AFs78 7UCGKksxg7/zJee5ci4Co6u7Y/Il1s2Hm5OlMexaEQ4Zs+GlMhxLrk8Cqlp1vvv715fo3gr0o0P 5Ap/koNHu520uuRvaGFSgfMmuWpPI28zC/z9bNfwHHMrIrLQi6dNXvKixx/Iqy4ADH4eSl28uN3 usHHIi5LytUmwv8XoZMfH+3Eqb3Tv0abVwYCcSJ7zZbdSJG/oT0dMiKI27MhPqIUNNB3rD3Z5aX w7e/UMylqEuJttlzmMpu7MpDLjNMYO1TVRmBZEEwT1yAYoktCRCo3bObmM9GzM0aqrFBUGPD5Ap e3a/Ukh3g5LWtQHAmO/LsUP2U/gM+ZJxYp3MDrwDxPPe8cNfjGEd4EAM8= X-Received: by 2002:a05:6a00:3697:b0:82a:18a2:91b9 with SMTP id d2e1a72fcca58-82c9602633fmr6665277b3a.49.1774725078111; Sat, 28 Mar 2026 12:11:18 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82caf97abfesm1497851b3a.1.2026.03.28.12.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 12:11:17 -0700 (PDT) From: Rosen Penev To: linux-ide@vger.kernel.org Cc: Damien Le Moal , Niklas Cassel , Hans de Goede , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCHv2] ata: libahci_platform: use flex array for platform PHYs Date: Sat, 28 Mar 2026 12:10:58 -0700 Message-ID: <20260328191058.311509-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a flexible array member with struct_size to combine the allocations. Added __counted_by support for extra runtime analysis. Signed-off-by: Rosen Penev Reviewed-by: Damien Le Moal --- v2: update commit title drivers/ata/ahci.h | 3 ++- drivers/ata/libahci_platform.c | 33 +++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 293b7fb216b5..9e8b6319025c 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -357,7 +357,6 @@ struct ahci_host_priv { * If platform uses PHYs. There is a 1:1 relation between the port number= and * the PHY position in this array. */ - struct phy **phys; unsigned nports; /* Number of ports */ void *plat_data; /* Other platform data */ unsigned int irq; /* interrupt line */ @@ -379,6 +378,8 @@ struct ahci_host_priv { /* only required for per-port MSI(-X) support */ int (*get_irq_vector)(struct ata_host *host, int port); + + struct phy *phys[] __counted_by(nports); }; /* diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index f37247e7a5cb..6e072d681341 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -482,15 +482,29 @@ struct ahci_host_priv *ahci_platform_get_resources(st= ruct platform_device *pdev, struct ahci_host_priv *hpriv; u32 mask_port_map =3D 0; u32 max_port; + int nports; if (!devres_open_group(dev, NULL, GFP_KERNEL)) return ERR_PTR(-ENOMEM); - hpriv =3D devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), + /* find maximum port id for allocating structures */ + max_port =3D ahci_platform_find_max_port_id(dev); + /* + * Set nports according to maximum port id. Clamp at + * AHCI_MAX_PORTS, warning message for invalid port id + * is generated later. + * When DT has no sub-nodes max_port is 0, nports is 1, + * in order to be able to use the + * ahci_platform_[en|dis]able_[phys|regulators] functions. + */ + nports =3D min(AHCI_MAX_PORTS, max_port + 1); + hpriv =3D devres_alloc(ahci_platform_put_resources, struct_size(hpriv, ph= ys, nports), GFP_KERNEL); if (!hpriv) goto err_out; + hpriv->nports =3D nports; + devres_add(dev, hpriv); /* @@ -573,23 +587,6 @@ struct ahci_host_priv *ahci_platform_get_resources(str= uct platform_device *pdev, goto err_out; } - /* find maximum port id for allocating structures */ - max_port =3D ahci_platform_find_max_port_id(dev); - /* - * Set nports according to maximum port id. Clamp at - * AHCI_MAX_PORTS, warning message for invalid port id - * is generated later. - * When DT has no sub-nodes max_port is 0, nports is 1, - * in order to be able to use the - * ahci_platform_[en|dis]able_[phys|regulators] functions. - */ - hpriv->nports =3D min(AHCI_MAX_PORTS, max_port + 1); - - hpriv->phys =3D devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GF= P_KERNEL); - if (!hpriv->phys) { - rc =3D -ENOMEM; - goto err_out; - } /* * We cannot use devm_ here, since ahci_platform_put_resources() uses * target_pwrs after devm_ have freed memory -- 2.53.0