All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gwendal Grignou <gwendal@chromium.org>
To: tj@kernel.org, gregkh@linuxfoundation.org,
	sergei.shtylyov@cogentembedded.com, linux-ide@vger.kernel.org,
	htejun@gmail.com
Subject: [PATCH] libata: transport: Remove circular dependency at free time
Date: Fri,  3 Mar 2017 09:00:09 -0800	[thread overview]
Message-ID: <20170303170009.36744-1-gwendal@chromium.org> (raw)
In-Reply-To: <CAP8WD_ZJ9EgssJgTu8EOtKodtnfxO8tqhN6iAnuMHq2VQ7MoaQ@mail.gmail.com>

From: Tejun Heo <tj@kernel.org>

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 tranport 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
device_del().

Reported-by: Matthew Whitehead <tedheadster@gmail.com>
Tested-by: Matthew Whitehead <tedheadster@gmail.com>
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
 drivers/ata/libata-transport.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 46698232e6bf..19e6e539a061 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -224,7 +224,6 @@ static DECLARE_TRANSPORT_CLASS(ata_port_class,
 
 static void ata_tport_release(struct device *dev)
 {
-	put_device(dev->parent);
 }
 
 /**
@@ -284,7 +283,7 @@ int ata_tport_add(struct device *parent,
 	device_initialize(dev);
 	dev->type = &ata_port_type;
 
-	dev->parent = get_device(parent);
+	dev->parent = parent;
 	dev->release = ata_tport_release;
 	dev_set_name(dev, "ata%d", ap->print_id);
 	transport_setup_device(dev);
@@ -348,7 +347,6 @@ static DECLARE_TRANSPORT_CLASS(ata_link_class,
 
 static void ata_tlink_release(struct device *dev)
 {
-	put_device(dev->parent);
 }
 
 /**
@@ -410,7 +408,7 @@ int ata_tlink_add(struct ata_link *link)
 	int error;
 
 	device_initialize(dev);
-	dev->parent = get_device(&ap->tdev);
+	dev->parent = &ap->tdev;
 	dev->release = ata_tlink_release;
 	if (ata_is_host_link(link))
 		dev_set_name(dev, "link%d", ap->print_id);
@@ -589,7 +587,6 @@ static DECLARE_TRANSPORT_CLASS(ata_dev_class,
 
 static void ata_tdev_release(struct device *dev)
 {
-	put_device(dev->parent);
 }
 
 /**
@@ -662,7 +659,7 @@ static int ata_tdev_add(struct ata_device *ata_dev)
 	int error;
 
 	device_initialize(dev);
-	dev->parent = get_device(&link->tdev);
+	dev->parent = &link->tdev;
 	dev->release = ata_tdev_release;
 	if (ata_is_host_link(link))
 		dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
-- 
2.12.0.rc1.440.g5b76565f74-goog


  reply	other threads:[~2017-03-03 17:01 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 17:53 [PATCH] pata_legacy: Allow disabling of legacy PATA device probes on non-PCI systems Matthew Whitehead
2016-11-29 19:41 ` Tejun Heo
2016-11-29 20:12   ` tedheadster
2016-11-29 20:46     ` Tejun Heo
2016-11-30 13:06       ` Bartlomiej Zolnierkiewicz
2016-11-30 17:13         ` tedheadster
2016-11-30 13:11 ` Sergei Shtylyov
2016-11-30 14:53   ` One Thousand Gnomes
2016-11-30 15:03     ` tedheadster
2016-11-30 18:15       ` One Thousand Gnomes
2016-12-02 13:37         ` tedheadster
2016-12-02 16:24           ` One Thousand Gnomes
2016-11-30 20:22       ` Tejun Heo
     [not found]         ` <CAP8WD_bZWeLBhLXqJG5uDwBe+zBubw+A+ecSuaihOuwvw9QoCQ@mail.gmail.com>
2016-12-02 17:07           ` Tejun Heo
2016-12-05 14:19             ` tedheadster
2016-12-05 19:23               ` Tejun Heo
     [not found]                 ` <CAP8WD_becq+h2=-g7t-6Pp1psmkCCvdB0YUcg+wYPocUP4dYdw@mail.gmail.com>
2016-12-12 17:01                   ` Tejun Heo
     [not found]                     ` <CAP8WD_YMtnsuYmJHGz1eLmrQNemsB1Z6Soyb6f72brAfMNUNeg@mail.gmail.com>
2016-12-20  2:12                       ` tedheadster
2016-12-22 16:37                         ` Tejun Heo
2016-12-22 17:14                           ` tedheadster
2016-12-22 17:19                             ` Tejun Heo
2016-12-22 18:30                             ` tedheadster
2016-12-22 19:22                               ` Tejun Heo
2017-01-03 17:34                                 ` One Thousand Gnomes
     [not found]                                   ` <CAP8WD_bS61spyQkd7cvktFf_dPc0wgNZ8qEa7GVrXgUobHQdvw@mail.gmail.com>
2017-01-19 21:37                                     ` Tejun Heo
2017-01-20 17:08                                       ` tedheadster
2017-01-20 19:19                                         ` Tejun Heo
2017-01-20 19:38                                           ` Tejun Heo
2017-01-23 23:36                                             ` Gwendal Grignou
2017-01-23 23:57                                               ` tedheadster
2017-01-24 16:19                                                 ` Tejun Heo
2017-01-27  3:01                                                   ` tedheadster
2017-02-07 20:21                                                     ` Gwendal Grignou
2017-02-08 19:43                                                       ` Tejun Heo
2017-02-09 23:49                                                         ` Gwendal Grignou
2017-02-10  0:36                                                           ` tedheadster
2017-02-10 13:19                                                             ` Tejun Heo
2017-02-23 19:26                                                               ` tedheadster
2017-03-03 17:00                                                                 ` Gwendal Grignou [this message]
2017-03-03 18:28                                                                   ` [PATCH] libata: transport: Remove circular dependency at free time Sergei Shtylyov
2017-03-03 18:36                                                                     ` Tejun Heo
2017-03-06 20:09                                                                   ` Tejun Heo
2017-03-06 20:11                                                                     ` Sergei Shtylyov
2017-03-06 20:26                                                                       ` Tejun Heo
2017-01-24 15:57                                               ` [PATCH] pata_legacy: Allow disabling of legacy PATA device probes on non-PCI systems Tejun Heo
2016-12-12 12:21               ` Bartlomiej Zolnierkiewicz
2016-11-30 13:12 ` Bartlomiej Zolnierkiewicz
2016-11-30 13:15 ` Sergei Shtylyov

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=20170303170009.36744-1-gwendal@chromium.org \
    --to=gwendal@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=htejun@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.