ata: ahci: Loop over the actual number of ports, not the maximum
[oweals/u-boot.git] / drivers / ata / ahci.c
index 7c56f57bfdef5eb70268296158323a124d12514b..333f0457f6fb4d9031f9782d1d138b679fb2e8fd 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) Freescale Semiconductor, Inc. 2006.
  * Author: Jason Jin<Jason.jin@freescale.com>
  *         Zhang Wei<wei.zhang@freescale.com>
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
  * with the reference on libata and ahci drvier in kernel
  *
  * This driver provides a SCSI interface to SATA.
@@ -935,7 +934,7 @@ static int ahci_scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
 {
        struct ahci_uc_priv *uc_priv;
 #ifdef CONFIG_DM_SCSI
-       uc_priv = dev_get_uclass_priv(dev);
+       uc_priv = dev_get_uclass_priv(dev->parent);
 #else
        uc_priv = probe_ent;
 #endif
@@ -981,7 +980,7 @@ static int ahci_start_ports(struct ahci_uc_priv *uc_priv)
 
        linkmap = uc_priv->link_port_map;
 
-       for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) {
+       for (i = 0; i < uc_priv->n_ports; i++) {
                if (((linkmap >> i) & 0x01)) {
                        if (ahci_port_start(uc_priv, (u8) i)) {
                                printf("Can not start port %d\n", i);
@@ -1026,7 +1025,7 @@ void scsi_low_level_init(int busdevfunc)
 
 #ifndef CONFIG_SCSI_AHCI_PLAT
 # if defined(CONFIG_DM_PCI) || defined(CONFIG_DM_SCSI)
-int achi_init_one_dm(struct udevice *dev)
+int ahci_init_one_dm(struct udevice *dev)
 {
        struct ahci_uc_priv *uc_priv = dev_get_uclass_priv(dev);
 
@@ -1035,7 +1034,7 @@ int achi_init_one_dm(struct udevice *dev)
 #endif
 #endif
 
-int achi_start_ports_dm(struct udevice *dev)
+int ahci_start_ports_dm(struct udevice *dev)
 {
        struct ahci_uc_priv *uc_priv = dev_get_uclass_priv(dev);