Skip to content

Commit d85fc67

Browse files
gwendalcrhtejun
authored andcommitted
libata: transport: Remove circular dependency at free time
Without this patch, failed probe would not free resources like irq. ata port tdev object currently hold a reference to the ata port object. Therefore the ata port object release function will not get called until the ata_tport_release is called. But that would never happen, releasing the last reference of ata port dev is done by scsi_host_release, which is called by ata_host_release when the ata port object is released. The ata device objects actually do not need to explicitly hold a reference to their real counterpart, given the transport objects are the children of these objects and device_add() is call for each child. We know the parent will not be deleted until we call the child's device_del(). Reported-by: Matthew Whitehead <[email protected]> Tested-by: Matthew Whitehead <[email protected]> Suggested-by: Tejun Heo <[email protected]> Signed-off-by: Gwendal Grignou <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent c1ae3cf commit d85fc67

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

drivers/ata/libata-transport.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ static DECLARE_TRANSPORT_CLASS(ata_port_class,
224224

225225
static void ata_tport_release(struct device *dev)
226226
{
227-
put_device(dev->parent);
228227
}
229228

230229
/**
@@ -284,7 +283,7 @@ int ata_tport_add(struct device *parent,
284283
device_initialize(dev);
285284
dev->type = &ata_port_type;
286285

287-
dev->parent = get_device(parent);
286+
dev->parent = parent;
288287
dev->release = ata_tport_release;
289288
dev_set_name(dev, "ata%d", ap->print_id);
290289
transport_setup_device(dev);
@@ -348,7 +347,6 @@ static DECLARE_TRANSPORT_CLASS(ata_link_class,
348347

349348
static void ata_tlink_release(struct device *dev)
350349
{
351-
put_device(dev->parent);
352350
}
353351

354352
/**
@@ -410,7 +408,7 @@ int ata_tlink_add(struct ata_link *link)
410408
int error;
411409

412410
device_initialize(dev);
413-
dev->parent = get_device(&ap->tdev);
411+
dev->parent = &ap->tdev;
414412
dev->release = ata_tlink_release;
415413
if (ata_is_host_link(link))
416414
dev_set_name(dev, "link%d", ap->print_id);
@@ -589,7 +587,6 @@ static DECLARE_TRANSPORT_CLASS(ata_dev_class,
589587

590588
static void ata_tdev_release(struct device *dev)
591589
{
592-
put_device(dev->parent);
593590
}
594591

595592
/**
@@ -662,7 +659,7 @@ static int ata_tdev_add(struct ata_device *ata_dev)
662659
int error;
663660

664661
device_initialize(dev);
665-
dev->parent = get_device(&link->tdev);
662+
dev->parent = &link->tdev;
666663
dev->release = ata_tdev_release;
667664
if (ata_is_host_link(link))
668665
dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);

0 commit comments

Comments
 (0)