mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] ata: remove dead checks and redundant code
@ 2026-11-04 13:14 shao.mingyin
  2026-11-04 13:14 ` [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check shao.mingyin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: shao.mingyin @ 2026-11-04 13:14 UTC (permalink / raw)
  To: dlemoal, cassel, hansg, linux-ide; +Cc: linux-kernel

This series removes two checks that the surrounding code already
guarantees and folds five duplicated cleanup paths in
zpodd_get_mech_type() into one.  It was found while reading libata.
There is no functional change intended; every patch is independent and
can be applied on its own or as any subset.

Patch 1 drops a test that is constant-false at compile time.
SATA_PMP_GSCR_DWORDS is 128, so "SATA_PMP_GSCR_DWORDS & 3" is zero and
the loop already terminates every fourth dword with a newline.

Patch 2 drops a dead rc check in ahci_platform_get_resources().  The
branch is only entered when IS_ERR() is true, so PTR_ERR() is negative
and "rc != 0" always holds.

Patch 3 rewrites zpodd_get_mech_type() to use one exit label instead of
five "kfree(buf); return ..." pairs.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check
  2026-11-04 13:14 [PATCH 0/3] ata: remove dead checks and redundant code shao.mingyin
@ 2026-11-04 13:14 ` shao.mingyin
  2026-11-05  3:12   ` Damien Le Moal
  2026-11-04 13:14 ` [PATCH 2/3] ata: libahci_platform: drop the dead error check shao.mingyin
  2026-11-04 13:14 ` [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type() shao.mingyin
  2 siblings, 1 reply; 7+ messages in thread
From: shao.mingyin @ 2026-11-04 13:14 UTC (permalink / raw)
  To: dlemoal, cassel, hansg, linux-ide; +Cc: linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

SATA_PMP_GSCR_DWORDS is 128, so "SATA_PMP_GSCR_DWORDS & 3" is always
zero and the branch is dead.  The loop already terminates every fourth
dword with a newline.

No functional change.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 95862dc34419..bebccda4d710 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -447,8 +447,6 @@ show_ata_dev_gscr(struct device *dev,
 				    ata_dev->gscr[i],
 				    ((i+1) & 3) ? ' ' : '\n');
 	}
-	if (SATA_PMP_GSCR_DWORDS & 3)
-		buf[written-1] = '\n';
 	return written;
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] ata: libahci_platform: drop the dead error check
  2026-11-04 13:14 [PATCH 0/3] ata: remove dead checks and redundant code shao.mingyin
  2026-11-04 13:14 ` [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check shao.mingyin
@ 2026-11-04 13:14 ` shao.mingyin
  2026-11-05  3:12   ` Damien Le Moal
  2026-11-04 13:14 ` [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type() shao.mingyin
  2 siblings, 1 reply; 7+ messages in thread
From: shao.mingyin @ 2026-11-04 13:14 UTC (permalink / raw)
  To: dlemoal, cassel, hansg, linux-ide; +Cc: linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

IS_ERR(hpriv->ahci_regulator) is true here, so PTR_ERR() is negative
and "rc != 0" is always true.  Jump to the error path directly.

No functional change.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index ae342080556a..819fbf200dc0 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -557,8 +557,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
 	hpriv->ahci_regulator = devm_regulator_get(dev, "ahci");
 	if (IS_ERR(hpriv->ahci_regulator)) {
 		rc = PTR_ERR(hpriv->ahci_regulator);
-		if (rc != 0)
-			goto err_out;
+		goto err_out;
 	}
 
 	hpriv->phy_regulator = devm_regulator_get(dev, "phy");

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type()
  2026-11-04 13:14 [PATCH 0/3] ata: remove dead checks and redundant code shao.mingyin
  2026-11-04 13:14 ` [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check shao.mingyin
  2026-11-04 13:14 ` [PATCH 2/3] ata: libahci_platform: drop the dead error check shao.mingyin
@ 2026-11-04 13:14 ` shao.mingyin
  2026-11-05  3:13   ` Damien Le Moal
  2 siblings, 1 reply; 7+ messages in thread
From: shao.mingyin @ 2026-11-04 13:14 UTC (permalink / raw)
  To: dlemoal, cassel, hansg, linux-ide; +Cc: linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

zpodd_get_mech_type() repeats "kfree(buf); return ..." at five
points.  Use one cleanup label and return the result from there.

No functional change.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c
index 414e7c63bd85..c03387d94006 100644
--- a/drivers/ata/libata-zpodd.c
+++ b/drivers/ata/libata-zpodd.c
@@ -53,6 +53,7 @@ static int eject_tray(struct ata_device *dev)
 static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
 {
 	char *buf;
+	enum odd_mech_type type;
 	unsigned int ret;
 	struct rm_feature_desc *desc;
 	struct ata_taskfile tf;
@@ -78,26 +79,25 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
 	ret = ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
 				buf, 16, 0);
 	if (ret) {
-		kfree(buf);
-		return ODD_MECH_TYPE_UNSUPPORTED;
+		type = ODD_MECH_TYPE_UNSUPPORTED;
+		goto out;
 	}
 
 	if (be16_to_cpu(desc->feature_code) != 3) {
-		kfree(buf);
-		return ODD_MECH_TYPE_UNSUPPORTED;
+		type = ODD_MECH_TYPE_UNSUPPORTED;
+		goto out;
 	}
 
-	if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1) {
-		kfree(buf);
-		return ODD_MECH_TYPE_SLOT;
-	} else if (desc->mech_type == 1 && desc->load == 0 &&
-		   desc->eject == 1) {
-		kfree(buf);
-		return ODD_MECH_TYPE_DRAWER;
-	} else {
-		kfree(buf);
-		return ODD_MECH_TYPE_UNSUPPORTED;
-	}
+	if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1)
+		type = ODD_MECH_TYPE_SLOT;
+	else if (desc->mech_type == 1 && desc->load == 0 &&
+		 desc->eject == 1)
+		type = ODD_MECH_TYPE_DRAWER;
+	else
+		type = ODD_MECH_TYPE_UNSUPPORTED;
+out:
+	kfree(buf);
+	return type;
 }
 
 /* Test if ODD is zero power ready by sense code */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check
  2026-11-04 13:14 ` [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check shao.mingyin
@ 2026-11-05  3:12   ` Damien Le Moal
  0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2026-11-05  3:12 UTC (permalink / raw)
  To: shao.mingyin, cassel, hansg, linux-ide; +Cc: linux-kernel

On 11/4/26 22:14, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> SATA_PMP_GSCR_DWORDS is 128, so "SATA_PMP_GSCR_DWORDS & 3" is always
> zero and the branch is dead.  The loop already terminates every fourth
> dword with a newline.
> 
> No functional change.
> 
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Looks OK.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] ata: libahci_platform: drop the dead error check
  2026-11-04 13:14 ` [PATCH 2/3] ata: libahci_platform: drop the dead error check shao.mingyin
@ 2026-11-05  3:12   ` Damien Le Moal
  0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2026-11-05  3:12 UTC (permalink / raw)
  To: shao.mingyin, cassel, hansg, linux-ide; +Cc: linux-kernel

On 11/4/26 22:14, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> IS_ERR(hpriv->ahci_regulator) is true here, so PTR_ERR() is negative
> and "rc != 0" is always true.  Jump to the error path directly.
> 
> No functional change.
> 
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Looks OK.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type()
  2026-11-04 13:14 ` [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type() shao.mingyin
@ 2026-11-05  3:13   ` Damien Le Moal
  0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2026-11-05  3:13 UTC (permalink / raw)
  To: shao.mingyin, cassel, hansg, linux-ide; +Cc: linux-kernel

On 11/4/26 22:14, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> zpodd_get_mech_type() repeats "kfree(buf); return ..." at five
> points.  Use one cleanup label and return the result from there.
> 
> No functional change.
> 
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Looks OK.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-05  3:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 13:14 [PATCH 0/3] ata: remove dead checks and redundant code shao.mingyin
2026-11-04 13:14 ` [PATCH 1/3] ata: libata-transport: drop the dead GSCR newline check shao.mingyin
2026-11-05  3:12   ` Damien Le Moal
2026-11-04 13:14 ` [PATCH 2/3] ata: libahci_platform: drop the dead error check shao.mingyin
2026-11-05  3:12   ` Damien Le Moal
2026-11-04 13:14 ` [PATCH 3/3] ata: libata-zpodd: use a single exit in zpodd_get_mech_type() shao.mingyin
2026-11-05  3:13   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®