* 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 */
/* only required for per-port MSI(-X) support */
int (*get_irq_vector)(struct ata_host *host,
int port);
+
+ struct phy *phys[] __counted_by(nports);
};
/*
struct ahci_host_priv *hpriv;
u32 mask_port_map = 0;
u32 max_port;
+ int nports;
if (!devres_open_group(dev, NULL, GFP_KERNEL))
return ERR_PTR(-ENOMEM);
- hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv),
+ /* find maximum port id for allocating structures */
+ max_port = 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 = min(AHCI_MAX_PORTS, max_port + 1);
+ hpriv = devres_alloc(ahci_platform_put_resources, struct_size(hpriv, phys, nports),
GFP_KERNEL);
if (!hpriv)
goto err_out;
+ hpriv->nports = nports;
+
devres_add(dev, hpriv);
/*
goto err_out;
}
- /* find maximum port id for allocating structures */
- max_port = 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 = min(AHCI_MAX_PORTS, max_port + 1);
-
- hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL);
- if (!hpriv->phys) {
- rc = -ENOMEM;
- goto err_out;
- }
/*
* We cannot use devm_ here, since ahci_platform_put_resources() uses
* target_pwrs after devm_ have freed memory