2019-08-12 03:08:42

by Wu Hao

[permalink] [raw]
Subject: [PATCH v5 1/9] fpga: dfl: make init callback optional

This patch makes init callback of sub features optional. With
this change, people don't need to prepare any empty init callback.

Signed-off-by: Wu Hao <[email protected]>
---
drivers/fpga/dfl.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index c0512af..96a2b82 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -271,11 +271,13 @@ static int dfl_feature_instance_init(struct platform_device *pdev,
struct dfl_feature *feature,
struct dfl_feature_driver *drv)
{
- int ret;
+ int ret = 0;

- ret = drv->ops->init(pdev, feature);
- if (ret)
- return ret;
+ if (drv->ops->init) {
+ ret = drv->ops->init(pdev, feature);
+ if (ret)
+ return ret;
+ }

feature->ops = drv->ops;

--
1.8.3.1


2019-08-21 03:26:23

by Moritz Fischer

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] fpga: dfl: make init callback optional

Hi,

On Mon, Aug 12, 2019 at 10:49:56AM +0800, Wu Hao wrote:
> This patch makes init callback of sub features optional. With
> this change, people don't need to prepare any empty init callback.
>
> Signed-off-by: Wu Hao <[email protected]>

Acked-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/dfl.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index c0512af..96a2b82 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -271,11 +271,13 @@ static int dfl_feature_instance_init(struct platform_device *pdev,
> struct dfl_feature *feature,
> struct dfl_feature_driver *drv)
> {
> - int ret;
> + int ret = 0;
>
> - ret = drv->ops->init(pdev, feature);
> - if (ret)
> - return ret;
> + if (drv->ops->init) {
> + ret = drv->ops->init(pdev, feature);
> + if (ret)
> + return ret;
> + }
>
> feature->ops = drv->ops;

You could swap it around maybe like so:

int dfl_feature_instance_init() ...
{
feature->ops = drv->ops;
if (drv->ops->init)
return drv->ops->init(pdev, feature);

return 0;
}

With the caveat that feature->ops gets always set ...

Your call.

Thanks,
Moritz

2019-08-21 05:32:35

by Wu Hao

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] fpga: dfl: make init callback optional

On Tue, Aug 20, 2019 at 08:24:06PM -0700, Moritz Fischer wrote:
> Hi,
>
> On Mon, Aug 12, 2019 at 10:49:56AM +0800, Wu Hao wrote:
> > This patch makes init callback of sub features optional. With
> > this change, people don't need to prepare any empty init callback.
> >
> > Signed-off-by: Wu Hao <[email protected]>
>
> Acked-by: Moritz Fischer <[email protected]>
> > ---
> > drivers/fpga/dfl.c | 10 ++++++----
> > 1 file changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> > index c0512af..96a2b82 100644
> > --- a/drivers/fpga/dfl.c
> > +++ b/drivers/fpga/dfl.c
> > @@ -271,11 +271,13 @@ static int dfl_feature_instance_init(struct platform_device *pdev,
> > struct dfl_feature *feature,
> > struct dfl_feature_driver *drv)
> > {
> > - int ret;
> > + int ret = 0;
> >
> > - ret = drv->ops->init(pdev, feature);
> > - if (ret)
> > - return ret;
> > + if (drv->ops->init) {
> > + ret = drv->ops->init(pdev, feature);
> > + if (ret)
> > + return ret;
> > + }
> >
> > feature->ops = drv->ops;
>
> You could swap it around maybe like so:
>
> int dfl_feature_instance_init() ...
> {
> feature->ops = drv->ops;
> if (drv->ops->init)
> return drv->ops->init(pdev, feature);
>
> return 0;
> }
>
> With the caveat that feature->ops gets always set ...
>
> Your call.

Hi Moritz,

Thanks a lot for the review and comments. It does simplify the code,
will modify it.

Thanks
Hao

>
> Thanks,
> Moritz