From nobody Wed Apr 1 09:43:50 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 C4AAC36CDF3 for ; Mon, 30 Mar 2026 20:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774903077; cv=none; b=mkIyi1SQOWjUdMFyBOaFIxNlLZBaumULxcjYazMtEe+dfk7PpivCbp5/Vi8H/AOmsvwJVcKu2tFVhBMqEv7VYZl1WFYI1HwNd/oM30yYhxIb8WA7LdHhAXzIBU+u3H7Qr5niKmQU5VI9jwGULa+O2pJKJJ9SaUN6KZLVvRF7OBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774903077; c=relaxed/simple; bh=I6azZYdblCJz5ug7vx1CsFyj0Va/RBwHEN4bN2GaLfI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h2g7awtA93DOKxxaHMOZfE57rRb4x6aDbPGypBJrs0/rDxvGN49JT9A0j0Aun/TGdlgdhrXecJDN5k/XUXzbydMNXA5kEexigwH0sn95rU02Q4r2BBlKG8PiFnFBIE/l7+ygIOZzOjC6ESr5QCXwSjwImO1IDLWZKVUiWjVmXKM= 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=ROSKQEPE; arc=none smtp.client-ip=209.85.216.43 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="ROSKQEPE" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-35d8e548a05so2992731a91.1 for ; Mon, 30 Mar 2026 13:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774903075; x=1775507875; 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=yi1MOTZzQiL1ZMjYlLUzoyKuclzjHlNpIloD5RD5TAE=; b=ROSKQEPEqcpQcsbyfeljCxmFZeoq9pbRDDafu7yTq8zBMMtMoVlUeuiNheXSnmUDGC EiVVtONyGJE01SAoP/Je+BF9+eZLCeD7PjoTIKRkNtiN5J4kwc/GeR5N7E8g01wpFcVU KnsUF/J2Pw7e0eHEEFxBu34U/D8r5TxZrZS4e0h898HzerH9+SH+UsnHyjElb1Omqy0k 1BlI2SqQUw+7ZrGYL/7that9LBSFAA0AIPcs/tMTiUki5jShwyVoAuW1Klv6cimhUx5n +UgtcKbN3Cqvjyfja9zMG2078TqQfweaOR9DNnd/T7T9UGtVU/1Boiqu1PDor9AygypX 3Wiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774903075; x=1775507875; 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=yi1MOTZzQiL1ZMjYlLUzoyKuclzjHlNpIloD5RD5TAE=; b=k4vVYu3vI/bIMFXqXE+PWnxuqgai/7ehlpX2aIBTGwx1I5Z0yX+ZD+nJaHHOSd+t65 Q0V21SLD3YLCO7JAY3b/QL4jLuajcZJMV+LInEViSN76eVQ2FdqayVeL2v7ZMgCAQkeV iy1BK4L1w757T29DOe7wlN0ckncPg02Lt9N+ncD+oRPsemY6uyPOXzong71p+7AA/7vN OFc8MuNNXfq4vthHVAbta6H6EQxNKNqWp97bCDlFVPQjMR8EPzr6YJgV7zzr/N7InZ2h KZ3zmrpuoAJUSNPJL0S1R/5/24cI3tsSa3SlcJF8YGoAK0rvWFIVcrVqqw3voTebAR3h RrHg== X-Forwarded-Encrypted: i=1; AJvYcCXZMrsTXXdF8JiXz2mMcOswn+FytusRlVPHf7bRwc6gQx6l4yGv8tHu/tbRiJCzjMZuhpl0SNSeobuT/9c=@vger.kernel.org X-Gm-Message-State: AOJu0YyIqi2cebypzjtVgVIQ6JEYw9EArfLLY8i4kUAGcvyJDwNVkTZa ff7930qo4NfIanoO03V2re1n8tU5M0fT5n11gDdb2fBxfDeu0L+nAhEw X-Gm-Gg: ATEYQzz2sSsfFSiub07JPDSLHv6sQE/Mb9+X6lCu8dJIXzJnGGB0bufmhNjQd2aWAHu d95KXyYkySmuNer1a3o+8FtVCZcoW9Ag5fxYZo9qqXJlItUhSUattZjt2Y8J4QqgqbJUC9ZtP1q mAaoAbpFIfxssZBUO4ahIFD+d0r68HFW9S3Oo9v0PBFgRYgcY0Z2ge0OQHcQtnrWF6IZPREm0LT sJ24wBTDny1ai0k/nfEAMpQcHsthQytnSpphAa69JE3C9fYT2HsnhDgfOPuS7Mh12NGTpg4+ZXH vPGpjxAbhsxG1i13qA5K2I/EBAEfeR/dxdLobJzu+RDvRkmFkAklywxybSSlj1Rtj9l0bLBrMy1 GJ/2Ew92j7EHAZdWNiIkFU0evpz227FhZHE/jTfaJMcQ5HSqHjJoXemQc0iOl9/722sjb+fKjRu ftG1SOqdAL34egbcO02+GK1OsZWJwVAAo5iyQfMoZoEh/Z3l4KstCN61A= X-Received: by 2002:a05:6a21:7a45:b0:39c:8c0a:d09b with SMTP id adf61e73a8af0-39c8c0ad0fbmr14357138637.49.1774903075051; Mon, 30 Mar 2026 13:37:55 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cd7d0410bsm260281b3a.33.2026.03.30.13.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 13:37:54 -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: [PATCHv3] ata: libahci_platform: use flex array for platform PHYs Date: Mon, 30 Mar 2026 13:37:37 -0700 Message-ID: <20260330203737.3995-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" Modify struct ahci_host_priv to use a flexible array member for an adapter = port PHYs and use struct_size to combine the allocation of this array together w= ith the adapter private data structure. __counted_by() annotation is added for = the phys field to support runtime analysis. Signed-off-by: Rosen Penev Reviewed-by: Damien Le Moal --- v3: update description 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