From: <atull@opensource.altera.com>
To: <gregkh@linuxfoundation.org>
Cc: Josh Cartwright <joshc@ni.com>,
Moritz Fischer <moritz.fischer@ettus.com>,
<linux-kernel@vger.kernel.org>, <delicious.quinoa@gmail.com>,
<dinguyen@opensource.altera.com>,
Alan Tull <atull@opensource.altera.com>
Subject: [PATCH 1/2] fpga manager: ensure lifetime with of_fpga_mgr_get
Date: Thu, 22 Oct 2015 12:38:37 -0500 [thread overview]
Message-ID: <1445535518-13406-2-git-send-email-atull@opensource.altera.com> (raw)
In-Reply-To: <1445535518-13406-1-git-send-email-atull@opensource.altera.com>
From: Alan Tull <atull@opensource.altera.com>
Ensure device and driver lifetime from of_fpga_mgr_get() to
fpga_mgr_put().
* Don't put_device() in of_fpga_mgr_get, do it in fpga_mgr_put().
(still do put_device if there is an error).
* Do module_get on the low level driver.
* Don't need to module_get(THIS_MODULE) since we won't be allowed
to unload the fpga manager core without unloading low level
driver first.
* Remove unnedessary null check for node pointer.
Signed-off-by: Alan Tull <atull@opensource.altera.com>
---
drivers/fpga/fpga-mgr.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index 2526163..68d7b41 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -204,9 +204,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
{
struct fpga_manager *mgr;
struct device *dev;
-
- if (!node)
- return ERR_PTR(-EINVAL);
+ int ret = -ENODEV;
dev = class_find_device(fpga_mgr_class, NULL, node,
fpga_mgr_of_node_match);
@@ -214,20 +212,25 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
return ERR_PTR(-ENODEV);
mgr = to_fpga_manager(dev);
- put_device(dev);
if (!mgr)
- return ERR_PTR(-ENODEV);
+ goto err_dev;
/* Get exclusive use of fpga manager */
- if (!mutex_trylock(&mgr->ref_mutex))
- return ERR_PTR(-EBUSY);
-
- if (!try_module_get(THIS_MODULE)) {
- mutex_unlock(&mgr->ref_mutex);
- return ERR_PTR(-ENODEV);
+ if (!mutex_trylock(&mgr->ref_mutex)) {
+ ret = -EBUSY;
+ goto err_dev;
}
+ if (!try_module_get(dev->parent->driver->owner))
+ goto err_ll_mod;
+
return mgr;
+
+err_ll_mod:
+ mutex_unlock(&mgr->ref_mutex);
+err_dev:
+ put_device(dev);
+ return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(of_fpga_mgr_get);
@@ -237,10 +240,9 @@ EXPORT_SYMBOL_GPL(of_fpga_mgr_get);
*/
void fpga_mgr_put(struct fpga_manager *mgr)
{
- if (mgr) {
- module_put(THIS_MODULE);
- mutex_unlock(&mgr->ref_mutex);
- }
+ module_put(mgr->dev.parent->driver->owner);
+ mutex_unlock(&mgr->ref_mutex);
+ put_device(&mgr->dev);
}
EXPORT_SYMBOL_GPL(fpga_mgr_put);
--
1.7.9.5
next prev parent reply other threads:[~2015-10-22 17:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 17:38 [PATCH 0/2] fpga manager fixes atull
2015-10-22 17:38 ` atull [this message]
2015-10-22 17:38 ` [PATCH 2/2] fpga manager: remove unnecessary null pointer checks atull
2015-10-22 17:50 ` Moritz Fischer
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=1445535518-13406-2-git-send-email-atull@opensource.altera.com \
--to=atull@opensource.altera.com \
--cc=delicious.quinoa@gmail.com \
--cc=dinguyen@opensource.altera.com \
--cc=gregkh@linuxfoundation.org \
--cc=joshc@ni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=moritz.fischer@ettus.com \
/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
Powered by JetHome