Skip to content

Commit 365da8c

Browse files
hkallweitfloatious
authored andcommitted
ata: libata-transport: use static struct ata_transport_internal to simplify match functions
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>
1 parent f212246 commit 365da8c

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

drivers/ata/libata-transport.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ struct ata_internal {
4646
struct transport_container link_attr_cont;
4747
struct transport_container dev_attr_cont;
4848
};
49-
#define to_ata_internal(tmpl) container_of(tmpl, struct ata_internal, t)
49+
50+
static int ata_tlink_match(struct attribute_container *cont,
51+
struct device *dev);
52+
static int ata_tdev_match(struct attribute_container *cont,
53+
struct device *dev);
5054

5155
#define tdev_to_device(d) \
5256
container_of((d), struct ata_device, tdev)
@@ -519,16 +523,6 @@ static bool ata_is_ata_dev(const struct device *dev)
519523
return dev->release == ata_tdev_release;
520524
}
521525

522-
static int ata_tdev_match(struct attribute_container *cont,
523-
struct device *dev)
524-
{
525-
struct ata_internal *i = to_ata_internal(ata_scsi_transport_template);
526-
527-
if (!ata_is_ata_dev(dev))
528-
return 0;
529-
return &i->dev_attr_cont.ac == cont;
530-
}
531-
532526
/**
533527
* ata_tdev_free -- free an ATA transport device
534528
* @dev: struct ata_device owning the transport device to free
@@ -660,16 +654,6 @@ static bool ata_is_link(const struct device *dev)
660654
return dev->release == ata_tlink_release;
661655
}
662656

663-
static int ata_tlink_match(struct attribute_container *cont,
664-
struct device *dev)
665-
{
666-
struct ata_internal *i = to_ata_internal(ata_scsi_transport_template);
667-
668-
if (!ata_is_link(dev))
669-
return 0;
670-
return &i->link_attr_cont.ac == cont;
671-
}
672-
673657
/**
674658
* ata_tlink_delete -- remove an ATA link transport device
675659
* @link: struct ata_link owning the link transport device to remove
@@ -762,6 +746,24 @@ static struct ata_internal ata_transport_internal = {
762746
.dev_attr_cont.ac.match = ata_tdev_match,
763747
};
764748

749+
static int ata_tlink_match(struct attribute_container *cont,
750+
struct device *dev)
751+
{
752+
if (!ata_is_link(dev))
753+
return 0;
754+
755+
return &ata_transport_internal.link_attr_cont.ac == cont;
756+
}
757+
758+
static int ata_tdev_match(struct attribute_container *cont,
759+
struct device *dev)
760+
{
761+
if (!ata_is_ata_dev(dev))
762+
return 0;
763+
764+
return &ata_transport_internal.dev_attr_cont.ac == cont;
765+
}
766+
765767
/*
766768
* Setup / Teardown code
767769
*/

0 commit comments

Comments
 (0)