Skip to contentSkip to conversation

drivers/ata/libata-core: check return value of sata_scr_read()

PATCH In review Li Zhong 2 participants 3 messages Aug 28, 2022 – Sep 3, 2022 libata

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 drivers/ata/libata-core: check return value of sata_scr_read()

sata_scr_read() could return 0 on failure. Check the return value.

---
 drivers/ata/libata-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +2 -1
index 826d41f341e4..ae08c7d35cb0 100644
@@ -3021,7 +3021,8 @@ static void sata_print_link_status(struct ata_link *link)
 
 	if (sata_scr_read(link, SCR_STATUS, &sstatus))
 		return;
-	sata_scr_read(link, SCR_CONTROL, &scontrol);
+	if (sata_scr_read(link, SCR_CONTROL, &scontrol))
+		return;
 
 	if (ata_phys_link_online(link)) {
 		tmp = (sstatus >> 4) & 0xf;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 1 line · Li Zhong

sata_scr_read() could return 0 on failure. Check the return value.

Looks OK as a fix but the above sentence has a bug. 0 indicates success, not failure. So this should read:

sata_scr_read() may fail with a negative error code. Check that function return value when reading the control register.

Also, the patch title should be something like:

ata: libata-core: Check errors in sata_print_link_status()

Quoted 20 lines
---
 drivers/ata/libata-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +2 -1
index 826d41f341e4..ae08c7d35cb0 100644
@@ -3021,7 +3021,8 @@ static void sata_print_link_status(struct ata_link *link)
 
 	if (sata_scr_read(link, SCR_STATUS, &sstatus))
 		return;
-	sata_scr_read(link, SCR_CONTROL, &scontrol);
+	if (sata_scr_read(link, SCR_CONTROL, &scontrol))
+		return;
 
 	if (ata_phys_link_online(link)) {
 		tmp = (sstatus >> 4) & 0xf;
Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#2 lore raw
Quoted 7 lines · Damien Le Moal
Quoted 1 line · Li Zhong

sata_scr_read() could return 0 on failure. Check the return value.

Looks OK as a fix but the above sentence has a bug. 0 indicates success, not failure. So this should read:

Quoted 7 lines

sata_scr_read() may fail with a negative error code. Check that function return value when reading the control register.

Also, the patch title should be something like:

ata: libata-core: Check errors in sata_print_link_status()

Thanks. Will fix it in the new version.

Quoted 25 lines
Quoted 11 lines
---
 drivers/ata/libata-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +0 -0
index 826d41f341e4..ae08c7d35cb0 100644

drivers/ata/libata-core.c static void sata_print_link_status(struct ata_link *link) · line 3028

Quoted 9 lines
drivers/ata/libata-core.c +2 -1
@@ -3021,7 +3021,8 @@ static void sata_print_link_status(struct ata_link *link)
 
      if (sata_scr_read(link, SCR_STATUS, &sstatus))
              return;
-     sata_scr_read(link, SCR_CONTROL, &scontrol);
+     if (sata_scr_read(link, SCR_CONTROL, &scontrol))
+             return;
 
      if (ata_phys_link_online(link)) {
              tmp = (sstatus >> 4) & 0xf;

--
Damien Le Moal
Western Digital Research