Skip to contentSkip to conversation

ata: sata_mv: Fix the error handling of mv_chip_id()

PATCH Applied Zheyu Ma 2 participants 2 messages Oct 22, 2021 – Oct 25, 2021 libata

lore
Share & tools
lore

Zheyu Ma

author
#0 lore raw

PATCH v2 1/1 ata: sata_mv: Fix the error handling of mv_chip_id()

mv_init_host() propagates the value returned by mv_chip_id() which in turn gets propagated by mv_pci_init_one() and hits local_pci_probe().

During the process of driver probing, the probe function should return < 0 for failure, otherwise, the kernel will treat value > 0 as success.

Since this is a bug rather than a recoverable runtime error we should use dev_alert() instead of dev_err().

---
Changes in v2:
- Change the error code
- Change the logging function

---
 drivers/ata/sata_mv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +2 -2
index 9d86203e1e7a..c53633d47bfb 100644
@@ -3896,8 +3896,8 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
 		break;
 
 	default:
-		dev_err(host->dev, "BUG: invalid board index %u\n", board_idx);
-		return 1;
+		dev_alert(host->dev, "BUG: invalid board index %u\n", board_idx);
+		return -EINVAL;
 	}
 
 	hpriv->hp_flags = hp_flags;
Signature · 1 line
2.17.6
#1 lore raw
Quoted 24 lines · Zheyu Ma

mv_init_host() propagates the value returned by mv_chip_id() which in turn gets propagated by mv_pci_init_one() and hits local_pci_probe().

During the process of driver probing, the probe function should return < 0 for failure, otherwise, the kernel will treat value > 0 as success.

Since this is a bug rather than a recoverable runtime error we should use dev_alert() instead of dev_err().

---
Changes in v2:
- Change the error code
- Change the logging function

---
 drivers/ata/sata_mv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +0 -0
index 9d86203e1e7a..c53633d47bfb 100644

drivers/ata/sata_mv.c static int mv_chip_id(struct ata_host *host, unsigned int board_idx) · line 3903

Quoted 10 lines
drivers/ata/sata_mv.c +2 -2
@@ -3896,8 +3896,8 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
 		break;
 
 	default:
-		dev_err(host->dev, "BUG: invalid board index %u\n", board_idx);
-		return 1;
+		dev_alert(host->dev, "BUG: invalid board index %u\n", board_idx);
+		return -EINVAL;
 	}
 
 	hpriv->hp_flags = hp_flags;

Applied to for-5.15-fixes. Thanks !

Signature · 2 lines
Damien Le Moal
Western Digital Research