]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ata: libata-transport: use static struct ata_transport_internal to simplify match...
authorHeiner Kallweit <hkallweit1@gmail.com>
Thu, 2 Apr 2026 13:30:48 +0000 (15:30 +0200)
committerNiklas Cassel <cassel@kernel.org>
Thu, 2 Apr 2026 19:01:02 +0000 (21:01 +0200)
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.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
drivers/ata/libata-transport.c

index 9d594562c0a7544c3aa7bf777d3eb6a5772539f9..c3055e44d87d8f9702ae63eaf4905f228bbfa657 100644 (file)
@@ -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
  */