From: Federico Vaga <federico.vaga@cern.ch>
To: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org
Subject: Re: [PATCH 1/2] fpga: Document when fpga_blah_free functions should be used
Date: Thu, 26 Jul 2018 09:26:33 +0200 [thread overview]
Message-ID: <3092191.aOBZP6MEga@pcbe13614> (raw)
In-Reply-To: <20180725181514.3501-1-atull@kernel.org>
Hi Alan,
have you considered the possibility of having something like devm_fpga_[mgr|
bridge|region]_[create|free]() ? Like this, it will be obvious that 'struct
fpga_mgr' will be released automatically without reading any comment (but the
comment is still good), and you use devm_*_free() only to handle error
conditions.
On Wednesday, July 25, 2018 8:15:13 PM CEST Alan Tull wrote:
> Clarify when fpga_(mgr|bridge|region)_free functions should be used.
> The class's dev_release will handle cleanup when the device is released
> so once the mgr/brige/region has been successfully registered, it
> would be a bug to call fpga_(mgr|bridge|region)_free.
>
> Signed-off-by: Alan Tull <atull@kernel.org>
> Suggested-by: Florian Fainelli <f.fainelli@gmail.com>
> Suggested-by: Federico Vaga <federico.vaga@cern.ch>
> ---
> drivers/fpga/fpga-bridge.c | 10 +++++++++-
> drivers/fpga/fpga-mgr.c | 10 +++++++++-
> drivers/fpga/fpga-region.c | 10 +++++++++-
> 3 files changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 24b8f98..528d2149 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -379,7 +379,11 @@ EXPORT_SYMBOL_GPL(fpga_bridge_create);
>
> /**
> * fpga_bridge_free - free a fpga bridge and its id
> - * @bridge: FPGA bridge struct created by fpga_bridge_create
> + * @bridge: FPGA bridge struct created by fpga_bridge_create()
> + *
> + * Free a FPGA bridge. This function should only be called for
> + * freeing a bridge that has not been registered yet (such as in error
> + * paths in a probe function).
> */
> void fpga_bridge_free(struct fpga_bridge *bridge)
> {
> @@ -414,6 +418,10 @@ EXPORT_SYMBOL_GPL(fpga_bridge_register);
> /**
> * fpga_bridge_unregister - unregister and free a fpga bridge
> * @bridge: FPGA bridge struct created by fpga_bridge_create
> + *
> + * Unregister the bridge device. The class's dev_release will handle
> + * freeing the bridge struct when the device is released so don't
> + * call fpga_bridge_free() after calling fpga_bridge_unregister().
> */
> void fpga_bridge_unregister(struct fpga_bridge *bridge)
> {
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index a41b07e..9632cbd 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -619,7 +619,11 @@ EXPORT_SYMBOL_GPL(fpga_mgr_create);
>
> /**
> * fpga_mgr_free - deallocate a FPGA manager
> - * @mgr: fpga manager struct created by fpga_mgr_create
> + * @mgr: fpga manager struct created by fpga_mgr_create()
> + *
> + * Free a FPGA manager struct. This function should only be called
> + * for freeing a manager that has not been registered yet (such as in
> + * error paths in a probe function).
> */
> void fpga_mgr_free(struct fpga_manager *mgr)
> {
> @@ -663,6 +667,10 @@ EXPORT_SYMBOL_GPL(fpga_mgr_register);
> /**
> * fpga_mgr_unregister - unregister and free a FPGA manager
> * @mgr: fpga manager struct
> + *
> + * Unregister the manager device. The class's dev_release will handle
> + * freeing the manager struct when the device is released so don't
> + * call fpga_mgr_free() after calling fpga_mgr_unregister().
> */
> void fpga_mgr_unregister(struct fpga_manager *mgr)
> {
> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
> index 0d65220..7335fa9 100644
> --- a/drivers/fpga/fpga-region.c
> +++ b/drivers/fpga/fpga-region.c
> @@ -231,7 +231,11 @@ EXPORT_SYMBOL_GPL(fpga_region_create);
>
> /**
> * fpga_region_free - free a struct fpga_region
> - * @region: FPGA region created by fpga_region_create
> + * @region: FPGA region created by fpga_region_create()
> + *
> + * Free a FPGA region struct. This function should only be called for
> + * freeing a region that has not been registered yet (such as in error
> + * paths in a probe function).
> */
> void fpga_region_free(struct fpga_region *region)
> {
> @@ -255,6 +259,10 @@ EXPORT_SYMBOL_GPL(fpga_region_register);
> /**
> * fpga_region_unregister - unregister and free a FPGA region
> * @region: FPGA region
> + *
> + * Unregister the region device. The class's dev_release will handle
> + * freeing the region so don't call fpga_region_free() after calling
> + * fpga_region_unregister().
> */
> void fpga_region_unregister(struct fpga_region *region)
> {
next prev parent reply other threads:[~2018-07-26 8:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-25 18:15 [PATCH 1/2] fpga: Document when fpga_blah_free functions should be used Alan Tull
2018-07-25 18:15 ` [PATCH 2/2] fpga: do not access region struct after fpga_region_unregister Alan Tull
2018-07-26 7:26 ` Federico Vaga [this message]
2018-08-14 23:57 ` [PATCH 1/2] fpga: Document when fpga_blah_free functions should be used Alan Tull
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=3092191.aOBZP6MEga@pcbe13614 \
--to=federico.vaga@cern.ch \
--cc=atull@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).