fpga: Populate dev_release functions
cover fpga: Populate dev_release functions
The FPGA framework has a convention of using managed resource functions to allow parent drivers to manage the data structures allocated by the class drivers. They use an empty *_dev_release() function to satisfy the class driver.
This is inconsistent with linux driver model.
This is a complete re-do of the previous patch set entitled "fpga: Use standard class dev_release function". These changes populate the class dev_release callback functions while maintaining the current API. Additional changes are made to maintain consistency with the driver model.
For more context on these changes, refer to this email thread:
https://marc.info/?l=linux-fpga&m=162127412218557&w=2
Russ Weight (5):
fpga: mgr: Use standard dev_release for class driver
fpga: altera-pr-ip: Remove fpga_mgr_unregister() call
fpga: stratix10-soc: Add missing fpga_mgr_free() call
fpga: bridge: Use standard dev_release for class driver
fpga: region: Use standard dev_release for class driver
drivers/fpga/altera-pr-ip-core.c | 4 --- drivers/fpga/fpga-bridge.c | 48 +++++++++++++-------------- drivers/fpga/fpga-mgr.c | 57 +++++++++++++++----------------- drivers/fpga/fpga-region.c | 46 +++++++++++++------------- drivers/fpga/stratix10-soc.c | 1 + 5 files changed, 74 insertions(+), 82 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/5 fpga: mgr: Use standard dev_release for class driver
The FPGA manager class driver data structure is being treated as a managed resource instead of using the class.dev_release call-back function to release the class data structure. This change populates the class.dev_release function, changes the fpga_mgr_free() function to call put_device() and changes the fpga_mgr_unregister() function to call device_del() instead of device_unregister().
--- drivers/fpga/fpga-mgr.c | 57 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-)
drivers/fpga/fpga-mgr.c +26 -31
@@ -551,7 +551,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);/** * fpga_mgr_create - create and initialize a FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev * @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data
@@ -561,7 +561,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {
@@ -571,12 +571,12 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,if (!mops || !mops->write_complete || !mops->state || !mops->write_init || (!mops->write && !mops->write_sg) || (mops->write && mops->write_sg)) { -dev_err (dev,"Attempt to register without fpga_manager_ops\n" ); +dev_err (parent,"Attempt to register without fpga_manager_ops\n" );return NULL ; }if (!name || !strlen (name)) { -dev_err (dev,"Attempt to register with no name!\n" ); +dev_err (parent,"Attempt to register with no name!\n" );return NULL ; }
@@ -585,8 +585,10 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,return NULL ; id =ida_simple_get (&fpga_mgr_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto error_kfree; +if (id <0 ) { +kfree (mgr); +return NULL ; + }mutex_init (&mgr->ref_mutex);
@@ -597,22 +599,17 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,device_initialize (&mgr->dev); mgr->dev.class = fpga_mgr_class; mgr->dev.groups = mops->groups; - mgr->dev.parent = dev; - mgr->dev.of_node = dev->of_node; + mgr->dev.parent = parent; + mgr->dev.of_node = parent->of_node; mgr->dev.id = id; ret =dev_set_name (&mgr->dev,"fpga%d" , id); -if (ret) - goto error_device; +if (ret) { +put_device (&mgr->dev); +return NULL ; + }return mgr; - -error_device: -ida_simple_remove (&fpga_mgr_ida, id); -error_kfree: -kfree (mgr); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_mgr_create);
@@ -622,8 +619,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_create);*/ void fpga_mgr_free (struct fpga_manager *mgr) { -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); -kfree (mgr); +put_device (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_free);
@@ -631,12 +627,12 @@ static void devm_fpga_mgr_release(struct device *dev, void *res) {struct fpga_mgr_devres *dr = res; -fpga_mgr_free (dr->mgr); +put_device (&dr->mgr->dev); }/** * devm_fpga_mgr_create - create and initialize a managed FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev * @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data
@@ -651,7 +647,7 @@ static void devm_fpga_mgr_release(struct device *dev, void *res)* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *devm_fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *devm_fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {
@@ -661,13 +657,13 @@ struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,if (!dr)return NULL ; - dr->mgr =fpga_mgr_create (dev, name, mops, priv); + dr->mgr =fpga_mgr_create (parent, name, mops, priv);if (!dr->mgr) {devres_free (dr);return NULL ; } -devres_add (dev, dr); +devres_add (parent, dr);return dr->mgr; }
@@ -692,16 +688,11 @@ int fpga_mgr_register(struct fpga_manager *mgr) ret =device_add (&mgr->dev);if (ret) - goto error_device; +return ret;dev_info (&mgr->dev,"%s registered\n" , mgr->name);return 0 ; - -error_device: -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); - -return ret; }EXPORT_SYMBOL_GPL (fpga_mgr_register);
@@ -722,7 +713,7 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)if (mgr->mops->fpga_remove) mgr->mops->fpga_remove (mgr); -device_unregister (&mgr->dev); +device_del (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_unregister);
@@ -781,6 +772,10 @@ EXPORT_SYMBOL_GPL(devm_fpga_mgr_register);static void fpga_mgr_dev_release (struct device *dev) { +struct fpga_manager *mgr =to_fpga_manager (dev); + +ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); +kfree (mgr); }static int __init fpga_mgr_class_init (void )
Signature · 1 line
2.25.1
Xu Yilun
maintainerRe: [PATCH v1 1/5] fpga: mgr: Use standard dev_release for class driver
Quoted 17 lines · Russ Weight
The FPGA manager class driver data structure is being treated as a managed resource instead of using the class.dev_release call-back function to release the class data structure. This change populates the class.dev_release function, changes the
fpga_mgr_free()function to callput_device()and changes thefpga_mgr_unregister()function to calldevice_del()instead ofdevice_unregister().Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/fpga-mgr.c | 57 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-)drivers/fpga/fpga-mgr.c +0
-0
drivers/fpga/fpga-mgr.c EXPORT_SYMBOL_GPL(fpga_mgr_unlock); · line 554
Quoted 5 lines
drivers/fpga/fpga-mgr.c +1
-1@@ -551,7 +551,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);/** * fpga_mgr_create - create and initialize a FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev
Could you split the renaming change to a separate patch?
Quoted 80 lines
drivers/fpga/fpga-mgr.c +14
-18* @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data @@ -561,7 +561,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {@@ -571,12 +571,12 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,if (!mops || !mops->write_complete || !mops->state || !mops->write_init || (!mops->write && !mops->write_sg) || (mops->write && mops->write_sg)) { -dev_err (dev,"Attempt to register without fpga_manager_ops\n" ); +dev_err (parent,"Attempt to register without fpga_manager_ops\n" );return NULL ; }if (!name || !strlen (name)) { -dev_err (dev,"Attempt to register with no name!\n" ); +dev_err (parent,"Attempt to register with no name!\n" );return NULL ; }@@ -585,8 +585,10 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,return NULL ; id =ida_simple_get (&fpga_mgr_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto error_kfree; +if (id <0 ) { +kfree (mgr); +return NULL ; + }mutex_init (&mgr->ref_mutex);@@ -597,22 +599,17 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,device_initialize (&mgr->dev); mgr->dev.class = fpga_mgr_class; mgr->dev.groups = mops->groups; - mgr->dev.parent = dev; - mgr->dev.of_node = dev->of_node; + mgr->dev.parent = parent; + mgr->dev.of_node = parent->of_node; mgr->dev.id = id; ret =dev_set_name (&mgr->dev,"fpga%d" , id); -if (ret) - goto error_device; +if (ret) { +put_device (&mgr->dev); +return NULL ; + }return mgr; - -error_device: -ida_simple_remove (&fpga_mgr_ida, id); -error_kfree: -kfree (mgr); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_mgr_create);@@ -622,8 +619,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_create);*/ void fpga_mgr_free (struct fpga_manager *mgr) { -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); -kfree (mgr); +put_device (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_free);
drivers/fpga/fpga-mgr.c static void devm_fpga_mgr_release(struct device *dev, void *res) · line 630
Quoted 5 lines
drivers/fpga/fpga-mgr.c +1
-1@@ -631,12 +627,12 @@ static void devm_fpga_mgr_release(struct device *dev, void *res) {struct fpga_mgr_devres *dr = res; -fpga_mgr_free (dr->mgr); +put_device (&dr->mgr->dev);
I don't think we have to change this. devm_fpga_mgr_create() saves people from calling fpga_mgr_free(), so it may be more readable fpga_mgr_free() is called here.
Thanks,
Yilun
Quoted 74 lines
drivers/fpga/fpga-mgr.c +10
-11}/** * devm_fpga_mgr_create - create and initialize a managed FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev * @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data @@ -651,7 +647,7 @@ static void devm_fpga_mgr_release(struct device *dev, void *res)* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *devm_fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *devm_fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {@@ -661,13 +657,13 @@ struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,if (!dr)return NULL ; - dr->mgr =fpga_mgr_create (dev, name, mops, priv); + dr->mgr =fpga_mgr_create (parent, name, mops, priv);if (!dr->mgr) {devres_free (dr);return NULL ; } -devres_add (dev, dr); +devres_add (parent, dr);return dr->mgr; }@@ -692,16 +688,11 @@ int fpga_mgr_register(struct fpga_manager *mgr) ret =device_add (&mgr->dev);if (ret) - goto error_device; +return ret;dev_info (&mgr->dev,"%s registered\n" , mgr->name);return 0 ; - -error_device: -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); - -return ret; }EXPORT_SYMBOL_GPL (fpga_mgr_register);@@ -722,7 +713,7 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)if (mgr->mops->fpga_remove) mgr->mops->fpga_remove (mgr); -device_unregister (&mgr->dev); +device_del (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_unregister);@@ -781,6 +772,10 @@ EXPORT_SYMBOL_GPL(devm_fpga_mgr_register);static void fpga_mgr_dev_release (struct device *dev) { +struct fpga_manager *mgr =to_fpga_manager (dev); + +ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); +kfree (mgr); }static int __init fpga_mgr_class_init (void )Signature · 1 line
2.25.1
Re: [PATCH v1 1/5] fpga: mgr: Use standard dev_release for class driver
Quoted 19 lines · Xu Yilun
Quoted 18 lines · Russ Weight
The FPGA manager class driver data structure is being treated as a managed resource instead of using the class.dev_release call-back function to release the class data structure. This change populates the class.dev_release function, changes the
fpga_mgr_free()function to callput_device()and changes thefpga_mgr_unregister()function to calldevice_del()instead ofdevice_unregister().Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/fpga-mgr.c | 57 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-)drivers/fpga/fpga-mgr.c +0
-0@@ -551,7 +551,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);
Quoted 5 lines
drivers/fpga/fpga-mgr.c EXPORT_SYMBOL_GPL(fpga_mgr_unlock); · line 554
Quoted 4 lines
drivers/fpga/fpga-mgr.c +1
-1/** * fpga_mgr_create - create and initialize a FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev Could you split the renaming change to a separate patch?
Sure - I'll split it out.
Quoted 84 lines
Quoted 84 lines
drivers/fpga/fpga-mgr.c +14
-18* @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data @@ -561,7 +561,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock);* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {@@ -571,12 +571,12 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,if (!mops || !mops->write_complete || !mops->state || !mops->write_init || (!mops->write && !mops->write_sg) || (mops->write && mops->write_sg)) { -dev_err (dev,"Attempt to register without fpga_manager_ops\n" ); +dev_err (parent,"Attempt to register without fpga_manager_ops\n" );return NULL ; }if (!name || !strlen (name)) { -dev_err (dev,"Attempt to register with no name!\n" ); +dev_err (parent,"Attempt to register with no name!\n" );return NULL ; }@@ -585,8 +585,10 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,return NULL ; id =ida_simple_get (&fpga_mgr_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto error_kfree; +if (id <0 ) { +kfree (mgr); +return NULL ; + }mutex_init (&mgr->ref_mutex);@@ -597,22 +599,17 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,device_initialize (&mgr->dev); mgr->dev.class = fpga_mgr_class; mgr->dev.groups = mops->groups; - mgr->dev.parent = dev; - mgr->dev.of_node = dev->of_node; + mgr->dev.parent = parent; + mgr->dev.of_node = parent->of_node; mgr->dev.id = id; ret =dev_set_name (&mgr->dev,"fpga%d" , id); -if (ret) - goto error_device; +if (ret) { +put_device (&mgr->dev); +return NULL ; + }return mgr; - -error_device: -ida_simple_remove (&fpga_mgr_ida, id); -error_kfree: -kfree (mgr); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_mgr_create);@@ -622,8 +619,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_create);*/ void fpga_mgr_free (struct fpga_manager *mgr) { -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); -kfree (mgr); +put_device (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_free);@@ -631,12 +627,12 @@ static void devm_fpga_mgr_release(struct device *dev, void *res) {struct fpga_mgr_devres *dr = res;
Quoted 5 lines
drivers/fpga/fpga-mgr.c static void devm_fpga_mgr_release(struct device *dev, void *res) · line 630
Quoted 2 lines
drivers/fpga/fpga-mgr.c +1
-1-fpga_mgr_free (dr->mgr); +put_device (&dr->mgr->dev);I don't think we have to change this.
devm_fpga_mgr_create()saves people from callingfpga_mgr_free(), so it may be more readablefpga_mgr_free()is called here.
I changed it because I'm not real comfortable with using "free" terminology for lowering a reference count. But, I can change it back if you think it is more readable that way.
Quoted 77 lines
Thanks,
YilunQuoted 74 lines
drivers/fpga/fpga-mgr.c +10
-11}/** * devm_fpga_mgr_create - create and initialize a managed FPGA manager struct -* @dev: fpga manager device from pdev +* @parent: fpga manager device from pdev * @name: fpga manager name * @mops: pointer to structure of fpga manager ops * @priv: fpga manager private data @@ -651,7 +647,7 @@ static void devm_fpga_mgr_release(struct device *dev, void *res)* * Return: pointer to struct fpga_manager or NULL */ -struct fpga_manager *devm_fpga_mgr_create (struct device *dev,const char *name, +struct fpga_manager *devm_fpga_mgr_create (struct device *parent,const char *name,const struct fpga_manager_ops *mops,void *priv) {@@ -661,13 +657,13 @@ struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,if (!dr)return NULL ; - dr->mgr =fpga_mgr_create (dev, name, mops, priv); + dr->mgr =fpga_mgr_create (parent, name, mops, priv);if (!dr->mgr) {devres_free (dr);return NULL ; } -devres_add (dev, dr); +devres_add (parent, dr);return dr->mgr; }@@ -692,16 +688,11 @@ int fpga_mgr_register(struct fpga_manager *mgr) ret =device_add (&mgr->dev);if (ret) - goto error_device; +return ret;dev_info (&mgr->dev,"%s registered\n" , mgr->name);return 0 ; - -error_device: -ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); - -return ret; }EXPORT_SYMBOL_GPL (fpga_mgr_register);@@ -722,7 +713,7 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)if (mgr->mops->fpga_remove) mgr->mops->fpga_remove (mgr); -device_unregister (&mgr->dev); +device_del (&mgr->dev); }EXPORT_SYMBOL_GPL (fpga_mgr_unregister);@@ -781,6 +772,10 @@ EXPORT_SYMBOL_GPL(devm_fpga_mgr_register);static void fpga_mgr_dev_release (struct device *dev) { +struct fpga_manager *mgr =to_fpga_manager (dev); + +ida_simple_remove (&fpga_mgr_ida, mgr->dev.id); +kfree (mgr); }static int __init fpga_mgr_class_init (void )Signature · 1 line
2.25.1
PATCH 2/5 fpga: altera-pr-ip: Remove fpga_mgr_unregister() call
In reply to Russ WeightThe altera-pr-ip driver uses the devm_fpga_mgr_register() call, so it is unnecessary to call fpga_mgr_unregister(). Also, mgr is no longer stored in the dev.driver_data, so remove the call to dev_get_drvdata().
alt_pr_unregister() is now an empty function, but is left intact because it is an exported symbol.
--- drivers/fpga/altera-pr-ip-core.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/fpga/altera-pr-ip-core.c +0 -4
@@ -201,11 +201,7 @@ EXPORT_SYMBOL_GPL(alt_pr_register);void alt_pr_unregister (struct device *dev) { -struct fpga_manager *mgr =dev_get_drvdata (dev); -dev_dbg (dev,"%s\n" , __func__); - -fpga_mgr_unregister (mgr); }EXPORT_SYMBOL_GPL (alt_pr_unregister);
Signature · 1 line
2.25.1
Xu Yilun
maintainerRe: [PATCH v1 2/5] fpga: altera-pr-ip: Remove fpga_mgr_unregister() call
Quoted 6 lines · Russ Weight
The altera-pr-ip driver uses the
devm_fpga_mgr_register()call, so it is unnecessary to callfpga_mgr_unregister(). Also, mgr is no longer stored in the dev.driver_data, so remove the call todev_get_drvdata().
alt_pr_unregister()is now an empty function, but is left intact because it is an exported symbol.
I don't see this function be called anywhere, so could we just remove it?
Any impact we remove an exported symbol that is not used?
Thanks,
Yilun
Quoted 24 lines
Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/altera-pr-ip-core.c | 4 ---- 1 file changed, 4 deletions(-)drivers/fpga/altera-pr-ip-core.c +0
-4@@ -201,11 +201,7 @@ EXPORT_SYMBOL_GPL(alt_pr_register);void alt_pr_unregister (struct device *dev) { -struct fpga_manager *mgr =dev_get_drvdata (dev); -dev_dbg (dev,"%s\n" , __func__); - -fpga_mgr_unregister (mgr); }EXPORT_SYMBOL_GPL (alt_pr_unregister);Signature · 1 line
2.25.1
Re: [PATCH v1 2/5] fpga: altera-pr-ip: Remove fpga_mgr_unregister() call
Quoted 11 lines · Xu Yilun
Quoted 6 lines · Russ Weight
The altera-pr-ip driver uses the
devm_fpga_mgr_register()call, so it is unnecessary to callfpga_mgr_unregister(). Also, mgr is no longer stored in the dev.driver_data, so remove the call todev_get_drvdata().
alt_pr_unregister()is now an empty function, but is left intact because it is an exported symbol.I don't see this function be called anywhere, so could we just remove it?
Any impact we remove an exported symbol that is not used?
Only if there are out-of-tree drivers that use it. What do other's think? Can we remove this?
- Russ
Quoted 27 lines
Thanks,
YilunQuoted 23 lines
Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/altera-pr-ip-core.c | 4 ---- 1 file changed, 4 deletions(-)drivers/fpga/altera-pr-ip-core.c +0
-4@@ -201,11 +201,7 @@ EXPORT_SYMBOL_GPL(alt_pr_register);void alt_pr_unregister (struct device *dev) { -struct fpga_manager *mgr =dev_get_drvdata (dev); -dev_dbg (dev,"%s\n" , __func__); - -fpga_mgr_unregister (mgr); }EXPORT_SYMBOL_GPL (alt_pr_unregister);Signature · 1 line
2.25.1
Moritz Fischer
maintainerRe: [PATCH v1 2/5] fpga: altera-pr-ip: Remove fpga_mgr_unregister() call
Quoted 8 lines · Russ Weight
Quoted 5 lines · Xu Yilun
Quoted 4 lines · Russ Weight
The altera-pr-ip driver uses the
devm_fpga_mgr_register()call, so it is unnecessary to callfpga_mgr_unregister(). Also, mgr is no longer stored in the dev.driver_data, so remove the call todev_get_drvdata().
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
alt_pr_unregister()is now an empty function, but is left intact because it is an exported symbol.I don't see this function be called anywhere, so could we just remove it?
Any impact we remove an exported symbol that is not used?
Only if there are out-of-tree drivers that use it. What do other's think? Can we remove this?
We don't care about out-of-tree drivers. Please remove it.
- Moritz
PATCH 3/5 fpga: stratix10-soc: Add missing fpga_mgr_free() call
In reply to Russ WeightThe stratix10-soc driver uses fpga_mgr_create() function and is therefore responsible to call fpga_mgr_free() to release the class driver resources. Add a missing call to fpga_mgr_free in the s10_remove() function.
--- drivers/fpga/stratix10-soc.c | 1 + 1 file changed, 1 insertion(+)
drivers/fpga/stratix10-soc.c +1 -0
@@ -454,6 +454,7 @@ static int s10_remove(struct platform_device *pdev)struct s10_priv *priv = mgr->priv;fpga_mgr_unregister (mgr); +fpga_mgr_free (mgr);stratix10_svc_free_channel (priv->chan);return 0 ;
Signature · 1 line
2.25.1
Re: [PATCH v1 3/5] fpga: stratix10-soc: Add missing fpga_mgr_free() call
Looks good to me.
Quoted 23 lines · Russ Weight
The stratix10-soc driver uses
fpga_mgr_create()function and is therefore responsible to callfpga_mgr_free()to release the class driver resources. Add a missing call tofpga_mgr_freein thes10_remove()function.Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/stratix10-soc.c | 1 + 1 file changed, 1 insertion(+)drivers/fpga/stratix10-soc.c +1
-0@@ -454,6 +454,7 @@ static int s10_remove(struct platform_device *pdev)struct s10_priv *priv = mgr->priv;fpga_mgr_unregister (mgr); +fpga_mgr_free (mgr);stratix10_svc_free_channel (priv->chan);return 0 ;Signature · 1 line
2.25.1
PATCH 4/5 fpga: bridge: Use standard dev_release for class driver
In reply to Russ WeightThe FPGA bridge class driver data structure is being treated as a managed resource instead of using standard dev_release call-back to release the class data structure. This change populates the class.dev_release function and changes the fpga_bridge_free() function to call put_device(). It also changes fpga_bridge_unregister() to call device_del() instead of device_unregister().
--- drivers/fpga/fpga-bridge.c | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/fpga/fpga-bridge.c +24 -24
@@ -313,7 +313,7 @@ ATTRIBUTE_GROUPS(fpga_bridge);/** * fpga_bridge_create - create and initialize a struct fpga_bridge -* @dev: FPGA bridge device from pdev +* @parent: FPGA bridge device from pdev * @name: FPGA bridge name * @br_ops: pointer to structure of fpga bridge ops * @priv: FPGA bridge private data
@@ -323,7 +323,7 @@ ATTRIBUTE_GROUPS(fpga_bridge);* * Return: struct fpga_bridge or NULL */ -struct fpga_bridge *fpga_bridge_create (struct device *dev,const char *name, +struct fpga_bridge *fpga_bridge_create (struct device *parent,const char *name,const struct fpga_bridge_ops *br_ops,void *priv) {
@@ -331,7 +331,7 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,int id, ret;if (!name || !strlen (name)) { -dev_err (dev,"Attempt to register with no name!\n" ); +dev_err (parent,"Attempt to register with no name!\n" );return NULL ; }
@@ -340,8 +340,10 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,return NULL ; id =ida_simple_get (&fpga_bridge_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto error_kfree; +if (id <0 ) { +kfree (bridge); +return NULL ; + }mutex_init (&bridge->mutex);INIT_LIST_HEAD (&bridge->node);
@@ -353,22 +355,17 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,device_initialize (&bridge->dev); bridge->dev.groups = br_ops->groups; bridge->dev.class = fpga_bridge_class; - bridge->dev.parent = dev; - bridge->dev.of_node = dev->of_node; + bridge->dev.parent = parent; + bridge->dev.of_node = parent->of_node; bridge->dev.id = id; ret =dev_set_name (&bridge->dev,"br%d" , id); -if (ret) - goto error_device; +if (ret) { +put_device (&bridge->dev); +return NULL ; + }return bridge; - -error_device: -ida_simple_remove (&fpga_bridge_ida, id); -error_kfree: -kfree (bridge); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_bridge_create);
@@ -378,8 +375,7 @@ EXPORT_SYMBOL_GPL(fpga_bridge_create);*/ void fpga_bridge_free (struct fpga_bridge *bridge) { -ida_simple_remove (&fpga_bridge_ida, bridge->dev.id); -kfree (bridge); +put_device (&bridge->dev); }EXPORT_SYMBOL_GPL (fpga_bridge_free);
@@ -387,12 +383,12 @@ static void devm_fpga_bridge_release(struct device *dev, void *res) {struct fpga_bridge *bridge = *(struct fpga_bridge **)res; -fpga_bridge_free (bridge); +put_device (&bridge->dev); }/** * devm_fpga_bridge_create - create and init a managed struct fpga_bridge -* @dev: FPGA bridge device from pdev +* @parent: FPGA bridge device from pdev * @name: FPGA bridge name * @br_ops: pointer to structure of fpga bridge ops * @priv: FPGA bridge private data
@@ -408,7 +404,7 @@ static void devm_fpga_bridge_release(struct device *dev, void *res)* Return: struct fpga_bridge or NULL */ struct fpga_bridge -*devm_fpga_bridge_create (struct device *dev,const char *name, +*devm_fpga_bridge_create (struct device *parent,const char *name,const struct fpga_bridge_ops *br_ops,void *priv) {struct fpga_bridge **ptr, *bridge;
@@ -417,12 +413,12 @@ struct fpga_bridgeif (!ptr)return NULL ; - bridge =fpga_bridge_create (dev, name, br_ops, priv); + bridge =fpga_bridge_create (parent, name, br_ops, priv);if (!bridge) {devres_free (ptr); }else { *ptr = bridge; -devres_add (dev, ptr); +devres_add (parent, ptr); }return bridge;
@@ -469,12 +465,16 @@ void fpga_bridge_unregister(struct fpga_bridge *bridge)if (bridge->br_ops && bridge->br_ops->fpga_bridge_remove) bridge->br_ops->fpga_bridge_remove (bridge); -device_unregister (&bridge->dev); +device_del (&bridge->dev); }EXPORT_SYMBOL_GPL (fpga_bridge_unregister);static void fpga_bridge_dev_release (struct device *dev) { +struct fpga_bridge *bridge =to_fpga_bridge (dev); + +ida_simple_remove (&fpga_bridge_ida, bridge->dev.id); +kfree (bridge); }static int __init fpga_bridge_dev_init (void )
Signature · 1 line
2.25.1
Xu Yilun
maintainerRe: [PATCH v1 4/5] fpga: bridge: Use standard dev_release for class driver
Quoted 17 lines · Russ Weight
The FPGA bridge class driver data structure is being treated as a managed resource instead of using standard
dev_releasecall-back to release the class data structure. This change populates the class.dev_release function and changes thefpga_bridge_free()function to callput_device(). It also changesfpga_bridge_unregister()to calldevice_del()instead ofdevice_unregister().Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/fpga-bridge.c | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-)drivers/fpga/fpga-bridge.c +0
-0
drivers/fpga/fpga-bridge.c ATTRIBUTE_GROUPS(fpga_bridge); · line 316
Quoted 5 lines
drivers/fpga/fpga-bridge.c +1
-1@@ -313,7 +313,7 @@ ATTRIBUTE_GROUPS(fpga_bridge);/** * fpga_bridge_create - create and initialize a struct fpga_bridge -* @dev: FPGA bridge device from pdev +* @parent: FPGA bridge device from pdev
The same concern, split the rename changes out.
Quoted 74 lines
drivers/fpga/fpga-bridge.c +13
-17* @name: FPGA bridge name * @br_ops: pointer to structure of fpga bridge ops * @priv: FPGA bridge private data @@ -323,7 +323,7 @@ ATTRIBUTE_GROUPS(fpga_bridge);* * Return: struct fpga_bridge or NULL */ -struct fpga_bridge *fpga_bridge_create (struct device *dev,const char *name, +struct fpga_bridge *fpga_bridge_create (struct device *parent,const char *name,const struct fpga_bridge_ops *br_ops,void *priv) {@@ -331,7 +331,7 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,int id, ret;if (!name || !strlen (name)) { -dev_err (dev,"Attempt to register with no name!\n" ); +dev_err (parent,"Attempt to register with no name!\n" );return NULL ; }@@ -340,8 +340,10 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,return NULL ; id =ida_simple_get (&fpga_bridge_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto error_kfree; +if (id <0 ) { +kfree (bridge); +return NULL ; + }mutex_init (&bridge->mutex);INIT_LIST_HEAD (&bridge->node);@@ -353,22 +355,17 @@ struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,device_initialize (&bridge->dev); bridge->dev.groups = br_ops->groups; bridge->dev.class = fpga_bridge_class; - bridge->dev.parent = dev; - bridge->dev.of_node = dev->of_node; + bridge->dev.parent = parent; + bridge->dev.of_node = parent->of_node; bridge->dev.id = id; ret =dev_set_name (&bridge->dev,"br%d" , id); -if (ret) - goto error_device; +if (ret) { +put_device (&bridge->dev); +return NULL ; + }return bridge; - -error_device: -ida_simple_remove (&fpga_bridge_ida, id); -error_kfree: -kfree (bridge); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_bridge_create);@@ -378,8 +375,7 @@ EXPORT_SYMBOL_GPL(fpga_bridge_create);*/ void fpga_bridge_free (struct fpga_bridge *bridge) { -ida_simple_remove (&fpga_bridge_ida, bridge->dev.id); -kfree (bridge); +put_device (&bridge->dev); }EXPORT_SYMBOL_GPL (fpga_bridge_free);
drivers/fpga/fpga-bridge.c static void devm_fpga_bridge_release(struct device *dev, void *res) · line 386
Quoted 5 lines
drivers/fpga/fpga-bridge.c +1
-1@@ -387,12 +383,12 @@ static void devm_fpga_bridge_release(struct device *dev, void *res) {struct fpga_bridge *bridge = *(struct fpga_bridge **)res; -fpga_bridge_free (bridge); +put_device (&bridge->dev);
The same concern, I prefer to keep it unchanged.
Thanks,
Yilun
Quoted 53 lines
drivers/fpga/fpga-bridge.c +9
-5}/** * devm_fpga_bridge_create - create and init a managed struct fpga_bridge -* @dev: FPGA bridge device from pdev +* @parent: FPGA bridge device from pdev * @name: FPGA bridge name * @br_ops: pointer to structure of fpga bridge ops * @priv: FPGA bridge private data @@ -408,7 +404,7 @@ static void devm_fpga_bridge_release(struct device *dev, void *res)* Return: struct fpga_bridge or NULL */ struct fpga_bridge -*devm_fpga_bridge_create (struct device *dev,const char *name, +*devm_fpga_bridge_create (struct device *parent,const char *name,const struct fpga_bridge_ops *br_ops,void *priv) {struct fpga_bridge **ptr, *bridge;@@ -417,12 +413,12 @@ struct fpga_bridgeif (!ptr)return NULL ; - bridge =fpga_bridge_create (dev, name, br_ops, priv); + bridge =fpga_bridge_create (parent, name, br_ops, priv);if (!bridge) {devres_free (ptr); }else { *ptr = bridge; -devres_add (dev, ptr); +devres_add (parent, ptr); }return bridge;@@ -469,12 +465,16 @@ void fpga_bridge_unregister(struct fpga_bridge *bridge)if (bridge->br_ops && bridge->br_ops->fpga_bridge_remove) bridge->br_ops->fpga_bridge_remove (bridge); -device_unregister (&bridge->dev); +device_del (&bridge->dev); }EXPORT_SYMBOL_GPL (fpga_bridge_unregister);static void fpga_bridge_dev_release (struct device *dev) { +struct fpga_bridge *bridge =to_fpga_bridge (dev); + +ida_simple_remove (&fpga_bridge_ida, bridge->dev.id); +kfree (bridge); }static int __init fpga_bridge_dev_init (void )Signature · 1 line
2.25.1
PATCH 5/5 fpga: region: Use standard dev_release for class driver
In reply to Russ WeightThe FPGA region class driver data structure is being treated as a managed resource instead of using standard dev_release call-back to release the class data structure. This change populates the class.dev_release function and changes the fpga_region_free() function to call put_device(). It also changes fpga_region_unregister() to call device_del() instead of device_unregister().
--- drivers/fpga/fpga-region.c | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
drivers/fpga/fpga-region.c +23 -23
@@ -181,7 +181,7 @@ ATTRIBUTE_GROUPS(fpga_region);/** * fpga_region_create - alloc and init a struct fpga_region -* @dev: device parent +* @parent: device parent * @mgr: manager that programs this region * @get_bridges: optional function to get bridges to a list *
@@ -192,7 +192,7 @@ ATTRIBUTE_GROUPS(fpga_region);* Return: struct fpga_region or NULL */ struct fpga_region -*fpga_region_create (struct device *dev, +*fpga_region_create (struct device *parent,struct fpga_manager *mgr,int (*get_bridges)(struct fpga_region *)) {
@@ -204,8 +204,10 @@ struct fpga_regionreturn NULL ; id =ida_simple_get (&fpga_region_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto err_free; +if (id <0 ) { +kfree (region); +return NULL ; + } region->mgr = mgr; region->get_bridges = get_bridges;
@@ -214,22 +216,17 @@ struct fpga_regiondevice_initialize (®ion->dev); region->dev.class = fpga_region_class; - region->dev.parent = dev; - region->dev.of_node = dev->of_node; + region->dev.parent = parent; + region->dev.of_node = parent->of_node; region->dev.id = id; ret =dev_set_name (®ion->dev,"region%d" , id); -if (ret) - goto err_remove; +if (ret) { +put_device (®ion->dev); +return NULL ; + }return region; - -err_remove: -ida_simple_remove (&fpga_region_ida, id); -err_free: -kfree (region); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_region_create);
@@ -239,8 +236,7 @@ EXPORT_SYMBOL_GPL(fpga_region_create);*/ void fpga_region_free (struct fpga_region *region) { -ida_simple_remove (&fpga_region_ida, region->dev.id); -kfree (region); +put_device (®ion->dev); }EXPORT_SYMBOL_GPL (fpga_region_free);
@@ -248,12 +244,12 @@ static void devm_fpga_region_release(struct device *dev, void *res) {struct fpga_region *region = *(struct fpga_region **)res; -fpga_region_free (region); +put_device (®ion->dev); }/** * devm_fpga_region_create - create and initialize a managed FPGA region struct -* @dev: device parent +* @parent: device parent * @mgr: manager that programs this region * @get_bridges: optional function to get bridges to a list *
@@ -268,7 +264,7 @@ static void devm_fpga_region_release(struct device *dev, void *res)* Return: struct fpga_region or NULL */ struct fpga_region -*devm_fpga_region_create (struct device *dev, +*devm_fpga_region_create (struct device *parent,struct fpga_manager *mgr,int (*get_bridges)(struct fpga_region *)) {
@@ -278,12 +274,12 @@ struct fpga_regionif (!ptr)return NULL ; - region =fpga_region_create (dev, mgr, get_bridges); + region =fpga_region_create (parent, mgr, get_bridges);if (!region) {devres_free (ptr); }else { *ptr = region; -devres_add (dev, ptr); +devres_add (parent, ptr); }return region;
@@ -310,12 +306,16 @@ EXPORT_SYMBOL_GPL(fpga_region_register);*/ void fpga_region_unregister (struct fpga_region *region) { -device_unregister (®ion->dev); +device_del (®ion->dev); }EXPORT_SYMBOL_GPL (fpga_region_unregister);static void fpga_region_dev_release (struct device *dev) { +struct fpga_region *region =to_fpga_region (dev); + +ida_simple_remove (&fpga_region_ida, region->dev.id); +kfree (region); }/**
Signature · 1 line
2.25.1
Xu Yilun
maintainerRe: [PATCH v1 5/5] fpga: region: Use standard dev_release for class driver
Quoted 26 lines · Russ Weight
The FPGA region class driver data structure is being treated as a managed resource instead of using standard
dev_releasecall-back to release the class data structure. This change populates the class.dev_release function and changes thefpga_region_free()function to callput_device(). It also changesfpga_region_unregister()to calldevice_del()instead ofdevice_unregister().Signed-off-by Russ Weight <[email protected]>--- drivers/fpga/fpga-region.c | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-)drivers/fpga/fpga-region.c +1
-1@@ -181,7 +181,7 @@ ATTRIBUTE_GROUPS(fpga_region);/** * fpga_region_create - alloc and init a struct fpga_region -* @dev: device parent +* @parent: device parent * @mgr: manager that programs this region * @get_bridges: optional function to get bridges to a list *
drivers/fpga/fpga-region.c ATTRIBUTE_GROUPS(fpga_region); · line 195
Quoted 5 lines
drivers/fpga/fpga-region.c +1
-1@@ -192,7 +192,7 @@ ATTRIBUTE_GROUPS(fpga_region);* Return: struct fpga_region or NULL */ struct fpga_region -*fpga_region_create(struct device *dev, +*fpga_region_create(struct device *parent,
Same concern, split the renaming changes out.
Quoted 56 lines
drivers/fpga/fpga-region.c +11
-15struct fpga_manager *mgr, int (*get_bridges)(struct fpga_region *)) {@@ -204,8 +204,10 @@ struct fpga_regionreturn NULL ; id =ida_simple_get (&fpga_region_ida,0 ,0 ,GFP_KERNEL ); -if (id <0 ) - goto err_free; +if (id <0 ) { +kfree (region); +return NULL ; + } region->mgr = mgr; region->get_bridges = get_bridges;@@ -214,22 +216,17 @@ struct fpga_regiondevice_initialize (®ion->dev); region->dev.class = fpga_region_class; - region->dev.parent = dev; - region->dev.of_node = dev->of_node; + region->dev.parent = parent; + region->dev.of_node = parent->of_node; region->dev.id = id; ret =dev_set_name (®ion->dev,"region%d" , id); -if (ret) - goto err_remove; +if (ret) { +put_device (®ion->dev); +return NULL ; + }return region; - -err_remove: -ida_simple_remove (&fpga_region_ida, id); -err_free: -kfree (region); - -return NULL ; }EXPORT_SYMBOL_GPL (fpga_region_create);@@ -239,8 +236,7 @@ EXPORT_SYMBOL_GPL(fpga_region_create);*/ void fpga_region_free (struct fpga_region *region) { -ida_simple_remove (&fpga_region_ida, region->dev.id); -kfree (region); +put_device (®ion->dev); }EXPORT_SYMBOL_GPL (fpga_region_free);
drivers/fpga/fpga-region.c static void devm_fpga_region_release(struct device *dev, void *res) · line 247
Quoted 5 lines
drivers/fpga/fpga-region.c +1
-1@@ -248,12 +244,12 @@ static void devm_fpga_region_release(struct device *dev, void *res) {struct fpga_region *region = *(struct fpga_region **)res; -fpga_region_free (region); +put_device (®ion->dev);
Same concern, I prefer to keep it unchanged.
Thanks,
Yilun
Quoted 53 lines
drivers/fpga/fpga-region.c +9
-5}/** * devm_fpga_region_create - create and initialize a managed FPGA region struct -* @dev: device parent +* @parent: device parent * @mgr: manager that programs this region * @get_bridges: optional function to get bridges to a list * @@ -268,7 +264,7 @@ static void devm_fpga_region_release(struct device *dev, void *res)* Return: struct fpga_region or NULL */ struct fpga_region -*devm_fpga_region_create (struct device *dev, +*devm_fpga_region_create (struct device *parent,struct fpga_manager *mgr,int (*get_bridges)(struct fpga_region *)) {@@ -278,12 +274,12 @@ struct fpga_regionif (!ptr)return NULL ; - region =fpga_region_create (dev, mgr, get_bridges); + region =fpga_region_create (parent, mgr, get_bridges);if (!region) {devres_free (ptr); }else { *ptr = region; -devres_add (dev, ptr); +devres_add (parent, ptr); }return region;@@ -310,12 +306,16 @@ EXPORT_SYMBOL_GPL(fpga_region_register);*/ void fpga_region_unregister (struct fpga_region *region) { -device_unregister (®ion->dev); +device_del (®ion->dev); }EXPORT_SYMBOL_GPL (fpga_region_unregister);static void fpga_region_dev_release (struct device *dev) { +struct fpga_region *region =to_fpga_region (dev); + +ida_simple_remove (&fpga_region_ida, region->dev.id); +kfree (region); }/** Signature · 1 line
2.25.1