public inbox for linux-ide@vger.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Damien Le Moal <dlemoal@kernel.org>, Niklas Cassel <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org
Subject: [PATCH 3/5] ata: libata-transport: use static struct ata_transport_internal to simplify match functions
Date: Mon, 30 Mar 2026 17:19:40 +0200	[thread overview]
Message-ID: <a0fbf4ec-cbd8-43e3-b52c-39eaf937052c@gmail.com> (raw)
In-Reply-To: <8592ed06-3a6f-45cb-9811-e163f31f7183@gmail.com>

Both matching functions can make use of static struct
ata_transport_internal. This eliminates the dependency on static
variable ata_scsi_transport_template, and it allows to remove helper
to_ata_internal(). Small drawback is that a forward declaration of
both functions is needed.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/ata/libata-transport.c | 44 ++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 9d594562c..68ae57a89 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -46,7 +46,11 @@ struct ata_internal {
 	struct transport_container link_attr_cont;
 	struct transport_container dev_attr_cont;
 };
-#define to_ata_internal(tmpl)	container_of(tmpl, struct ata_internal, t)
+
+static int ata_tlink_match(struct attribute_container *cont,
+			   struct device *dev);
+static int ata_tdev_match(struct attribute_container *cont,
+			  struct device *dev);
 
 #define tdev_to_device(d)					\
 	container_of((d), struct ata_device, tdev)
@@ -519,16 +523,6 @@ static bool ata_is_ata_dev(const struct device *dev)
 	return dev->release == ata_tdev_release;
 }
 
-static int ata_tdev_match(struct attribute_container *cont,
-			  struct device *dev)
-{
-	struct ata_internal *i = to_ata_internal(ata_scsi_transport_template);
-
-	if (!ata_is_ata_dev(dev))
-		return 0;
-	return &i->dev_attr_cont.ac == cont;
-}
-
 /**
  * ata_tdev_free  --  free an ATA transport device
  * @dev:	struct ata_device owning the transport device to free
@@ -660,16 +654,6 @@ static bool ata_is_link(const struct device *dev)
 	return dev->release == ata_tlink_release;
 }
 
-static int ata_tlink_match(struct attribute_container *cont,
-			    struct device *dev)
-{
-	struct ata_internal *i = to_ata_internal(ata_scsi_transport_template);
-
-	if (!ata_is_link(dev))
-		return 0;
-	return &i->link_attr_cont.ac == cont;
-}
-
 /**
  * ata_tlink_delete  --  remove an ATA link transport device
  * @link:	struct ata_link owning the link transport device to remove
@@ -762,6 +746,24 @@ static struct ata_internal ata_transport_internal = {
 	.dev_attr_cont.ac.match	= ata_tdev_match,
 };
 
+static int ata_tlink_match(struct attribute_container *cont,
+			    struct device *dev)
+{
+	if (!ata_is_link(dev))
+		return 0;
+
+	return &ata_transport_internal.link_attr_cont.ac == cont;
+}
+
+static int ata_tdev_match(struct attribute_container *cont,
+			  struct device *dev)
+{
+	if (!ata_is_ata_dev(dev))
+		return 0;
+
+	return &ata_transport_internal.dev_attr_cont.ac == cont;
+}
+
 /*
  * Setup / Teardown code
  */
-- 
2.53.0



  parent reply	other threads:[~2026-03-30 15:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 15:17 [PATCH 0/5] ata: libata-transport: series with further refactorings Heiner Kallweit
2026-03-30 15:18 ` [PATCH 1/5] ata: libata-transport: instantiate struct ata_internal statically Heiner Kallweit
2026-03-31  1:26   ` Damien Le Moal
2026-04-07 10:29   ` Hannes Reinecke
2026-03-30 15:18 ` [PATCH 2/5] ata: libata-transport: inline ata_attach|release_transport Heiner Kallweit
2026-03-31  1:29   ` Damien Le Moal
2026-04-07 10:30   ` Hannes Reinecke
2026-03-30 15:19 ` Heiner Kallweit [this message]
2026-03-31  1:37   ` [PATCH 3/5] ata: libata-transport: use static struct ata_transport_internal to simplify match functions Damien Le Moal
2026-04-07 10:32   ` Hannes Reinecke
2026-03-30 15:20 ` [PATCH 4/5] ata: libata-transport: split struct ata_internal Heiner Kallweit
2026-03-31  1:41   ` Damien Le Moal
2026-04-07 10:33   ` Hannes Reinecke
2026-03-30 15:21 ` [PATCH 5/5] ata: libata-transport: remove static variable ata_scsi_transport_template Heiner Kallweit
2026-03-31  1:42   ` Damien Le Moal
2026-03-31 11:41     ` Sergey Shtylyov
2026-03-31 20:09       ` Damien Le Moal
2026-04-07 10:39   ` Hannes Reinecke
2026-04-07 12:44     ` Heiner Kallweit
2026-04-02  8:34 ` [PATCH 0/5] ata: libata-transport: series with further refactorings Niklas Cassel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0fbf4ec-cbd8-43e3-b52c-39eaf937052c@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox