2021-12-11 13:43:40

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] fpga: stratix10-soc: fix NULL vs IS_ERR() checking

The stratix10_svc_allocate_memory function does not return NULL. It
returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.

Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/fpga/stratix10-soc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
index 047fd7f23706..2d2687a90ae6 100644
--- a/drivers/fpga/stratix10-soc.c
+++ b/drivers/fpga/stratix10-soc.c
@@ -213,7 +213,7 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
/* Allocate buffers from the service layer's pool. */
for (i = 0; i < NUM_SVC_BUFS; i++) {
kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
- if (!kbuf) {
+ if (IS_ERR(kbuf)) {
s10_free_buffers(mgr);
ret = -ENOMEM;
goto init_done;
--
2.17.1



2021-12-11 14:05:22

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH] fpga: stratix10-soc: fix NULL vs IS_ERR() checking


On 12/11/21 5:43 AM, Miaoqian Lin wrote:
> The stratix10_svc_allocate_memory function does not return NULL. It
> returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.
>
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> drivers/fpga/stratix10-soc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> index 047fd7f23706..2d2687a90ae6 100644
> --- a/drivers/fpga/stratix10-soc.c
> +++ b/drivers/fpga/stratix10-soc.c
> @@ -213,7 +213,7 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
> /* Allocate buffers from the service layer's pool. */
> for (i = 0; i < NUM_SVC_BUFS; i++) {
> kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
> - if (!kbuf) {
> + if (IS_ERR(kbuf)) {
> s10_free_buffers(mgr);
> ret = -ENOMEM;

This should also change to

ret = PTR_ERR(kbuf)

Tom

> goto init_done;


2021-12-11 14:50:48

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH v2] fpga: stratix10-soc: fix NULL vs IS_ERR() checking

The stratix10_svc_allocate_memory function does not return NULL. It
returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.

Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/fpga/stratix10-soc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
index 047fd7f23706..91212bab5871 100644
--- a/drivers/fpga/stratix10-soc.c
+++ b/drivers/fpga/stratix10-soc.c
@@ -213,9 +213,9 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
/* Allocate buffers from the service layer's pool. */
for (i = 0; i < NUM_SVC_BUFS; i++) {
kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
- if (!kbuf) {
+ if (IS_ERR(kbuf)) {
s10_free_buffers(mgr);
- ret = -ENOMEM;
+ ret = PTR_ERR(kbuf);
goto init_done;
}

--
2.17.1


2021-12-11 14:59:04

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH v2] fpga: stratix10-soc: fix NULL vs IS_ERR() checking


On 12/11/21 6:50 AM, Miaoqian Lin wrote:
> The stratix10_svc_allocate_memory function does not return NULL. It
> returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.
>
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> drivers/fpga/stratix10-soc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> index 047fd7f23706..91212bab5871 100644
> --- a/drivers/fpga/stratix10-soc.c
> +++ b/drivers/fpga/stratix10-soc.c
> @@ -213,9 +213,9 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
> /* Allocate buffers from the service layer's pool. */
> for (i = 0; i < NUM_SVC_BUFS; i++) {
> kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
> - if (!kbuf) {
> + if (IS_ERR(kbuf)) {
> s10_free_buffers(mgr);
> - ret = -ENOMEM;
> + ret = PTR_ERR(kbuf);

Thanks!

Reviewed-by: Tom Rix <[email protected]>

> goto init_done;
> }
>


2021-12-13 01:35:53

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH v2] fpga: stratix10-soc: fix NULL vs IS_ERR() checking

On Sat, Dec 11, 2021 at 06:57:51AM -0800, Tom Rix wrote:
>
> On 12/11/21 6:50 AM, Miaoqian Lin wrote:
> > The stratix10_svc_allocate_memory function does not return NULL. It
> > returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.
> >
> > Signed-off-by: Miaoqian Lin <[email protected]>
> > ---
> > drivers/fpga/stratix10-soc.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> > index 047fd7f23706..91212bab5871 100644
> > --- a/drivers/fpga/stratix10-soc.c
> > +++ b/drivers/fpga/stratix10-soc.c
> > @@ -213,9 +213,9 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
> > /* Allocate buffers from the service layer's pool. */
> > for (i = 0; i < NUM_SVC_BUFS; i++) {
> > kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
> > - if (!kbuf) {
> > + if (IS_ERR(kbuf)) {
> > s10_free_buffers(mgr);
> > - ret = -ENOMEM;
> > + ret = PTR_ERR(kbuf);
>
> Thanks!
>
> Reviewed-by: Tom Rix <[email protected]>

Acked-by: Xu Yilun <[email protected]>

Thanks,
Yilun

>
> > goto init_done;
> > }

2021-12-13 06:12:45

by Wu Hao

[permalink] [raw]
Subject: RE: [PATCH v2] fpga: stratix10-soc: fix NULL vs IS_ERR() checking

> > On 12/11/21 6:50 AM, Miaoqian Lin wrote:
> > > The stratix10_svc_allocate_memory function does not return NULL. It
> > > returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.
> > >

Please add "Fixes" tag, then
Acked-by: Wu Hao <[email protected]>

Thanks for the patch.
Hao

> > > Signed-off-by: Miaoqian Lin <[email protected]>
> > > ---
> > > drivers/fpga/stratix10-soc.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> > > index 047fd7f23706..91212bab5871 100644
> > > --- a/drivers/fpga/stratix10-soc.c
> > > +++ b/drivers/fpga/stratix10-soc.c
> > > @@ -213,9 +213,9 @@ static int s10_ops_write_init(struct fpga_manager
> *mgr,
> > > /* Allocate buffers from the service layer's pool. */
> > > for (i = 0; i < NUM_SVC_BUFS; i++) {
> > > kbuf = stratix10_svc_allocate_memory(priv->chan,
> SVC_BUF_SIZE);
> > > - if (!kbuf) {
> > > + if (IS_ERR(kbuf)) {
> > > s10_free_buffers(mgr);
> > > - ret = -ENOMEM;
> > > + ret = PTR_ERR(kbuf);
> >
> > Thanks!
> >
> > Reviewed-by: Tom Rix <[email protected]>
>
> Acked-by: Xu Yilun <[email protected]>
>
> Thanks,
> Yilun
>
> >
> > > goto init_done;
> > > }

2021-12-13 06:49:15

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH v3] fpga: stratix10-soc: fix NULL vs IS_ERR() checking

The stratix10_svc_allocate_memory function does not return NULL. It
returns ERR_PTR(-ENOMEM). Use IS_ERR check the return value.

Fixes: e7eef1d7633a("fpga: add intel stratix10 soc fpga manager driver")
Signed-off-by: Miaoqian Lin <[email protected]>
Reviewed-by: Tom Rix <[email protected]>
Acked-by: Xu Yilun <[email protected]>
Acked-by: Wu Hao <[email protected]>
---
drivers/fpga/stratix10-soc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
index 047fd7f23706..91212bab5871 100644
--- a/drivers/fpga/stratix10-soc.c
+++ b/drivers/fpga/stratix10-soc.c
@@ -213,9 +213,9 @@ static int s10_ops_write_init(struct fpga_manager *mgr,
/* Allocate buffers from the service layer's pool. */
for (i = 0; i < NUM_SVC_BUFS; i++) {
kbuf = stratix10_svc_allocate_memory(priv->chan, SVC_BUF_SIZE);
- if (!kbuf) {
+ if (IS_ERR(kbuf)) {
s10_free_buffers(mgr);
- ret = -ENOMEM;
+ ret = PTR_ERR(kbuf);
goto init_done;
}

--
2.17.1