Skip to contentSkip to conversation

firmware: stratix10-svc: Fix some error handling code

PATCH Superseded Christophe JAILLET 4 participants 20 messages Apr 29, 2020 – Jun 27, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover firmware: stratix10-svc: Fix some error handling code

This serie was previously sent as a single patch.
After a comment from Dan Carpenter about an error handling path that could be improved, I've looked deeper at the code and found other issues.

The previous patch corresponds to patch 3/4 in this serie. This v2 takes Dan's comment into account and fix another resource leak.

Patch 1/4: svc_create_memory_pool returns an error code on error, not NULL Patch 2/4: undo a memremap on error path and remove funtion Patch 3/4: improve error handling in the probe function
Patch 4/4: unrelated clean-up

Christophe JAILLET (4):
firmware: stratix10-svc: Fix genpool creation error handling
firmware: stratix10-svc: Unmap some previously memremap'ed memory
firmware: stratix10-svc: Fix some error handling paths in

    'stratix10_svc_drv_probe()'

firmware: stratix10-svc: Slighly simplify call

 drivers/firmware/stratix10-svc.c | 42 +++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 firmware: stratix10-svc: Fix genpool creation error handling

'svc_create_memory_pool()' returns an error pointer on error, not NULL. Fix the corresponding test and return value accordingly.

Move the genpool allocation after a few devm_kzalloc in order to ease error handling.

Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
 drivers/firmware/stratix10-svc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +4 -4
index d5f0769f3761..3a176e62754a 100644
@@ -997,10 +997,6 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	genpool = svc_create_memory_pool(pdev, sh_memory);
-	if (!genpool)
-		return -ENOMEM;
-
 	/* allocate service controller and supporting channel */
 	controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
 	if (!controller)
@@ -1011,6 +1007,10 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	if (!chans)
 		return -ENOMEM;
 
+	genpool = svc_create_memory_pool(pdev, sh_memory);
+	if (IS_ERR(genpool))
+		return PTR_ERR(genpool);
+
 	controller->dev = dev;
 	controller->num_chans = SVC_NUM_CHANNEL;
 	controller->num_active_client = 0;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/4 firmware: stratix10-svc: Unmap some previously memremap'ed memory

In reply to Christophe JAILLET

In 'svc_create_memory_pool()' we memremap some memory. This has to be undone in case of error and if the driver is removed.

The easiest way to do it is to use 'devm_memremap()'.

Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
 drivers/firmware/stratix10-svc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/stratix10-svc.c +1 -1
index 3a176e62754a..de5870f76c5e 100644
@@ -631,7 +631,7 @@ svc_create_memory_pool(struct platform_device *pdev,
 	end = rounddown(sh_memory->addr + sh_memory->size, PAGE_SIZE);
 	paddr = begin;
 	size = end - begin;
-	va = memremap(paddr, size, MEMREMAP_WC);
+	va = devm_memremap(dev, paddr, size, MEMREMAP_WC);
 	if (!va) {
 		dev_err(dev, "fail to remap shared memory\n");
 		return ERR_PTR(-EINVAL);
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH 2/4 v2] firmware: stratix10-svc: Unmap some previously memremap'ed memory

Quoted 16 lines · Christophe JAILLET

In 'svc_create_memory_pool()' we memremap some memory. This has to be undone in case of error and if the driver is removed.

The easiest way to do it is to use 'devm_memremap()'.

Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
 drivers/firmware/stratix10-svc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/stratix10-svc.c +0 -0
index 3a176e62754a..de5870f76c5e 100644

drivers/firmware/stratix10-svc.c svc_create_memory_pool(struct platform_device *pdev, · line 637

Quoted 8 lines
drivers/firmware/stratix10-svc.c +1 -1
@@ -631,7 +631,7 @@ svc_create_memory_pool(struct platform_device *pdev,
 	end = rounddown(sh_memory->addr + sh_memory->size, PAGE_SIZE);
 	paddr = begin;
 	size = end - begin;
-	va = memremap(paddr, size, MEMREMAP_WC);
+	va = devm_memremap(dev, paddr, size, MEMREMAP_WC);
 	if (!va) {
 		dev_err(dev, "fail to remap shared memory\n");
 		return ERR_PTR(-EINVAL);

And there was no previous unmap happening when the pool was torn down that now needs to be removed?

thanks,

greg k-h

#4 lore raw

Re: [PATCH 2/4 v2] firmware: stratix10-svc: Unmap some previously memremap'ed memory

Le 05/05/2020 à 16:43, Greg KH a écrit :

Quoted 12 lines · Christophe JAILLET
Quoted 11 lines

In 'svc_create_memory_pool()' we memremap some memory. This has to be undone in case of error and if the driver is removed.

The easiest way to do it is to use 'devm_memremap()'.

Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
  drivers/firmware/stratix10-svc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/firmware/stratix10-svc.c svc_create_memory_pool(struct platform_device *pdev, · line 637

Quoted 13 lines
drivers/firmware/stratix10-svc.c +1 -1
index 3a176e62754a..de5870f76c5e 100644
@@ -631,7 +631,7 @@ svc_create_memory_pool(struct platform_device *pdev,
  	end = rounddown(sh_memory->addr + sh_memory->size, PAGE_SIZE);
  	paddr = begin;
  	size = end - begin;
-	va = memremap(paddr, size, MEMREMAP_WC);
+	va = devm_memremap(dev, paddr, size, MEMREMAP_WC);
  	if (!va) {
  		dev_err(dev, "fail to remap shared memory\n");
  		return ERR_PTR(-EINVAL);

And there was no previous unmap happening when the pool was torn down that now needs to be removed?

I don't think so, there is no memunmap call in 'stratix10-svc.c'

CJ

Quoted 4 lines

thanks,

greg k-h

#5 lore raw

PATCH v2 3/4 firmware: stratix10-svc: Fix some error handling paths in 'stratix10_svc_drv_probe()'

In reply to Christophe JAILLET

If an error occurs after calling 'svc_create_memory_pool()', the allocated genpool should be destroyed with 'gen_pool_destroy()', as already done in the remove function.

If an error occurs after calling 'kfifo_alloc()', the allocated memory should be freed with 'kfifo_free()', as already done in the remove function.

While at it, also move a 'platform_device_put()' call to the error handling path.

Fixes b5dc75c915cd ("firmware: stratix10-svc: extend svc to support new RSU features")
Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
 drivers/firmware/stratix10-svc.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/firmware/stratix10-svc.c +18 -8
index de5870f76c5e..739004398877 100644
@@ -1024,7 +1024,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	ret = kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL);
 	if (ret) {
 		dev_err(dev, "failed to allocate FIFO\n");
-		return ret;
+		goto err_destroy_pool;
 	}
 	spin_lock_init(&controller->svc_fifo_lock);
 
@@ -1043,24 +1043,34 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 
 	/* add svc client device(s) */
 	svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL);
-	if (!svc)
-		return -ENOMEM;
+	if (!svc) {
+		ret = -ENOMEM;
+		goto err_free_kfifo;
+	}
 
 	svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0);
 	if (!svc->stratix10_svc_rsu) {
 		dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_free_kfifo;
 	}
 
 	ret = platform_device_add(svc->stratix10_svc_rsu);
-	if (ret) {
-		platform_device_put(svc->stratix10_svc_rsu);
-		return ret;
-	}
+	if (ret)
+		goto put_platform;
+
 	dev_set_drvdata(dev, svc);
 
 	pr_info("Intel Service Layer Driver Initialized\n");
 
+	return 0;
+
+put_platform:
+	platform_device_put(svc->stratix10_svc_rsu);
+err_free_kfifo:
+	kfifo_free(&controller->svc_fifo);
+err_destroy_pool:
+	gen_pool_destroy(genpool);
 	return ret;
 }
 
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH 3/4 v2] firmware: stratix10-svc: Fix some error handling paths in 'stratix10_svc_drv_probe()'

Hi,

Similarly we need add error handling for controller and chans, something like below:

@@ -997,13 +997,17 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)

        /* allocate service controller and supporting channel */
        controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);

- if (!controller)
- return -ENOMEM;
+ if (!controller) {
+ ret = -ENOMEM;
+ goto err_destroy_pool;
+ }

chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
sizeof(*chans), GFP_KERNEL |
__GFP_ZERO);
- if (!chans)
- return -ENOMEM;
+ if (!chans) {
+ ret = -ENOMEM;
+ goto err_destroy_pool;
+ }

        controller->dev = dev;
        controller->num_chans = SVC_NUM_CHANNEL;
Quoted 11 lines · Christophe JAILLET

If an error occurs after calling 'svc_create_memory_pool()', the allocated genpool should be destroyed with 'gen_pool_destroy()', as already done in the remove function.

If an error occurs after calling 'kfifo_alloc()', the allocated memory should be freed with 'kfifo_free()', as already done in the remove function.

While at it, also move a 'platform_device_put()' call to the error handling path.

Quoted 7 lines
Fixes b5dc75c915cd ("firmware: stratix10-svc: extend svc to support new RSU features")
Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
---
  drivers/firmware/stratix10-svc.c | 26 ++++++++++++++++++--------
  1 file changed, 18 insertions(+), 8 deletions(-)

I am fine with below changes.

Quoted 46 lines
drivers/firmware/stratix10-svc.c +11 -8
index de5870f76c5e..739004398877 100644
@@ -1024,7 +1024,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
  	ret = kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL);
  	if (ret) {
  		dev_err(dev, "failed to allocate FIFO\n");
-		return ret;
+		goto err_destroy_pool;
  	}
  	spin_lock_init(&controller->svc_fifo_lock);
 
@@ -1043,24 +1043,34 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 
  	/* add svc client device(s) */
  	svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL);
-	if (!svc)
-		return -ENOMEM;
+	if (!svc) {
+		ret = -ENOMEM;
+		goto err_free_kfifo;
+	}
 
  	svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0);
  	if (!svc->stratix10_svc_rsu) {
  		dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_free_kfifo;
  	}
 
  	ret = platform_device_add(svc->stratix10_svc_rsu);
-	if (ret) {
-		platform_device_put(svc->stratix10_svc_rsu);
-		return ret;
-	}
+	if (ret)
+		goto put_platform;
+
  	dev_set_drvdata(dev, svc);
 
  	pr_info("Intel Service Layer Driver Initialized\n");
 
+	return 0;

drivers/firmware/stratix10-svc.c static int stratix10_svc_drv_probe(struct platform_device *pdev) · line 1076

Quoted 10 lines
drivers/firmware/stratix10-svc.c +7 -0
+
+put_platform:
+	platform_device_put(svc->stratix10_svc_rsu);
+err_free_kfifo:
+	kfifo_free(&controller->svc_fifo);
+err_destroy_pool:
+	gen_pool_destroy(genpool);
  	return ret;
  }
 

Regards,
Richard

#7 lore raw

Re: [PATCH 3/4 v2] firmware: stratix10-svc: Fix some error handling paths in 'stratix10_svc_drv_probe()'

Le 05/05/2020 à 16:02, Richard Gong a écrit :

Quoted 27 lines

Hi,

Similarly we need add error handling for controller and chans, something like below:

(quoted diff) +4 -2
@@ -997,13 +997,17 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
 
         /* allocate service controller and supporting channel */
         controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
-       if (!controller)
-               return -ENOMEM;
+       if (!controller) {
+               ret = -ENOMEM;
+               goto err_destroy_pool;
+       }
 
         chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,

                                   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
-       if (!chans)
-               return -ENOMEM;
+       if (!chans) {
+               ret = -ENOMEM;
+               goto err_destroy_pool;
+       }

Quoted 3 lines

        controller->dev = dev;
        controller->num_chans = SVC_NUM_CHANNEL;

Hi,

This is addressed in patch 1/4.
It moves 'svc_create_memory_pool' after these 2 allocations in order to avoid the goto.

I'll send a V3 in only 1 patch, as you proposed, it will ease review.

CJ

Quoted 82 lines · Christophe JAILLET
Quoted 14 lines

If an error occurs after calling 'svc_create_memory_pool()', the allocated
genpool should be destroyed with 'gen_pool_destroy()', as already done in
the remove function.

If an error occurs after calling 'kfifo_alloc()', the allocated memory should be freed with 'kfifo_free()', as already done in the remove function.

While at it, also move a 'platform_device_put()' call to the error handling
path.

Quoted 9 lines
Fixes b5dc75c915cd ("firmware: stratix10-svc: extend svc to support

new RSU features")

Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer

driver")

---
  drivers/firmware/stratix10-svc.c | 26 ++++++++++++++++++--------

  1 file changed, 18 insertions(+), 8 deletions(-)

I am fine with below changes.

Quoted 50 lines
drivers/firmware/stratix10-svc.c +1 -1
index de5870f76c5e..739004398877 100644
@@ -1024,7 +1024,7 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
       ret = kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL);
       if (ret) {
           dev_err(dev, "failed to allocate FIFO\n");
-        return ret;
+        goto err_destroy_pool;
       }
       spin_lock_init(&controller->svc_fifo_lock);

  @@ -1043,24 +1043,34 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
        /* add svc client device(s) */
      svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL);
-    if (!svc)
-        return -ENOMEM;
+    if (!svc) {
+        ret = -ENOMEM;
+        goto err_free_kfifo;
+    }
        svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0);
      if (!svc->stratix10_svc_rsu) {
          dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU); -        return -ENOMEM;
+        ret = -ENOMEM;
+        goto err_free_kfifo;
      }
        ret = platform_device_add(svc->stratix10_svc_rsu);
-    if (ret) {
-        platform_device_put(svc->stratix10_svc_rsu);
-        return ret;
-    }
+    if (ret)
+        goto put_platform;
+
      dev_set_drvdata(dev, svc);
        pr_info("Intel Service Layer Driver Initialized\n"); +    return 0;

drivers/firmware/stratix10-svc.c +7 -0
+
+put_platform:
+    platform_device_put(svc->stratix10_svc_rsu);
+err_free_kfifo:
+    kfifo_free(&controller->svc_fifo);
+err_destroy_pool:
+    gen_pool_destroy(genpool);
Quoted 3 lines

      return ret;
  }

Regards,
Richard

#8 lore raw

PATCH v3 1/1 firmware: stratix10-svc: Fix some error handling code

Fix several error handling issues:
- In 'svc_create_memory_pool()' we memremap some memory. This has to be
undone in case of error and if the driver is removed.
The easiest way to do it is to use 'devm_memremap()'.

- 'svc_create_memory_pool()' returns an error pointer on error, not NULL.
In 'stratix10_svc_drv_probe()', fix the corresponding test and return value accordingly.

- Move the genpool allocation after a few devm_kzalloc in order to ease
error handling. (some call to 'gen_pool_destroy()' were missing)

- If an error occurs after calling 'svc_create_memory_pool()', the
allocated genpool should be destroyed with 'gen_pool_destroy()', as already done in the remove function.
Add an error handling path for that

- If an error occurs after calling 'kfifo_alloc()', the allocated
memory should be freed with 'kfifo_free()', as already done in the remove function.
Add an error handling path for that

While at it, do some clean-up:
- Use 'devm_kcalloc()' instead of 'devm_kmalloc_array(... __GFP_ZERO)'

- move a 'platform_device_put()' call to the new error handling path.

- In 'stratix10_svc_drv_remove()', 'ctrl->genpool' can not be NULL, so
axe a useless test in the remove function.

Fixes b5dc75c915cd ("firmware: stratix10-svc: extend svc to support new RSU features")
Fixes 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")

---
v2: takes Dan's comment into account and fix another resource leak.
v3: merge the previous 4 patches in a single one to ease review

---
 drivers/firmware/stratix10-svc.c | 42 +++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 17 deletions(-)
drivers/firmware/stratix10-svc.c +25 -17
index e0db8dbfc9d1..90f7d68a2473 100644
@@ -605,7 +605,7 @@ svc_create_memory_pool(struct platform_device *pdev,
 	end = rounddown(sh_memory->addr + sh_memory->size, PAGE_SIZE);
 	paddr = begin;
 	size = end - begin;
-	va = memremap(paddr, size, MEMREMAP_WC);
+	va = devm_memremap(dev, paddr, size, MEMREMAP_WC);
 	if (!va) {
 		dev_err(dev, "fail to remap shared memory\n");
 		return ERR_PTR(-EINVAL);
@@ -971,20 +971,19 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	genpool = svc_create_memory_pool(pdev, sh_memory);
-	if (!genpool)
-		return -ENOMEM;
-
 	/* allocate service controller and supporting channel */
 	controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
 	if (!controller)
 		return -ENOMEM;
 
-	chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-				   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+	chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), GFP_KERNEL);
 	if (!chans)
 		return -ENOMEM;
 
+	genpool = svc_create_memory_pool(pdev, sh_memory);
+	if (IS_ERR(genpool))
+		return PTR_ERR(genpool);
+
 	controller->dev = dev;
 	controller->num_chans = SVC_NUM_CHANNEL;
 	controller->num_active_client = 0;
@@ -998,7 +997,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	ret = kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL);
 	if (ret) {
 		dev_err(dev, "failed to allocate FIFO\n");
-		return ret;
+		goto err_destroy_pool;
 	}
 	spin_lock_init(&controller->svc_fifo_lock);
 
@@ -1017,24 +1016,34 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 
 	/* add svc client device(s) */
 	svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL);
-	if (!svc)
-		return -ENOMEM;
+	if (!svc) {
+		ret = -ENOMEM;
+		goto err_free_kfifo;
+	}
 
 	svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0);
 	if (!svc->stratix10_svc_rsu) {
 		dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_free_kfifo;
 	}
 
 	ret = platform_device_add(svc->stratix10_svc_rsu);
-	if (ret) {
-		platform_device_put(svc->stratix10_svc_rsu);
-		return ret;
-	}
+	if (ret)
+		goto put_platform;
+
 	dev_set_drvdata(dev, svc);
 
 	pr_info("Intel Service Layer Driver Initialized\n");
 
+	return 0;
+
+put_platform:
+	platform_device_put(svc->stratix10_svc_rsu);
+err_free_kfifo:
+	kfifo_free(&controller->svc_fifo);
+err_destroy_pool:
+	gen_pool_destroy(genpool);
 	return ret;
 }
 
@@ -1050,8 +1059,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)
 		kthread_stop(ctrl->task);
 		ctrl->task = NULL;
 	}
-	if (ctrl->genpool)
-		gen_pool_destroy(ctrl->genpool);
+	gen_pool_destroy(ctrl->genpool);
 	list_del(&ctrl->node);
 
 	return 0;
Signature · 1 line
2.25.1
#9 lore raw
Quoted 1 line · Christophe JAILLET

Fix several error handling issues:

<snip>

When you have to list a bunch of different things you do in a driver, that's a huge hint this needs to be broken up into multiple patches.

Please do that here.

thanks,

greg k-h

#10 lore raw
In reply to Christophe JAILLET
Quoted 3 lines · Christophe JAILLET

---
v2: takes Dan's comment into account and fix another resource leak.
v3: merge the previous 4 patches in a single one to ease review

No, 4 small patches are _MUCH_ easier to review than one larger one that mixes everything together. Who told you to put them together?

#11 lore raw

Le 27/06/2020 à 07:15, Greg KH a écrit :

Quoted 7 lines · Christophe JAILLET
Quoted 3 lines

---
v2: takes Dan's comment into account and fix another resource leak.
v3: merge the previous 4 patches in a single one to ease review

No, 4 small patches are _MUCH_ easier to review than one larger one that mixes everything together. Who told you to put them together?

The cover letter of v2 serie can be found at [1]. The request for merging them in 1 patch is in [2].

V3, should be the same as v2, but all in one.

[1]: https://lkml.org/lkml/2020/4/29/77
[2]: https://lkml.org/lkml/2020/5/5/541

CJ

#12 lore raw
Quoted 10 lines · Marion & Christophe JAILLET

Le 27/06/2020 à 07:15, Greg KH a écrit :

Quoted 7 lines · Christophe JAILLET
Quoted 3 lines

---
v2: takes Dan's comment into account and fix another resource leak.
v3: merge the previous 4 patches in a single one to ease review

No, 4 small patches are _MUCH_ easier to review than one larger one that mixes everything together. Who told you to put them together?

Quoted 7 lines

The cover letter of v2 serie can be found at [1]. The request for merging them in 1 patch is in [2].

V3, should be the same as v2, but all in one.

[1]: https://lkml.org/lkml/2020/4/29/77
[2]: https://lkml.org/lkml/2020/5/5/541

Please use lore.kernel.org in the future, we don't control lkml.org and can't rely on it.

Anyway, that request was incorrect, sorry. Please keep them split up in a way that makes it easy to review.

Which would you want to read if you had to review hundreds of patches?

thanks,

greg k-h

#13 lore raw

PATCH v2 4/4 firmware: stratix10-svc: Slightly simplify code

In reply to Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
 drivers/firmware/stratix10-svc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +2 -4
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
 	if (!controller)
 		return -ENOMEM;
 
-	chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-				   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+	chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), GFP_KERNEL);
 	if (!chans)
 		return -ENOMEM;
 
@@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)
 		kthread_stop(ctrl->task);
 		ctrl->task = NULL;
 	}
-	if (ctrl->genpool)
-		gen_pool_destroy(ctrl->genpool);
+	gen_pool_destroy(ctrl->genpool);
 	list_del(&ctrl->node);
 
 	return 0;
Signature · 1 line
2.25.1
#14 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

Quoted 24 lines

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
  drivers/firmware/stratix10-svc.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +1 -2
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
  	if (!controller)
  		return -ENOMEM;
 
-	chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-				   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+	chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), GFP_KERNEL);
  	if (!chans)
  		return -ENOMEM;
 

drivers/firmware/stratix10-svc.c static int stratix10_svc_drv_remove(struct platform_device *pdev) · line 1091

Quoted 9 lines
drivers/firmware/stratix10-svc.c +1 -2
@@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)
  		kthread_stop(ctrl->task);
  		ctrl->task = NULL;
  	}
-	if (ctrl->genpool)
-		gen_pool_destroy(ctrl->genpool);
+	gen_pool_destroy(ctrl->genpool);
  	list_del(&ctrl->node);
 
  	return 0;

Regards,
Richard

#15 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

Le 01/05/2020 à 17:40, Richard Gong a écrit :

Quoted 9 lines

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

The only goal is to have a sightly less verbose code. This saves one line of code and there is no need to wonder why we explicitly pass __GFP_ZERO to kmalloc_array.

Mostly a matter of taste.

'devm_kcalloc' is inlined, so the binary should be exactly the same.

CJ

Quoted 38 lines
Quoted 25 lines

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
  drivers/firmware/stratix10-svc.c | 6 ++----

  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +1 -1
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
       if (!controller)
           return -ENOMEM;
   -    chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-                   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+    chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), 
 GFP_KERNEL);
       if (!chans)

          return -ENOMEM;
  @@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)

Quoted 9 lines

          kthread_stop(ctrl->task);
          ctrl->task = NULL;
      }
-    if (ctrl->genpool)
-        gen_pool_destroy(ctrl->genpool);
+    gen_pool_destroy(ctrl->genpool);
      list_del(&ctrl->node);
        return 0;

Regards,
Richard

#16 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

Hi,

Quoted 7 lines · Christophe JAILLET

Le 01/05/2020 à 17:40, Richard Gong a écrit :

Quoted 6 lines

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

Quoted 7 lines
Quoted 3 lines

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

The only goal is to have a sightly less verbose code.
This saves one line of code and there is no need to wonder why we explicitly pass __GFP_ZERO to kmalloc_array.

Mostly a matter of taste.

I prefer this part remain unchanged.

Regards,
Richard

Quoted 41 lines

'devm_kcalloc' is inlined, so the binary should be exactly the same. > CJ

Quoted 36 lines
Quoted 23 lines

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
  drivers/firmware/stratix10-svc.c | 6 ++----

  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +1 -1
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
       if (!controller)
           return -ENOMEM;
   -    chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-                   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+    chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), 
 GFP_KERNEL);
       if (!chans)

          return -ENOMEM;
  @@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)

Quoted 9 lines

          kthread_stop(ctrl->task);
          ctrl->task = NULL;
      }
-    if (ctrl->genpool)
-        gen_pool_destroy(ctrl->genpool);
+    gen_pool_destroy(ctrl->genpool);
      list_del(&ctrl->node);
        return 0;

Regards,
Richard

#17 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

Le 01/05/2020 à 18:55, Richard Gong a écrit :

Quoted 14 lines

Hi,

Quoted 11 lines · Christophe JAILLET

Le 01/05/2020 à 17:40, Richard Gong a écrit :

Quoted 10 lines

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

Quoted 7 lines
Quoted 5 lines

The only goal is to have a sightly less verbose code. This saves one line of code and there is no need to wonder why we explicitly pass __GFP_ZERO to kmalloc_array.

Mostly a matter of taste.

I prefer this part remain unchanged.

The easiest would be just to ignore this patch entirely but if you need a v3 for the series, could you tell me if you have any comments on the 3 other patches?

CJ

Quoted 47 lines

Regards,
Richard

Quoted 43 lines

'devm_kcalloc' is inlined, so the binary should be exactly the same. > CJ

Quoted 38 lines
Quoted 25 lines

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
  drivers/firmware/stratix10-svc.c | 6 ++----

  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +1 -1
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
       if (!controller)
           return -ENOMEM;
   -    chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-                   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+    chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), 
 GFP_KERNEL);
       if (!chans)

          return -ENOMEM;
  @@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)

Quoted 9 lines

          kthread_stop(ctrl->task);
          ctrl->task = NULL;
      }
-    if (ctrl->genpool)
-        gen_pool_destroy(ctrl->genpool);
+    gen_pool_destroy(ctrl->genpool);
      list_del(&ctrl->node);
        return 0;

Regards,
Richard

#18 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

Hi,

Quoted 14 lines · Christophe JAILLET

Le 01/05/2020 à 18:55, Richard Gong a écrit :

Quoted 13 lines

Hi,

Quoted 10 lines · Christophe JAILLET

Le 01/05/2020 à 17:40, Richard Gong a écrit :

Quoted 9 lines

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The only goal is to have a sightly less verbose code.
This saves one line of code and there is no need to wonder why we explicitly pass __GFP_ZERO to kmalloc_array.

Mostly a matter of taste.

I prefer this part remain unchanged.

The easiest would be just to ignore this patch entirely

Yes, please.
but if you need

Quoted 2 lines

a v3 for the series, could you tell me if you have any comments on the 3 other patches?

I added some comments in your patch #3, also recommend putting all changes in one patch.

Regards,
Richard

Quoted 49 lines

CJ

Quoted 45 lines

Regards,
Richard

Quoted 41 lines

'devm_kcalloc' is inlined, so the binary should be exactly the same. > CJ

Quoted 36 lines
Quoted 23 lines

'ctrl->genpool' can not be NULL, so axe a useless test in the remove function.

---
  drivers/firmware/stratix10-svc.c | 6 ++----

  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/firmware/stratix10-svc.c +1 -1
index 739004398877..c228337cb0a1 100644
@@ -1002,8 +1002,7 @@ static int stratix10_svc_drv_probe(struct 
 platform_device *pdev)
       if (!controller)
           return -ENOMEM;
   -    chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
-                   sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
+    chans = devm_kcalloc(dev, SVC_NUM_CHANNEL, sizeof(*chans), 
 GFP_KERNEL);
       if (!chans)

          return -ENOMEM;
  @@ -1086,8 +1085,7 @@ static int stratix10_svc_drv_remove(struct platform_device *pdev)

Quoted 9 lines

          kthread_stop(ctrl->task);
          ctrl->task = NULL;
      }
-    if (ctrl->genpool)
-        gen_pool_destroy(ctrl->genpool);
+    gen_pool_destroy(ctrl->genpool);
      list_del(&ctrl->node);
        return 0;

Regards,
Richard

#19 lore raw

Re: [PATCH 4/4 v2] firmware: stratix10-svc: Slightly simplify code

In reply to Richard Gong
Quoted 9 lines · Richard Gong

Hi,

Quoted 3 lines · Christophe JAILLET

Replace 'devm_kmalloc_array(... | __GFP_ZERO)' with the equivalent and shorter 'devm_kcalloc(...)'.

It doesn't make much sense.
Actually devm_kcalloc returns devm_kmalloc_array(.., flag | __GFP_ZERO).

devm_kcalloc() is better style and easier to read. I was just reading a bunch of AMD code that does this and I almost complained to them that devm_kmalloc_array() doesn't zero the memory so they were freeing uninitialized pointers.

regards,
dan carpenter