*
* Step the low level fpga manager through the device-specific steps of getting
* an FPGA ready to be configured, writing the image to it, then doing whatever
- * post-configuration steps necessary.
+ * post-configuration steps necessary. This code assumes the caller got the
+ * mgr pointer from of_fpga_mgr_get() and checked that it is not an error code.
*
* Return: 0 on success, negative error code otherwise.
*/
struct device *dev = &mgr->dev;
int ret;
- if (!mgr)
- return -ENODEV;
-
/*
* Call the low level driver's write_init function. This will do the
* device-specific things to get the FPGA into the state where it is
*
* Request an FPGA image using the firmware class, then write out to the FPGA.
* Update the state before each step to provide info on what step failed if
- * there is a failure.
+ * there is a failure. This code assumes the caller got the mgr pointer
+ * from of_fpga_mgr_get() and checked that it is not an error code.
*
* Return: 0 on success, negative error code otherwise.
*/
const struct firmware *fw;
int ret;
- if (!mgr)
- return -ENODEV;
-
dev_info(dev, "writing %s to %s\n", image_name, mgr->name);
mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ;
{
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);
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);
*/
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);