From: Xu Yilun <yilun.xu@intel.com>
To: Russ Weight <russell.h.weight@intel.com>
Cc: mdf@kernel.org, linux-fpga@vger.kernel.org, trix@redhat.com,
lgoncalv@redhat.com, hao.wu@intel.com, matthew.gerlach@intel.com,
richard.gong@intel.com
Subject: Re: [PATCH v3 3/3] fpga: region: Use standard dev_release for class driver
Date: Sat, 29 May 2021 00:10:42 +0800 [thread overview]
Message-ID: <20210528161042.GC1881814@yilunxu-OptiPlex-7050> (raw)
In-Reply-To: <20210524185049.681683-4-russell.h.weight@intel.com>
On Mon, May 24, 2021 at 11:50:49AM -0700, Russ Weight wrote:
> The 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 removes the
> managed resource code and combines the create() and register()
> functions into a single register() function.
>
> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
> ---
> v3:
> - Cleaned up comment header for fpga_region_register()
> - Fix fpga_region_register() error return on ida_simple_get() failure
> v2:
> - No changes
> ---
> drivers/fpga/dfl-fme-region.c | 10 +--
> drivers/fpga/dfl.c | 10 +--
> drivers/fpga/fpga-region.c | 103 ++++++-------------------------
> drivers/fpga/of-fpga-region.c | 10 +--
> include/linux/fpga/fpga-region.h | 12 +---
> 5 files changed, 32 insertions(+), 113 deletions(-)
>
> diff --git a/drivers/fpga/dfl-fme-region.c b/drivers/fpga/dfl-fme-region.c
> index 1eeb42af1012..631c8ce160e3 100644
> --- a/drivers/fpga/dfl-fme-region.c
> +++ b/drivers/fpga/dfl-fme-region.c
> @@ -39,9 +39,9 @@ static int fme_region_probe(struct platform_device *pdev)
> if (IS_ERR(mgr))
> return -EPROBE_DEFER;
>
> - region = devm_fpga_region_create(dev, mgr, fme_region_get_bridges);
> - if (!region) {
> - ret = -ENOMEM;
> + region = fpga_region_register(dev, mgr, fme_region_get_bridges);
> + if (IS_ERR(region)) {
> + ret = PTR_ERR(region);
> goto eprobe_mgr_put;
> }
>
> @@ -49,10 +49,6 @@ static int fme_region_probe(struct platform_device *pdev)
> region->compat_id = mgr->compat_id;
This is the issue I've mentioned in Patch #1. There is a chance user
get zero value via compat_id sysfs node.
> platform_set_drvdata(pdev, region);
>
> - ret = fpga_region_register(region);
> - if (ret)
> - goto eprobe_mgr_put;
> -
> dev_dbg(dev, "DFL FME FPGA Region probed\n");
>
> return 0;
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 511b20ff35a3..2fb3a5bfe4df 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -1400,9 +1400,9 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info)
> if (!cdev)
> return ERR_PTR(-ENOMEM);
>
> - cdev->region = devm_fpga_region_create(info->dev, NULL, NULL);
> - if (!cdev->region) {
> - ret = -ENOMEM;
> + cdev->region = fpga_region_register(info->dev, NULL, NULL);
> + if (IS_ERR(cdev->region)) {
> + ret = PTR_ERR(cdev->region);
> goto free_cdev_exit;
> }
>
> @@ -1410,10 +1410,6 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info)
> mutex_init(&cdev->lock);
> INIT_LIST_HEAD(&cdev->port_dev_list);
How about we moves fpga_region_register() here? It was here before.
Thanks,
Yilun
>
> - ret = fpga_region_register(cdev->region);
> - if (ret)
> - goto free_cdev_exit;
> -
> /* create and init build info for enumeration */
> binfo = devm_kzalloc(info->dev, sizeof(*binfo), GFP_KERNEL);
> if (!binfo) {
> diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
> index c3134b89c3fe..f65f60367e2c 100644
> --- a/drivers/fpga/fpga-region.c
> +++ b/drivers/fpga/fpga-region.c
> @@ -180,39 +180,35 @@ static struct attribute *fpga_region_attrs[] = {
> ATTRIBUTE_GROUPS(fpga_region);
>
> /**
> - * fpga_region_create - alloc and init a struct fpga_region
> + * fpga_region_register - create and register a FPGA Region device
> * @dev: device parent
> * @mgr: manager that programs this region
> * @get_bridges: optional function to get bridges to a list
> *
> - * The caller of this function is responsible for freeing the resulting region
> - * struct with fpga_region_free(). Using devm_fpga_region_create() instead is
> - * recommended.
> - *
> - * Return: struct fpga_region or NULL
> + * Returns a struct fpga_region pointer on success, or ERR_PTR() on error.
> */
> -struct fpga_region
> -*fpga_region_create(struct device *dev,
> - struct fpga_manager *mgr,
> - int (*get_bridges)(struct fpga_region *))
> +struct fpga_region *
> +fpga_region_register(struct device *dev, struct fpga_manager *mgr,
> + int (*get_bridges)(struct fpga_region *))
> {
> struct fpga_region *region;
> int id, ret = 0;
>
> region = kzalloc(sizeof(*region), GFP_KERNEL);
> if (!region)
> - return NULL;
> + return ERR_PTR(-ENOMEM);
>
> id = ida_simple_get(&fpga_region_ida, 0, 0, GFP_KERNEL);
> - if (id < 0)
> + if (id < 0) {
> + ret = id;
> goto err_free;
> + }
>
> region->mgr = mgr;
> region->get_bridges = get_bridges;
> mutex_init(®ion->mutex);
> INIT_LIST_HEAD(®ion->bridge_list);
>
> - device_initialize(®ion->dev);
> region->dev.class = fpga_region_class;
> region->dev.parent = dev;
> region->dev.of_node = dev->of_node;
> @@ -222,6 +218,12 @@ struct fpga_region
> if (ret)
> goto err_remove;
>
> + ret = device_register(®ion->dev);
> + if (ret) {
> + put_device(®ion->dev);
> + return ERR_PTR(ret);
> + }
> +
> return region;
>
> err_remove:
> @@ -229,76 +231,7 @@ struct fpga_region
> err_free:
> kfree(region);
>
> - return NULL;
> -}
> -EXPORT_SYMBOL_GPL(fpga_region_create);
> -
> -/**
> - * fpga_region_free - free a FPGA region created by fpga_region_create()
> - * @region: FPGA region
> - */
> -void fpga_region_free(struct fpga_region *region)
> -{
> - ida_simple_remove(&fpga_region_ida, region->dev.id);
> - kfree(region);
> -}
> -EXPORT_SYMBOL_GPL(fpga_region_free);
> -
> -static void devm_fpga_region_release(struct device *dev, void *res)
> -{
> - struct fpga_region *region = *(struct fpga_region **)res;
> -
> - fpga_region_free(region);
> -}
> -
> -/**
> - * devm_fpga_region_create - create and initialize a managed FPGA region struct
> - * @dev: device parent
> - * @mgr: manager that programs this region
> - * @get_bridges: optional function to get bridges to a list
> - *
> - * This function is intended for use in a FPGA region driver's probe function.
> - * After the region driver creates the region struct with
> - * devm_fpga_region_create(), it should register it with fpga_region_register().
> - * The region driver's remove function should call fpga_region_unregister().
> - * The region struct allocated with this function will be freed automatically on
> - * driver detach. This includes the case of a probe function returning error
> - * before calling fpga_region_register(), the struct will still get cleaned up.
> - *
> - * Return: struct fpga_region or NULL
> - */
> -struct fpga_region
> -*devm_fpga_region_create(struct device *dev,
> - struct fpga_manager *mgr,
> - int (*get_bridges)(struct fpga_region *))
> -{
> - struct fpga_region **ptr, *region;
> -
> - ptr = devres_alloc(devm_fpga_region_release, sizeof(*ptr), GFP_KERNEL);
> - if (!ptr)
> - return NULL;
> -
> - region = fpga_region_create(dev, mgr, get_bridges);
> - if (!region) {
> - devres_free(ptr);
> - } else {
> - *ptr = region;
> - devres_add(dev, ptr);
> - }
> -
> - return region;
> -}
> -EXPORT_SYMBOL_GPL(devm_fpga_region_create);
> -
> -/**
> - * fpga_region_register - register a FPGA region
> - * @region: FPGA region
> - *
> - * Return: 0 or -errno
> - */
> -int fpga_region_register(struct fpga_region *region)
> -{
> - return device_add(®ion->dev);
> + return ERR_PTR(ret);
> }
> EXPORT_SYMBOL_GPL(fpga_region_register);
>
> @@ -316,6 +249,10 @@ 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);
> }
>
> /**
> diff --git a/drivers/fpga/of-fpga-region.c b/drivers/fpga/of-fpga-region.c
> index e405309baadc..466e083654ae 100644
> --- a/drivers/fpga/of-fpga-region.c
> +++ b/drivers/fpga/of-fpga-region.c
> @@ -405,16 +405,12 @@ static int of_fpga_region_probe(struct platform_device *pdev)
> if (IS_ERR(mgr))
> return -EPROBE_DEFER;
>
> - region = devm_fpga_region_create(dev, mgr, of_fpga_region_get_bridges);
> - if (!region) {
> - ret = -ENOMEM;
> + region = fpga_region_register(dev, mgr, of_fpga_region_get_bridges);
> + if (IS_ERR(region)) {
> + ret = PTR_ERR(region);
> goto eprobe_mgr_put;
> }
>
> - ret = fpga_region_register(region);
> - if (ret)
> - goto eprobe_mgr_put;
> -
> of_platform_populate(np, fpga_region_of_match, NULL, ®ion->dev);
> platform_set_drvdata(pdev, region);
>
> diff --git a/include/linux/fpga/fpga-region.h b/include/linux/fpga/fpga-region.h
> index 27cb706275db..ca793f43af14 100644
> --- a/include/linux/fpga/fpga-region.h
> +++ b/include/linux/fpga/fpga-region.h
> @@ -37,15 +37,9 @@ struct fpga_region *fpga_region_class_find(
>
> int fpga_region_program_fpga(struct fpga_region *region);
>
> -struct fpga_region
> -*fpga_region_create(struct device *dev, struct fpga_manager *mgr,
> - int (*get_bridges)(struct fpga_region *));
> -void fpga_region_free(struct fpga_region *region);
> -int fpga_region_register(struct fpga_region *region);
> +struct fpga_region *
> +fpga_region_register(struct device *dev, struct fpga_manager *mgr,
> + int (*get_bridges)(struct fpga_region *));
> void fpga_region_unregister(struct fpga_region *region);
>
> -struct fpga_region
> -*devm_fpga_region_create(struct device *dev, struct fpga_manager *mgr,
> - int (*get_bridges)(struct fpga_region *));
> -
> #endif /* _FPGA_REGION_H */
> --
> 2.25.1
next prev parent reply other threads:[~2021-05-28 16:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-24 18:50 [PATCH v3 0/3] fpga: Use standard class dev_release function Russ Weight
2021-05-24 18:50 ` [PATCH v3 1/3] fpga: mgr: Use standard dev_release for class driver Russ Weight
2021-05-24 20:16 ` Tom Rix
2021-05-25 16:51 ` Russ Weight
2021-05-28 14:46 ` Xu Yilun
2021-05-24 22:39 ` Moritz Fischer
2021-05-24 23:07 ` Russ Weight
2021-05-25 17:39 ` Russ Weight
2021-05-25 19:00 ` Tom Rix
2021-05-28 15:41 ` Xu Yilun
2021-05-28 17:26 ` Russ Weight
2021-05-24 18:50 ` [PATCH v3 2/3] fpga: bridge: " Russ Weight
2021-05-28 15:51 ` Xu Yilun
2021-05-24 18:50 ` [PATCH v3 3/3] fpga: region: " Russ Weight
2021-05-28 16:10 ` Xu Yilun [this message]
2021-05-28 17:43 ` Russ Weight
2021-05-24 18:52 ` [PATCH v3 0/3] fpga: Use standard class dev_release function Russ Weight
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=20210528161042.GC1881814@yilunxu-OptiPlex-7050 \
--to=yilun.xu@intel.com \
--cc=hao.wu@intel.com \
--cc=lgoncalv@redhat.com \
--cc=linux-fpga@vger.kernel.org \
--cc=matthew.gerlach@intel.com \
--cc=mdf@kernel.org \
--cc=richard.gong@intel.com \
--cc=russell.h.weight@intel.com \
--cc=trix@redhat.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;
as well as URLs for NNTP newsgroup(s).