Source code review around jump label usage
Subsystems (101)
PATCH 4/14 GPU-DRM-OMAP: Delete an unnecessary variable initialisation in tiler_map_show()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 13:31:45 +0200
The local variable "map" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +1 -1
@@ -896,7 +896,7 @@ static void map_2d_info(char **map, int xdiv, int ydiv, char *nice,int tiler_map_show (struct seq_file *s,void *arg) {int xdiv =2 , ydiv =1 ; -char **map =NULL , *global_map; +char **map, *global_map;struct tiler_block *block;struct tcm_area a, p;int i;
Signature · 1 line
2.10.0
PATCH 5/14 GPU-DRM-OMAP: Improve a size determination in dmm_txn_append()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 13:53:11 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +1 -1
@@ -224,7 +224,7 @@ static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area,int rows = (1 + area->y1 - area->y0);int i = columns*rows; - pat =alloc_dma (txn,sizeof (struct pat ), &pat_pa); + pat =alloc_dma (txn,sizeof (*pat), &pat_pa);if (txn->last_pat) txn->last_pat->next_pa = (uint32_t )pat_pa;
Signature · 1 line
2.10.0
PATCH 6/14 GPU-DRM-OMAP: Improve a size determination in omap_dmm_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:21:57 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +2 -1
@@ -735,7 +735,8 @@ static int omap_dmm_probe(struct platform_device *dev)/* alloc engines */ omap_dmm->engines =kcalloc (omap_dmm->num_engines, -sizeof (struct refill_engine ),GFP_KERNEL ); +sizeof (*omap_dmm->engines), +GFP_KERNEL );if (!omap_dmm->engines) { ret = -ENOMEM ; goto fail;
Signature · 1 line
2.10.0
PATCH 7/14 GPU-DRM-OMAP: Rename a jump label in omap_dmm_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:30:25 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +12 -13
@@ -624,7 +624,7 @@ static int omap_dmm_probe(struct platform_device *dev) omap_dmm =kzalloc (sizeof (*omap_dmm),GFP_KERNEL );if (!omap_dmm) - goto fail; + goto check_dmm_removal;/* initialize lists */ INIT_LIST_HEAD (&omap_dmm->alloc_head);
@@ -648,20 +648,20 @@ static int omap_dmm_probe(struct platform_device *dev) mem =platform_get_resource (dev,IORESOURCE_MEM ,0 );if (!mem) {dev_err (&dev->dev,"failed to get base address resource\n" ); - goto fail; + goto check_dmm_removal; } omap_dmm->base =ioremap (mem->start,SZ_2K );if (!omap_dmm->base) {dev_err (&dev->dev,"failed to get dmm base address\n" ); - goto fail; + goto check_dmm_removal; } omap_dmm->irq =platform_get_irq (dev,0 );if (omap_dmm->irq <0 ) {dev_err (&dev->dev,"failed to get IRQ resource\n" ); - goto fail; + goto check_dmm_removal; } omap_dmm->dev = &dev->dev;
@@ -699,7 +699,7 @@ static int omap_dmm_probe(struct platform_device *dev)dev_err (&dev->dev,"couldn't register IRQ %d, error %d\n" , omap_dmm->irq, ret); omap_dmm->irq =-1 ; - goto fail; + goto check_dmm_removal; }/* Enable all interrupts for each refill engine except
@@ -714,13 +714,13 @@ static int omap_dmm_probe(struct platform_device *dev)if (!omap_dmm->dummy_page) {dev_err (&dev->dev,"could not allocate dummy page\n" ); ret = -ENOMEM ; - goto fail; + goto check_dmm_removal; }/* set dma mask for device */ ret =dma_set_coherent_mask (&dev->dev,DMA_BIT_MASK (32 ));if (ret) - goto fail; + goto check_dmm_removal; omap_dmm->dummy_pa =page_to_phys (omap_dmm->dummy_page);
@@ -730,7 +730,7 @@ static int omap_dmm_probe(struct platform_device *dev) &omap_dmm->refill_pa, GFP_KERNEL);if (!omap_dmm->refill_va) {dev_err (&dev->dev,"could not allocate refill memory\n" ); - goto fail; + goto check_dmm_removal; }/* alloc engines */
@@ -739,7 +739,7 @@ static int omap_dmm_probe(struct platform_device *dev) GFP_KERNEL);if (!omap_dmm->engines) { ret = -ENOMEM ; - goto fail; + goto check_dmm_removal; }for (i =0 ; i < omap_dmm->num_engines; i++) {
@@ -758,7 +758,7 @@ static int omap_dmm_probe(struct platform_device *dev) GFP_KERNEL);if (!omap_dmm->tcm) { ret = -ENOMEM ; - goto fail; + goto check_dmm_removal; }/* init containers */
@@ -772,7 +772,7 @@ static int omap_dmm_probe(struct platform_device *dev)if (!omap_dmm->tcm[i]) {dev_err (&dev->dev,"failed to allocate container\n" ); ret = -ENOMEM ; - goto fail; + goto check_dmm_removal; } omap_dmm->tcm[i]->lut_id = i;
@@ -812,8 +812,7 @@ static int omap_dmm_probe(struct platform_device *dev)dev_info (omap_dmm->dev,"initialized all PAT entries\n" );return 0 ; - -fail: + check_dmm_removal:if (omap_dmm_remove (dev))dev_err (&dev->dev,"cleanup failed\n" );return ret;
Signature · 1 line
2.10.0
PATCH 8/14 GPU-DRM-OMAP: Rename a jump label in dmm_txn_commit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:32:42 +0200
Adjust a jump target so that redundant checks can be avoided at the end.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +3 -3
@@ -269,7 +269,7 @@ static int dmm_txn_commit(struct dmm_txn *txn, bool wait)if (!txn->last_pat) {dev_err (engine->dmm->dev,"need at least one txn\n" ); ret = -EINVAL ; - goto cleanup; + goto release_engine; } txn->last_pat->next_pa =0 ;
@@ -281,7 +281,7 @@ static int dmm_txn_commit(struct dmm_txn *txn, bool wait) ret =wait_status (engine,DMM_PATSTATUS_READY );if (ret) { ret = -EFAULT ; - goto cleanup; + goto release_engine; }/* mark whether it is async to denote list management in IRQ handler */
@@ -301,9 +301,9 @@ static int dmm_txn_commit(struct dmm_txn *txn, bool wait) } } -cleanup:/* only place engine back on list if we are done with it */ if (ret || wait) + release_engine:release_engine (engine);return ret;
Signature · 1 line
2.10.0
PATCH 9/14 GPU-DRM-OMAP: Delete an unnecessary variable initialisation in dmm_txn_commit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:34:40 +0200
The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +1 -1
@@ -262,7 +262,7 @@ static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area,*/ static int dmm_txn_commit (struct dmm_txn *txn,bool wait) { -int ret =0 ; +int ret;struct refill_engine *engine = txn->engine_handle;struct dmm *dmm = engine->dmm;
Signature · 1 line
2.10.0
PATCH 10/14 GPU-DRM-OMAP: Use kmalloc_array() in omap_gem_attach_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:37:04 +0200
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -259,7 +259,7 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)* DSS, GPU, etc. are not cache coherent: */ if (omap_obj->flags & (OMAP_BO_WC |OMAP_BO_UNCACHED )) { - addrs =kmalloc (npages *sizeof (*addrs),GFP_KERNEL ); + addrs =kmalloc_array (npages,sizeof (*addrs),GFP_KERNEL );if (!addrs) { ret = -ENOMEM ; goto free_pages;
Signature · 1 line
2.10.0
PATCH 11/14 GPU-DRM-OMAP: Replace a kzalloc() call by kcalloc() in omap_gem_attach_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:40:20 +0200
The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer kcalloc over kzalloc with multiply
Thus fix the affected source code place.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -283,7 +283,7 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj) } } }else { - addrs =kzalloc (npages *sizeof (*addrs),GFP_KERNEL ); + addrs =kcalloc (npages,sizeof (*addrs),GFP_KERNEL );if (!addrs) { ret = -ENOMEM ; goto free_pages;
Signature · 1 line
2.10.0
PATCH 12/14 GPU-DRM-OMAP: Move a variable assignment in omap_gem_attach_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:42:28 +0200
Move one assignment for the local variable "npages" so that its setting will only be performed after a call of the function "drm_gem_get_pages" succeeded by this function.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_gem.c +3 -1
@@ -243,7 +243,7 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)struct drm_device *dev = obj->dev;struct omap_gem_object *omap_obj =to_omap_bo (obj);struct page **pages; -int npages = obj->size >>PAGE_SHIFT ; +int npages;int i, ret;dma_addr_t *addrs;
@@ -255,6 +255,8 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)return PTR_ERR (pages); } + npages = obj->size >>PAGE_SHIFT ; +/* for non-cached buffers, ensure the new pages are clean because * DSS, GPU, etc. are not cache coherent: */
Signature · 1 line
2.10.0
PATCH 13/14 GPU-DRM-OMAP: Rename a jump label in omap_gem_new_dmabuf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 17:45:04 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +4 -5
@@ -1442,7 +1442,7 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size, obj =omap_gem_new (dev, gsize,OMAP_BO_MEM_DMABUF |OMAP_BO_WC );if (!obj) { obj =ERR_PTR (-ENOMEM ); - goto done; + goto unlock; } omap_obj =to_omap_bo (obj);
@@ -1462,7 +1462,7 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,if (!pages) {omap_gem_free_object (obj); obj =ERR_PTR (-ENOMEM ); - goto done; + goto unlock; } omap_obj->pages = pages;
@@ -1476,11 +1476,10 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,if (WARN_ON (i != npages)) {omap_gem_free_object (obj); obj =ERR_PTR (-ENOMEM ); - goto done; + goto unlock; } } - -done: + unlock:mutex_unlock (&dev->struct_mutex);return obj; }
Signature · 1 line
2.10.0
PATCH 14/14 GPU-DRM-OMAP: Rename a jump label in four functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 18:00:23 +0200
Adjust jump labels according to the current Linux coding style convention. Thus replace the identifier "fail" by "unlock" for this refactoring.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +11 -16
@@ -549,7 +549,7 @@ int omap_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)/* if a shmem backed object, make sure we have pages attached now */ ret =get_pages (obj, &pages);if (ret) - goto fail; + goto unlock;/* where should we do corresponding put_pages().. we are mapping * the original page, rather than thru a GART, so we can't rely
@@ -561,9 +561,7 @@ int omap_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ret =fault_2d (obj, vma, vmf); else ret =fault_1d (obj, vma, vmf); - - -fail: + unlock:mutex_unlock (&dev->struct_mutex);switch (ret) {case 0 :
@@ -682,14 +680,13 @@ int omap_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, obj =drm_gem_object_lookup (file, handle);if (obj ==NULL ) { ret = -ENOENT ; - goto fail; + goto unlock; } *offset =omap_gem_mmap_offset (obj);drm_gem_object_unreference_unlocked (obj); - -fail: + unlock:return ret; }
@@ -719,13 +716,12 @@ int omap_gem_roll(struct drm_gem_object *obj, uint32_t roll)struct page **pages; ret =get_pages (obj, &pages);if (ret) - goto fail; + goto unlock; ret =tiler_pin (omap_obj->block, pages, npages, roll, true);if (ret)dev_err (obj->dev->dev,"could not repin: %d\n" , ret); } - -fail: + unlock:mutex_unlock (&obj->dev->struct_mutex);return ret;
@@ -825,7 +821,7 @@ int omap_gem_get_paddr(struct drm_gem_object *obj, ret =get_pages (obj, &pages);if (ret) - goto fail; + goto unlock;if (omap_obj->flags &OMAP_BO_TILED ) { block = tiler_reserve_2d(fmt,
@@ -839,7 +835,7 @@ int omap_gem_get_paddr(struct drm_gem_object *obj, ret =PTR_ERR (block);dev_err (obj->dev->dev,"could not remap: %d (%d)\n" , ret, fmt); - goto fail; + goto unlock; }/* TODO: enable async refill.. */
@@ -849,7 +845,7 @@ int omap_gem_get_paddr(struct drm_gem_object *obj,tiler_release (block);dev_err (obj->dev->dev,"could not pin: %d\n" , ret); - goto fail; + goto unlock; } omap_obj->paddr =tiler_ssptr (block);
@@ -865,10 +861,9 @@ int omap_gem_get_paddr(struct drm_gem_object *obj, *paddr = omap_obj->paddr; }else { ret = -EINVAL ; - goto fail; + goto unlock; } - -fail: + unlock:mutex_unlock (&obj->dev->struct_mutex);return ret;
Signature · 1 line
2.10.0
Re: [PATCH 00/14] GPU-DRM-OMAP: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 18:28:38 +0200Several update suggestions were taken into account from static source code analysis.
For the next pile of driver patches _please_ talk with driver maintainers before starting to create&submit patches. Like I said I won't take them, and many of your changes are not clear-cut at all, so I expect many driver maintaines also won't take them. Again, your contributions are welcome, but blindly following suggestions from code checkers in drivers you cant test isn't really all that useful. At the scale you're doing it, I think it's mostly wasting everyone's time :( I'd like to avoid that.
Thanks, Daniel
Quoted 28 lines
Markus Elfring (14):
Usekmalloc_array()intiler_map_show()
Replace anotherkmalloc()call bykmalloc_array()intiler_map_show()Less function calls intiler_map_show()after error detection Delete an unnecessary variable initialisation intiler_map_show()Improve a size determination indmm_txn_append()
Improve a size determination inomap_dmm_probe()
Rename a jump label inomap_dmm_probe()
Rename a jump label indmm_txn_commit()
Delete an unnecessary variable initialisation indmm_txn_commit()Usekmalloc_array()inomap_gem_attach_pages()
Replace akzalloc()call bykcalloc()inomap_gem_attach_pages()Move a variable assignment inomap_gem_attach_pages()Rename a jump label inomap_gem_new_dmabuf()
Rename a jump label in four functionsdrivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 58 ++++++++++++++++---------------- drivers/gpu/drm/omapdrm/omap_gem.c | 44 +++++++++++------------- 2 files changed, 49 insertions(+), 53 deletions(-)Signature · 6 lines
2.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Laurent Pinchart
maintainerRe: [PATCH 00/14] GPU-DRM-OMAP: Fine-tuning for several function implementations
Quoted 7 lines · On Thursday 22 Sep 2016 08:45:01 Daniel Vetter wrote:
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 21 Sep 2016 18:28:38 +0200Several update suggestions were taken into account from static source code analysis.
Quoted 7 lines
For the next pile of driver patches _please_ talk with driver maintainers before starting to create&submit patches. Like I said I won't take them, and many of your changes are not clear-cut at all, so I expect many driver maintaines also won't take them. Again, your contributions are welcome, but blindly following suggestions from code checkers in drivers you cant test isn't really all that useful. At the scale you're doing it, I think it's mostly wasting everyone's time :( I'd like to avoid that.
I second that. After a very quick review, I see that the series splits related changes in multiple patches. I've already commented in reply to another series submitted by Markus that patches should then be combined. I will thus ignore this series completely for the time being.
Quoted 19 lines
Quoted 19 lines
Markus Elfring (14):
Usekmalloc_array()intiler_map_show()
Replace anotherkmalloc()call bykmalloc_array()intiler_map_show()Less function calls intiler_map_show()after error detection Delete an unnecessary variable initialisation intiler_map_show()Improve a size determination indmm_txn_append()
Improve a size determination inomap_dmm_probe()
Rename a jump label inomap_dmm_probe()
Rename a jump label indmm_txn_commit()
Delete an unnecessary variable initialisation indmm_txn_commit()Usekmalloc_array()inomap_gem_attach_pages()
Replace akzalloc()call bykcalloc()inomap_gem_attach_pages()Move a variable assignment inomap_gem_attach_pages()Rename a jump label inomap_gem_new_dmabuf()
Rename a jump label in four functionsdrivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 58 +++++++++++++-------------- drivers/gpu/drm/omapdrm/omap_gem.c | 44 +++++++++++------------- 2 files changed, 49 insertions(+), 53 deletions(-)
Signature · 3 lines
Regards, Laurent Pinchart
cover GPU-DRM-TILCDC: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 10:25:43 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Use kmalloc_array()
Return directly after a failed kfree_table_init() in tilcdc_convert_slave_node() Less function calls in tilcdc_convert_slave_node() after error detection Delete unnecessary variable initialisations
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/4 GPU-DRM-TILCDC: Use kmalloc_array() in kfree_table_init()
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 09:05:14 +0200
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +1 -2
@@ -32,8 +32,7 @@ static int __init kfree_table_init(struct kfree_table *kft) { kft->total =32 ; kft->num =0 ; - kft->table =kmalloc (kft->total *sizeof (*kft->table), -GFP_KERNEL ); + kft->table =kmalloc_array (kft->total,sizeof (*kft->table),GFP_KERNEL );if (!kft->table)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/4 GPU-DRM-TILCDC: Return directly after a failed kfree_table_init() in tilcdc_convert_slave_node()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 09:29:23 +0200
Return directly after a memory allocation failed in this function at the beginning.
--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +1 -1
@@ -206,7 +206,7 @@ void __init tilcdc_convert_slave_node(void)int ret;if (kfree_table_init (&kft)) - goto out; +return ; lcdc =of_find_matching_node (NULL , tilcdc_of_match); slave =of_find_matching_node (NULL , tilcdc_slave_of_match);
Signature · 1 line
2.10.0
PATCH 3/4 GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 10:06:50 +0200
The of_node_put() function was called in some cases
by the tilcdc_convert_slave_node() function during error handling even if the passed variable contained a null pointer.
* Adjust jump targets according to the Linux coding style convention.
* Split a condition check for resource detection failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +17 -11
@@ -209,25 +209,27 @@ void __init tilcdc_convert_slave_node(void)return ; lcdc =of_find_matching_node (NULL , tilcdc_of_match); - slave =of_find_matching_node (NULL , tilcdc_slave_of_match); +if (!of_device_is_available (lcdc)) + goto free_table; -if (!slave || !of_device_is_available (lcdc)) - goto out; + slave =of_find_matching_node (NULL , tilcdc_slave_of_match); +if (!slave) + goto put_node_lcdc; i2c =of_parse_phandle (slave,"i2c" ,0 );if (!i2c) {pr_err ("%s: Can't find i2c node trough phandle\n" , __func__); - goto out; + goto put_node_slave; } overlay =tilcdc_get_overlay (&kft);if (!overlay) - goto out; + goto put_node_i2c; encoder =of_find_matching_node (overlay, tilcdc_tda998x_of_match);if (!encoder) {pr_err ("%s: Failed to find tda998x node\n" , __func__); - goto out; + goto put_node_i2c; }tilcdc_copy_props (slave, encoder, tilcdc_slave_props, &kft);
@@ -238,10 +240,10 @@ void __init tilcdc_convert_slave_node(void)continue ;if (!strncmp ("i2c" , (char *)prop->value, prop->length))if (tilcdc_prop_str_update (prop, i2c->full_name, &kft)) - goto out; + goto put_node_fragment;if (!strncmp ("lcdc" , (char *)prop->value, prop->length))if (tilcdc_prop_str_update (prop, lcdc->full_name, &kft)) - goto out; + goto put_node_fragment; }tilcdc_node_disable (slave);
@@ -252,12 +254,16 @@ void __init tilcdc_convert_slave_node(void)else pr_info ("%s: ti,tilcdc,slave node successfully converted\n" , __func__); -out: -kfree_table_free (&kft); + put_node_fragment: +of_node_put (fragment); + put_node_i2c:of_node_put (i2c); + put_node_slave:of_node_put (slave); + put_node_lcdc:of_node_put (lcdc); -of_node_put (fragment); + free_table: +kfree_table_free (&kft); }int __init tilcdc_slave_compat_init (void )
Signature · 1 line
2.10.0
PATCH 4/4 GPU-DRM-TILCDC: Delete unnecessary variable initialisations in tilcdc_convert_slave_node()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 10:15:36 +0200
Four local variables will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation which became unnecessary with a previous update step.
--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +1 -2
@@ -196,8 +196,7 @@ static const char * const tilcdc_slave_props[] __initconst = {void __init tilcdc_convert_slave_node (void ) { -struct device_node *slave =NULL , *lcdc =NULL ; -struct device_node *i2c =NULL , *fragment =NULL ; +struct device_node *slave, *lcdc, *i2c, *fragment;struct device_node *overlay, *encoder;struct property *prop;/* For all memory needed for the overlay tree. This memory can
Signature · 1 line
2.10.0
Re: GPU-DRM-OMAP: Fine-tuning for several function implementations
In reply to Laurent PinchartQuoted 2 lines
Quoted 2 lines
For the next pile of driver patches _please_ talk with driver maintainers before starting to create&submit patches.
Did the software development discussion start a bit here?
Would you like to support an other "talking style" on a conference like in Berlin next month?
Quoted 1 line
Quoted 1 line
Like I said I won't take them,
It's a pity.
Quoted 1 line
Quoted 1 line
and many of your changes are not clear-cut at all,
I know that specific update suggestions could be interpreted as controversial.
Quoted 1 line
Quoted 1 line
so I expect many driver maintaines also won't take them.
I am curious on useful responses.
Quoted 1 line
Quoted 1 line
Again, your contributions are welcome,
Thanks for another bit of constructive feedback.
Quoted 1 line
Quoted 1 line
but blindly following suggestions from code checkers in drivers
I propose to dare another look at corresponding information sources.
Quoted 1 line
Quoted 1 line
you cant test isn't really all that useful.
I have got an other impression.
How many improvements can still be achieved by usual (advanced) collaboration techniques for free software development?
Quoted 1 line
Quoted 1 line
At the scale you're doing it, I think it's mostly wasting everyone's time
I hope not.
Quoted 1 line
:( I'd like to avoid that.
I am going to point more update opportunities out also for various Linux software.
Quoted 1 line
I second that.
Thanks for your opinion on this issue.
Quoted 2 lines
After a very quick review, I see that the series splits related changes in multiple patches.
I chose a specific patch granularity for this proposal.
Quoted 2 lines
I've already commented in reply to another series submitted by Markus that patches should then be combined.
Will such a combination depend on any more agreements between the involved contributors?
Quoted 1 line
I will thus ignore this series completely for the time being.
I hope that you can give similar ideas a second chance somehow.
Regards,
Markus
Herbert Xu
maintainerRe: crypto-caamhash: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 14 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 16:27:23 +0200Some update suggestions were taken into account
from static source code analysis.Markus Elfring (6):
Usekmalloc_array()inahash_setkey()
Rename jump labels inahash_setkey()
Rename a jump label in five functions
Return a value directly incaam_hash_cra_init()Delete an unnecessary initialisation in seven functions Move common error handling code in two functions
Quoted 2 lines
drivers/crypto/caam/caamhash.c | 111 +++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 59 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH 2/4] GPU-DRM-TILCDC: Return directly after a failed kfree_table_init() in tilcdc_convert_slave_node()
In reply to SF Markus ElfringThis one is actually a bug fix... But finding bug fixes in this series is like looking for kernels of edible corn in piles of monkey poop.
Also, classic "One Err" bug.
regards,
dan carpenter
Re: [PATCH 1/4] GPU-DRM-TILCDC: Use kmalloc_array() in kfree_table_init()
In reply to SF Markus ElfringQuoted 19 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 09:05:14 +0200A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +0
-0
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c static int __init kfree_table_init(struct kfree_table *kft) · line 35
Quoted 6 lines
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +1
-2@@ -32,8 +32,7 @@ static int __init kfree_table_init(struct kfree_table *kft) { kft->total =32 ; kft->num =0 ; - kft->table =kmalloc (kft->total *sizeof (*kft->table), -GFP_KERNEL ); + kft->table =kmalloc_array (kft->total,sizeof (*kft->table),GFP_KERNEL );
I was not sure if it is Ok to call kremalloc() for a pointer that was previously allocated with kmalloc_array(). And at least it felt pointless.
But if you can confirm that it is ok, then sure I can take the patch.
Thanks,
Jyri
Quoted 4 lines
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +0
-0if (!kft->table)return -ENOMEM ;
Re: [PATCH 2/4] GPU-DRM-TILCDC: Return directly after a failed kfree_table_init() in tilcdc_convert_slave_node()
In reply to SF Markus ElfringQuoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 09:29:23 +0200Return directly after a memory allocation failed in this function at the beginning.
Signed-off-by Markus Elfring <[email protected]>--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +0
-0
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c void __init tilcdc_convert_slave_node(void) · line 212
Quoted 8 lines
drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +1
-1@@ -206,7 +206,7 @@ void __init tilcdc_convert_slave_node(void)int ret;if (kfree_table_init (&kft)) - goto out; +return ; lcdc =of_find_matching_node (NULL , tilcdc_of_match); slave =of_find_matching_node (NULL , tilcdc_slave_of_match);
Thanks,
This is a real bug. I'll pick this up, but with your permission I change the commit subject to follow the current convention.
Best regards,
Jyri
Re: [PATCH 3/4] GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 10:06:50 +0200The
of_node_put()function was called in some cases
by thetilcdc_convert_slave_node()function during error handling even if the passed variable contained a null pointer.
Quoted 9 lines
* Adjust jump targets according to the Linux coding style convention.
* Split a condition check for resource detection failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
I don't really agree with this patch. There is no harm in calling of_node_put() with NULL as an argument and because of that there is no point in making the function more complex and harder to maintain.
Best regards,
Jyri
Quoted 77 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +17
-11@@ -209,25 +209,27 @@ void __init tilcdc_convert_slave_node(void)return ; lcdc =of_find_matching_node (NULL , tilcdc_of_match); - slave =of_find_matching_node (NULL , tilcdc_slave_of_match); +if (!of_device_is_available (lcdc)) + goto free_table; -if (!slave || !of_device_is_available (lcdc)) - goto out; + slave =of_find_matching_node (NULL , tilcdc_slave_of_match); +if (!slave) + goto put_node_lcdc; i2c =of_parse_phandle (slave,"i2c" ,0 );if (!i2c) {pr_err ("%s: Can't find i2c node trough phandle\n" , __func__); - goto out; + goto put_node_slave; } overlay =tilcdc_get_overlay (&kft);if (!overlay) - goto out; + goto put_node_i2c; encoder =of_find_matching_node (overlay, tilcdc_tda998x_of_match);if (!encoder) {pr_err ("%s: Failed to find tda998x node\n" , __func__); - goto out; + goto put_node_i2c; }tilcdc_copy_props (slave, encoder, tilcdc_slave_props, &kft);@@ -238,10 +240,10 @@ void __init tilcdc_convert_slave_node(void)continue ;if (!strncmp ("i2c" , (char *)prop->value, prop->length))if (tilcdc_prop_str_update (prop, i2c->full_name, &kft)) - goto out; + goto put_node_fragment;if (!strncmp ("lcdc" , (char *)prop->value, prop->length))if (tilcdc_prop_str_update (prop, lcdc->full_name, &kft)) - goto out; + goto put_node_fragment; }tilcdc_node_disable (slave);@@ -252,12 +254,16 @@ void __init tilcdc_convert_slave_node(void)else pr_info ("%s: ti,tilcdc,slave node successfully converted\n" , __func__); -out: -kfree_table_free (&kft); + put_node_fragment: +of_node_put (fragment); + put_node_i2c:of_node_put (i2c); + put_node_slave:of_node_put (slave); + put_node_lcdc:of_node_put (lcdc); -of_node_put (fragment); + free_table: +kfree_table_free (&kft); }int __init tilcdc_slave_compat_init (void )
cover GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 19:00:01 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (14):
Use kmalloc_array() in two functions
Rename a jump label in ttm_alloc_new_pages()
Rename jump labels in ttm_page_pool_free()
Rename a jump label in ttm_page_pool_get_pages()
Use kmalloc_array() in two more functions
Rename a jump label in ttm_dma_pool_alloc_new_pages()
Rename jump labels in ttm_dma_page_pool_free()
Rename a jump label in ttm_dma_pool_shrink_scan()
Return directly after a failed kzalloc() in ttm_dma_page_alloc_init() Return directly after a failed kobject_init_and_add() in ttm_dma_page_alloc_init() Return an error code only as a constant in ttm_dma_pool_init()
Less function calls in ttm_dma_pool_init() after error detection Delete unnecessary variable initialisations in ttm_dma_pool_init() Mark an array of text strings as "const" in ttm_dma_pool_init()
drivers/gpu/drm/ttm/ttm_page_alloc.c | 30 ++++++++--------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 58 +++++++++++++++----------------- 2 files changed, 42 insertions(+), 46 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/14 GPU-DRM-TTM: Use kmalloc_array() in two functions
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:00:31 +0200
* Multiplications for the size determination of memory allocations indicated that array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +6 -4
@@ -315,8 +315,9 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,if (use_static) pages_to_free = static_buf;else - pages_to_free =kmalloc (npages_to_free *sizeof (struct page *), -GFP_KERNEL ); + pages_to_free =kmalloc_array (npages_to_free, +sizeof (*pages_to_free), +GFP_KERNEL );if (!pages_to_free) {pr_err ("Failed to allocate memory for pool free operation\n" );return 0 ;
@@ -501,8 +502,9 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags, (unsigned)(PAGE_SIZE/sizeof(struct page *)));/* allocate array for page caching change */ - caching_array =kmalloc (max_cpages*sizeof (struct page *),GFP_KERNEL ); - + caching_array =kmalloc_array (max_cpages, +sizeof (*caching_array), +GFP_KERNEL );if (!caching_array) {pr_err ("Unable to allocate table for new pages\n" );return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/14 GPU-DRM-TTM: Rename a jump label in ttm_alloc_new_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:16:05 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +3 -3
@@ -527,7 +527,7 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags, caching_array, cpages); } r = -ENOMEM ; - goto out; + goto free_array; }#ifdef CONFIG_HIGHMEM
@@ -546,7 +546,7 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags,ttm_handle_caching_state_failure (pages, ttm_flags, cstate, caching_array, cpages); - goto out; + goto free_array; } cpages =0 ; }
@@ -562,7 +562,7 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags, ttm_flags, cstate, caching_array, cpages); } -out: + free_array:kfree (caching_array);return r;
Signature · 1 line
2.10.0
PATCH 3/14 GPU-DRM-TTM: Rename jump labels in ttm_page_pool_free()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:30:12 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +4 -6
@@ -322,8 +322,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,pr_err ("Failed to allocate memory for pool free operation\n" );return 0 ; } - -restart: + lock_restart:spin_lock_irqsave (&pool->lock, irq_flags);list_for_each_entry_reverse (p, &pool->list, lru) {
@@ -356,14 +355,13 @@ restart:/* free all so restart the processing */ if (nr_free) - goto restart; + goto lock_restart;/* Not allowed to fall through or break because * following context is inside spinlock while we are * outside here. */ - goto out; - + goto check_pages_to_free; } }
@@ -379,7 +377,7 @@ restart:if (freed_pages)ttm_pages_put (pages_to_free, freed_pages); -out: + check_pages_to_free:if (pages_to_free != static_buf)kfree (pages_to_free);return nr_free;
Signature · 1 line
2.10.0
PATCH 4/14 GPU-DRM-TTM: Rename a jump label in ttm_page_pool_get_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:36:47 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +2 -2
@@ -646,7 +646,7 @@ static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool,list_splice_init (&pool->list, pages); count -= pool->npages; pool->npages =0 ; - goto out; + goto unlock; }/* find the last pages to include for requested number of pages. Split * pool to begin and halve it to reduce search space. */
@@ -667,7 +667,7 @@ static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool,list_cut_position (pages, &pool->list, p); pool->npages -= count; count =0 ; -out: + unlock:spin_unlock_irqrestore (&pool->lock, irq_flags);return count; }
Signature · 1 line
2.10.0
PATCH 5/14 GPU-DRM-TTM: Use kmalloc_array() in two more functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:48:39 +0200
* Multiplications for the size determination of memory allocations indicated that array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6 -4
@@ -439,8 +439,9 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,if (use_static) pages_to_free = static_buf;else - pages_to_free =kmalloc (npages_to_free *sizeof (struct page *), -GFP_KERNEL ); + pages_to_free =kmalloc_array (npages_to_free, +sizeof (*pages_to_free), +GFP_KERNEL );if (!pages_to_free) { pr_err("%s: Failed to allocate memory for pool free operation\n",
@@ -726,8 +727,9 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool, (unsigned)(PAGE_SIZE/sizeof(struct page *)));/* allocate array for page caching change */ - caching_array =kmalloc (max_cpages*sizeof (struct page *),GFP_KERNEL ); - + caching_array =kmalloc_array (max_cpages, +sizeof (*caching_array), +GFP_KERNEL );if (!caching_array) {pr_err ("%s: Unable to allocate table for new pages\n" , pool->dev_name);
Signature · 1 line
2.10.0
PATCH 6/14 GPU-DRM-TTM: Rename a jump label in ttm_dma_pool_alloc_new_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 14:54:12 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +3 -3
@@ -758,7 +758,7 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool, cpages); } r = -ENOMEM ; - goto out; + goto free_array; } p = dma_p->p;#ifdef CONFIG_HIGHMEM
@@ -777,7 +777,7 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,ttm_dma_handle_caching_state_failure ( pool, d_pages, caching_array, cpages); - goto out; + goto free_array; } cpages =0 ; }
@@ -791,7 +791,7 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,ttm_dma_handle_caching_state_failure (pool, d_pages, caching_array, cpages); } -out: + free_array:kfree (caching_array);return r; }
Signature · 1 line
2.10.0
PATCH 7/14 GPU-DRM-TTM: Rename jump labels in ttm_dma_page_pool_free()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 15:32:32 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -5
@@ -449,7 +449,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,return 0 ; }INIT_LIST_HEAD (&d_pages); -restart: + lock_restart:spin_lock_irqsave (&pool->lock, irq_flags);/* We picking the oldest ones off the list */
@@ -489,14 +489,13 @@ restart:/* free all so restart the processing */ if (nr_free) - goto restart; + goto lock_restart;/* Not allowed to fall through or break because * following context is inside spinlock while we are * outside here. */ - goto out; - + goto check_pages_to_free; } }
@@ -510,7 +509,7 @@ restart:if (freed_pages)ttm_dma_pages_put (pool, &d_pages, pages_to_free, freed_pages); -out: + check_pages_to_free:if (pages_to_free != static_buf)kfree (pages_to_free);return nr_free;
Signature · 1 line
2.10.0
PATCH 8/14 GPU-DRM-TTM: Rename a jump label in ttm_dma_pool_shrink_scan()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 16:02:36 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +2 -2
@@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)if (!mutex_trylock (&_manager->lock))return SHRINK_STOP ;if (!_manager->npools) - goto out; + goto unlock; pool_offset = ++start_pool % _manager->npools;list_for_each_entry (p, &_manager->pools, pools) {unsigned nr_free;
@@ -1046,7 +1046,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) p->pool->dev_name, p->pool->name, current->pid, nr_free, shrink_pages); } -out: + unlock:mutex_unlock (&_manager->lock);return freed; }
Signature · 1 line
2.10.0
PATCH 9/14 GPU-DRM-TTM: Return directly after a failed kzalloc() in ttm_dma_page_alloc_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 16:16:36 +0200
* Return directly after a memory allocation failed in this function at the beginning.
* Delete the explicit initialisation for the local variable "ret" which became unnecessary with this refactoring.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +2 -2
@@ -1080,7 +1080,7 @@ static void ttm_dma_pool_mm_shrink_fini(struct ttm_pool_manager *manager)int ttm_dma_page_alloc_init (struct ttm_mem_global *glob,unsigned max_pages) { -int ret = -ENOMEM ; +int ret;WARN_ON (_manager);
@@ -1088,7 +1088,7 @@ int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) _manager =kzalloc (sizeof (*_manager),GFP_KERNEL );if (!_manager) - goto err; +return -ENOMEM ;mutex_init (&_manager->lock);INIT_LIST_HEAD (&_manager->pools);
Signature · 1 line
2.10.0
PATCH 10/14 GPU-DRM-TTM: Return directly after a failed kobject_init_and_add() in ttm_dma_page_alloc_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 16:24:43 +0200
* Return directly after a call of the function "kobject_init_and_add" failed here.
* Delete the jump target "err" which became unnecessary with this refactoring.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -3
@@ -1102,12 +1102,10 @@ int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) &glob->kobj, "dma_pool");if (unlikely (ret !=0 )) {kobject_put (&_manager->kobj); - goto err; +return ret; }ttm_dma_pool_mm_shrink_init (_manager);return 0 ; -err: -return ret; }void ttm_dma_page_alloc_fini (void )
Signature · 1 line
2.10.0
PATCH 11/14 GPU-DRM-TTM: Return an error code only as a constant in ttm_dma_pool_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 17:17:19 +0200
* Return an error code without storing it in a local variable.
* Delete the local variable "ret" which became unnecessary with this refactoring.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -4
@@ -579,7 +579,6 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,struct device_pools *sec_pool =NULL ;struct dma_pool *pool =NULL , **ptr;unsigned i; -int ret = -ENODEV ;char *p;if (!dev)
@@ -589,8 +588,6 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,if (!ptr)return NULL ; - ret = -ENOMEM ; - pool =kmalloc_node (sizeof (struct dma_pool ),GFP_KERNEL ,dev_to_node (dev));if (!pool)
@@ -644,7 +641,7 @@ err_mem:devres_free (ptr);kfree (sec_pool);kfree (pool); -return ERR_PTR (ret); +return ERR_PTR (-ENOMEM ); } static struct dma_pool *ttm_dma_find_pool(struct device *dev,
Signature · 1 line
2.10.0
PATCH 12/14 GPU-DRM-TTM: Less function calls in ttm_dma_pool_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 17:30:52 +0200
The kfree() function was called in up to two cases by the ttm_dma_pool_init() function during error handling even if the passed variable contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +5 -5
@@ -591,12 +591,12 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags, pool =kmalloc_node (sizeof (struct dma_pool ),GFP_KERNEL ,dev_to_node (dev));if (!pool) - goto err_mem; + goto free_devres; sec_pool =kmalloc_node (sizeof (struct device_pools ),GFP_KERNEL ,dev_to_node (dev));if (!sec_pool) - goto err_mem; + goto free_pool;INIT_LIST_HEAD (&sec_pool->pools); sec_pool->dev = dev;
@@ -637,10 +637,10 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,devres_add (dev, ptr);return pool; -err_mem: -devres_free (ptr); -kfree (sec_pool); + free_pool:kfree (pool); + free_devres: +devres_free (ptr);return ERR_PTR (-ENOMEM ); }
Signature · 1 line
2.10.0
PATCH 13/14 GPU-DRM-TTM: Delete unnecessary variable initialisations in ttm_dma_pool_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 17:37:24 +0200
Two local variables will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation which became unnecessary with a previous update step.
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +2 -2
@@ -576,8 +576,8 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags, {char *n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,};enum pool_type t[] = {IS_WC ,IS_UC ,IS_CACHED ,IS_DMA32 ,IS_UNDEFINED }; -struct device_pools *sec_pool =NULL ; -struct dma_pool *pool =NULL , **ptr; +struct device_pools *sec_pool; +struct dma_pool *pool, **ptr;unsigned i;char *p;
Signature · 1 line
2.10.0
PATCH 14/14 GPU-DRM-TTM: Mark an array of text strings as "const" in ttm_dma_pool_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 18:46:01 +0200
The local variable "n" was not modified after it was initialized with a few text strings.
Thus express this detail also by the data type qualifier "const".
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -1
@@ -574,7 +574,7 @@ static int ttm_dma_pool_match(struct device *dev, void *res, void *match_data)static struct dma_pool *ttm_dma_pool_init (struct device *dev,gfp_t flags,enum pool_type type) { -char *n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,}; +char const *const n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,};enum pool_type t[] = {IS_WC ,IS_UC ,IS_CACHED ,IS_DMA32 ,IS_UNDEFINED };struct device_pools *sec_pool;struct dma_pool *pool, **ptr;
Signature · 1 line
2.10.0
Re: GPU-DRM-TILCDC: Return directly after a failed kfree_table_init() in tilcdc_convert_slave_node()
In reply to Jyri SarhaQuoted 2 lines
I'll pick this up, but with your permission I change the commit subject to follow the current convention.
I guess that I can accept the integration of this update suggestion
also with an adjusted prefix in the commit title. ;-)
Regards,
Markus
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to Jyri SarhaQuoted 9 lines
Quoted 9 lines
The
of_node_put()function was called in some cases
by thetilcdc_convert_slave_node()function during error handling even if the passed variable contained a null pointer.* Adjust jump targets according to the Linux coding style convention.
* Split a condition check for resource detection failures so that each pointer from these function calls will be checked immediately.
Quoted 6 lines
Quoted 4 lines
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"I don't really agree with this patch.
This kind of feedback can be fine at first glance.
Quoted 1 line
There is no harm in calling
of_node_put()with NULL as an argument
The cost of additional function calls will be eventually not noticed just because they belong to an exception handling implementation so far.
Quoted 1 line
and because of that there is no point in making the function more complex
There is inherent software complexity involved.
Quoted 1 line
and harder to maintain.
How do you think about to discuss this aspect a bit more?
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
* How much will it matter in general that one function call was performed in this use case without checking its return value immediately?
* Should it usually be determined quicker if a required resource could be acquired before trying the next allocation?
Regards,
Markus
Joe Perches
maintainerRe: [PATCH 14/14] GPU-DRM-TTM: Mark an array of text strings as "const" in ttm_dma_pool_init()
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
The local variable "n" was not modified after it was initialized with a few text strings.
Thus express this detail also by the data type qualifier "const".
[]
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
Quoted 1 line
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0
-0
[]
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c static int ttm_dma_pool_match(struct device *dev, void *res, void *match_data) · line 578
Quoted 7 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1
-1@@ -574,7 +574,7 @@ static int ttm_dma_pool_match(struct device *dev, void *res, void *match_data)static struct dma_pool *ttm_dma_pool_init (struct device *dev,gfp_t flags,enum pool_type type) { -char *n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,}; +char const *const n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,};enum pool_type t[] = {IS_WC ,IS_UC ,IS_CACHED ,IS_DMA32 ,IS_UNDEFINED };
Please think a little deeper about what you are changing here and look at the line immediately below it too.
Both should be static const to avoid unnecessary reload.
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringQuoted 21 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
The
of_node_put()function was called in some cases
by thetilcdc_convert_slave_node()function during error handling even if the passed variable contained a null pointer.* Adjust jump targets according to the Linux coding style convention.
* Split a condition check for resource detection failures so that each pointer from these function calls will be checked immediately.
Quoted 6 lines
Quoted 4 lines
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"I don't really agree with this patch.
This kind of feedback can be fine at first glance.
Quoted 1 line
There is no harm in calling
of_node_put()with NULL as an argument
Quoted 8 lines
The cost of additional function calls will be eventually not noticed just because they belong to an exception handling implementation so far.
Quoted 1 line
and because of that there is no point in making the function more complex
There is inherent software complexity involved.
I think the "if (node)" in the of_node_put() is there on purpose, because it potentially saves the caller one extra if()-statement and keeps the caller code simpler.
Quoted 5 lines
Quoted 2 lines
and harder to maintain.
How do you think about to discuss this aspect a bit more?
Keeping the goto labels in right order needs precision and can lead to subtle errors. Sometimes there is no way to avoid that, but here there is.
Best regards,
Jyri
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
Quoted 1 line
I think the "if (node)" in the
of_node_put()is there on purpose,
Yes, of course.
Does such an implementation detail correspond to a general software design pattern?
Quoted 1 line
because it potentially saves the caller one extra if()-statement
This can occasionally happen.
Quoted 1 line
and keeps the caller code simpler.
A special view on software simplicity can also lead to questionable intermediate function implementation, can't it?
Quoted 1 line
Keeping the goto labels in right order needs precision
I can agree to this view.
Quoted 1 line
and can lead to subtle errors.
The management of jump labels is just another software development challenge as usual, isn't it?
Quoted 1 line
Sometimes there is no way to avoid that,
How do you think about to clarify the constraints which you imagine a bit more?
Quoted 1 line
but here there is.
I disagree to this conclusion.
Would you like to care a bit more for efficiency and software correctness around the discussed exception handling?
Regards,
Markus
Re: [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:56:56 +0200Several update suggestions were taken into account from static source code analysis.
All look very nice!
Vinod, please apply them all!
Yours,
Linus Walleij
Re: [PATCH 00/14] GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to SF Markus ElfringFirst of all please stop sending your patches as a reply to an earlier and completely unrelated series.
Second please prefix all TTM related patches with "drm/ttm:".
Additional to that I don't really see the point in renaming some of the jump labels, if you call it "restart" or "lock_restart" doesn't make much difference.
Regards,
Christian.
Am 22.09.2016 um 19:32 schrieb SF Markus Elfring:
Quoted 26 lines
From: Markus Elfring <[email protected]>
Date: Thu, 22 Sep 2016 19:00:01 +0200Several update suggestions were taken into account from static source code analysis.
Markus Elfring (14):
Usekmalloc_array()in two functions
Rename a jump label inttm_alloc_new_pages()
Rename jump labels inttm_page_pool_free()
Rename a jump label inttm_page_pool_get_pages()
Usekmalloc_array()in two more functions
Rename a jump label inttm_dma_pool_alloc_new_pages()
Rename jump labels inttm_dma_page_pool_free()
Rename a jump label inttm_dma_pool_shrink_scan()
Return directly after a failedkzalloc()inttm_dma_page_alloc_init()Return directly after a failedkobject_init_and_add()inttm_dma_page_alloc_init()Return an error code only as a constant inttm_dma_pool_init()
Less function calls inttm_dma_pool_init()after error detection Delete unnecessary variable initialisations inttm_dma_pool_init()Mark an array of text strings as "const" inttm_dma_pool_init()drivers/gpu/drm/ttm/ttm_page_alloc.c | 30 ++++++++--------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 58 +++++++++++++++----------------- 2 files changed, 42 insertions(+), 46 deletions(-)
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
Quoted 1 line
Additional to that I don't really see the point in renaming some of the jump labels,
I am suggesting changes for another collateral software evolution.
Quoted 1 line
if you call it "restart" or "
lock_restart" doesn't make much difference.
Do other identifiers fit better to a specification from the document "CodingStyle" like the following?
"…
Choose label names which say what the goto does or why the goto exists. …"
Does this wording need any more adjustments?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
Quoted 1 line
I think the "if (node)" in the
of_node_put()is there on purpose,Yes, of course.
Does such an implementation detail correspond to a general software design pattern?
Yes it does. For instance standard malloc()/free() implementation [1].
Quoted 11 lines
Quoted 2 lines
because it potentially saves the caller one extra if()-statement
This can occasionally happen.
Quoted 1 line
and keeps the caller code simpler.
A special view on software simplicity can also lead to questionable intermediate function implementation, can't it?
I don't really follow. But in any case I do not see anything questionable in the current tilcdc_convert_slave_node() implementation.
Quoted 11 lines
Quoted 2 lines
Keeping the goto labels in right order needs precision
I can agree to this view.
Quoted 1 line
and can lead to subtle errors.
The management of jump labels is just another software development challenge as usual, isn't it?
Yes. But usually it pays of to avoid complexity when possible.
Quoted 5 lines
Quoted 2 lines
Sometimes there is no way to avoid that,
How do you think about to clarify the constraints which you imagine a bit more?
If the the of_node_put() behaviour would not be specified with null pointer as parameter, there would be such a constraint.
I am beginning to have a feeling that this discussion is not going anywhere.
Quoted 8 lines
Quoted 2 lines
but here there is.
I disagree to this conclusion.
Would you like to care a bit more for efficiency and software correctness around the discussed exception handling?
No, I would not. I think we have reached the bottom of this discussion. For the moment I have more important tasks to do.
Best regards,
Jyri
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to SF Markus ElfringAm 23.09.2016 um 12:20 schrieb SF Markus Elfring:
Quoted 7 lines
Quoted 1 line
Additional to that I don't really see the point in renaming some of the jump labels,
I am suggesting changes for another collateral software evolution.
Quoted 1 line
if you call it "restart" or "
lock_restart" doesn't make much difference.Do other identifiers fit better to a specification from the document "CodingStyle" like the following?
No, not really.
Quoted 7 lines
"…
Choose label names which say what the goto does or why the goto exists. …"Does this wording need any more adjustments?
Of hand I can't find any better wording.
It's just the names like "out" or "restart" perfectly explain why the labels exists. So they fulfill this requirement from the coding style as far as I can see.
So why do you want to change them?
Regards,
Christian.
Quoted 3 lines
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to Jyri SarhaQuoted 5 lines
Quoted 2 lines
A special view on software simplicity can also lead to questionable intermediate function implementation, can't it?
I don't really follow. But in any case I do not see anything questionable in the current
tilcdc_convert_slave_node()implementation.
I identified update candidates there like the following.
1. Delayed checking for null pointers
…
if (!slave || !of_device_is_available(lcdc))
…
2. Usage of a single jump label for (too many?) cases …
goto out;
…
Can the corresponding exception handling become also a bit more efficient?
Quoted 4 lines
Quoted 2 lines
Would you like to care a bit more for efficiency and software correctness around the discussed exception handling?
No, I would not.
Thanks for this information.
I hope that the software situation can also be improved around this design aspect somehow.
Quoted 1 line
For the moment I have more important tasks to do.
I know also that various open issues are competing for your software development attention as usual.
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringQuoted 16 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
The
of_node_put()function was called in some cases
by thetilcdc_convert_slave_node()function during error handling even if the passed variable contained a null pointer.* Adjust jump targets according to the Linux coding style convention.
* Split a condition check for resource detection failures so that each pointer from these function calls will be checked immediately.
Quoted 6 lines
Quoted 4 lines
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"I don't really agree with this patch.
Quoted 7 lines
This kind of feedback can be fine at first glance.
Quoted 1 line
There is no harm in calling
of_node_put()with NULL as an argumentThe cost of additional function calls will be eventually not noticed just because they belong to an exception handling implementation so far.
iirc, there are Coccinelle rules that find code with unnecessary null checks and removes them..
Although you probably made this complex enough that cocinelle would not find it. That is not a complement. One should not make error handling/cleanup more complex than needed.
BR,
-R
Quoted 26 lines
Quoted 2 lines
and because of that there is no point in making the function more complex
There is inherent software complexity involved.
Quoted 1 line
and harder to maintain.
How do you think about to discuss this aspect a bit more?
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
* How much will it matter in general that one function call was performed in this use case without checking its return value immediately?
* Should it usually be determined quicker if a required resource could be acquired before trying the next allocation?
Regards,
Markus
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to Christian KönigQuoted 1 line
It's just the names like "out" or "restart" perfectly explain why the labels exists.
I have got an other impression.
Quoted 1 line
So they fulfill this requirement from the coding style as far as I can see.
Short identifiers might look more convenient in some cases because they are quicker to type.
Quoted 1 line
So why do you want to change them?
1. I suggest to select identifiers also for jump labels which are more meaningful and eventually unique for some function implementations.
2. How do you think about to add a single space character before any label?
Regards,
Markus
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
Am 23.09.2016 um 13:07 schrieb SF Markus Elfring:
Quoted 4 lines
Quoted 1 line
It's just the names like "out" or "restart" perfectly explain why the labels exists.
I have got an other impression.
Quoted 8 lines
Quoted 1 line
So they fulfill this requirement from the coding style as far as I can see.
Short identifiers might look more convenient in some cases because they are quicker to type.
Quoted 1 line
So why do you want to change them?
1. I suggest to select identifiers also for jump labels which are more meaningful and eventually unique for some function implementations.
I completely disagree. A longer identifier is not necessarily more meaningful than a shorter one.
The difference between calling a label "retry" and "lock_retry" is negligible, doesn't improve readability as far as I can see and is actually incorrect because the main meaning of the label is that we don't take the lock but rather that we restart the allocation operation.
Calling the label "unlock" instead of "out" is arguable a little better, but nothing I would call a major improvement either.
So that is a clear NAK to all those patches.
Quoted 1 line
2. How do you think about to add a single space character before any label?
Bad as well. Why would anybody want to do this?
Christian.
Quoted 3 lines
Regards,
Markus
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to Rob ClarkQuoted 2 lines
iirc, there are Coccinelle rules that find code with unnecessary null checks and removes them.
This kind of software change is not needed here.
I find that a corresponding return value check happens one function call too late.
Quoted 2 lines
Although you probably made this complex enough that cocinelle would not find it. That is not a complement.
I imagine that scripts for the semantic patch language can find more source code places where questionable disjunctions are used so far. Would you dare to split any more condition checks?
Quoted 1 line
One should not make error handling/cleanup more complex than needed.
I see a need to improve not only correctness there but also a bit of software efficiency.
Regards,
Markus
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
Quoted 8 lines · SF Markus Elfring
Quoted 2 lines
iirc, there are Coccinelle rules that find code with unnecessary null checks and removes them.
This kind of software change is not needed here.
I find that a corresponding return value check happens one function call too late.
I think you misunderstand my point.. which is that additional conditional checks wrapping a function call to something that already checks for null should be removed.. not introduced.
Quoted 9 lines
Quoted 3 lines
Although you probably made this complex enough that cocinelle would not find it. That is not a complement.
I imagine that scripts for the semantic patch language can find more source code places where questionable disjunctions are used so far. Would you dare to split any more condition checks?
Quoted 4 lines
Quoted 1 line
One should not make error handling/cleanup more complex than needed.
I see a need to improve not only correctness there but also a bit of software efficiency.
If you can measure any performance difference and present some results (esp. considering that this is something that just happens when the driver is loaded), then we'll talk. Until then, please don't send this sort of patch. Thank you.
BR,
-R
Quoted 2 lines
Regards,
Markus
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to Christian KönigQuoted 1 line
Calling the label "unlock" instead of "out" is arguable a little better,
Thanks that you can follow a renaming for this direction in principle.
Quoted 1 line
but nothing I would call a major improvement either.
This was not my intention for such an use case.
I am proposing some small software updates according to such a design pattern.
Quoted 1 line
So that is a clear NAK to all those patches.
Do you reject also update steps like the following then?
* drm/ttm: Use kmalloc_array() in two (or four?) functions"
* drm/ttm: Less function calls in ttm_dma_pool_init() after error detection
* Would you like to improve the usage of the variables "n" and "t" in the function "ttm_dma_pool_init" any further as Joe Perches suggested it?
Quoted 3 lines
Quoted 1 line
2. How do you think about to add a single space character before any label?
Bad as well. Why would anybody want to do this?
Do you find another software evolution interesting according to a recent commit?
"docs: Remove space-before-label guidance from CodingStyle"
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817a
Regards,
Markus
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to Rob ClarkQuoted 6 lines
Quoted 2 lines
I see a need to improve not only correctness there but also a bit of software efficiency.
If you can measure any performance difference and present some results (esp. considering that this is something that just happens when the driver is loaded), then we'll talk.
Are you really interested to increase your software development attention for a quicker exception handling implementation in this function?
Quoted 1 line
Until then, please don't send this sort of patch. Thank you.
Will benchmark statistics change such a change rejection ever?
Regards,
Markus
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 11 lines · SF Markus Elfring
Quoted 1 line
if you call it "restart" or "
lock_restart" doesn't make much difference.Do other identifiers fit better to a specification from the document "CodingStyle" like the following?
"…
Choose label names which say what the goto does or why the goto exists. …"Does this wording need any more adjustments?
No. I wrote that and "restart" seems like a pretty clear name to me. I never wrote that you should harrass people with your nonsense patches. In fact, I have asked you over and over again to stop.
regards,
dan carpenter
Re: GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Quoted 6 lines
Quoted 2 lines
I see a need to improve not only correctness there but also a bit of software efficiency.
If you can measure any performance difference and present some results (esp. considering that this is something that just happens when the driver is loaded), then we'll talk.
Are you really interested to increase your software development attention for a quicker exception handling implementation in this function?
No one is interested in making error handling more complex for a non-existent benefit ;-)
Quoted 4 lines
Quoted 2 lines
Until then, please don't send this sort of patch. Thank you.
Will benchmark statistics change such a change rejection ever?
If you could demonstrate a real benefit to additional complexity for something that actually matters (ie. not something like this that runs once at bootup) I would care.
I don't recommend that you waste your time, since there is approximately nothing in modesetting path that happens with a high enough frequency to benefit from such a micro-optimization. Especially not initialization code that runs once at boot up.
Fixing actual bugs is useful and valuable. Premature "optimization" at the expense of extra complexity is very much not useful.
BR,
-R
Quoted 2 lines
Regards,
Markus
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to SF Markus ElfringAm 23.09.2016 um 13:49 schrieb SF Markus Elfring:
Quoted 10 lines
Quoted 1 line
Calling the label "unlock" instead of "out" is arguable a little better,
Thanks that you can follow a renaming for this direction in principle.
Quoted 1 line
but nothing I would call a major improvement either.
This was not my intention for such an use case.
I am proposing some small software updates according to such a design pattern.
Quoted 6 lines
Quoted 1 line
So that is a clear NAK to all those patches.
Do you reject also update steps like the following then?
* drm/ttm: Use
kmalloc_array()in two (or four?) functions"* drm/ttm: Less function calls in
ttm_dma_pool_init()after error detection
The reason behind the advise to use kmalloc_array() is to avoid overruns when one of the parameters come from an IOCTL and so are controllable by user space.
Those overruns where the source of numerous security problems, but in this case the parameters don't come from an IOCTL and aren't user space controllable.
So this change actually doesn't make to much sense either, but I'm leaning towards accepting them for coding style consistency.
Regards,
Christian.
Quoted 14 lines
* Would you like to improve the usage of the variables "n" and "t" in the function "
ttm_dma_pool_init" any further as Joe Perches suggested it?Quoted 2 lines
Quoted 1 line
2. How do you think about to add a single space character before any label?
Bad as well. Why would anybody want to do this?
Do you find another software evolution interesting according to a recent commit?
"docs: Remove space-before-label guidance from CodingStyle"
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817aRegards,
Markus
Re: GPU-DRM-TTM: Fine-tuning for several function implementations
In reply to Dan CarpenterQuoted 11 lines
Quoted 9 lines
Do other identifiers fit better to a specification from the document "CodingStyle" like the following?
"…
Choose label names which say what the goto does or why the goto exists. …"Does this wording need any more adjustments?
No.
I have got an other impression.
The terse description can trigger disagreements about the "what" and "why", can't it?
Quoted 1 line
I wrote that and "restart" seems like a pretty clear name to me.
This identifier might be good enough to some degree.
I imagined that it would become better by the addition of a bit of information from the jump target.
Quoted 1 line
I never wrote that you should harrass people with your nonsense patches.
This is true in principle.
But your adjustment for the document "CodingStyle" supported also a reconsideration of the corresponding identifier selection.
Some developers disagreed with a proposed renaming while others reacted in a positive way.
Quoted 1 line
In fact, I have asked you over and over again to stop.
This happened under different software update contexts occasionally.
Regards,
Markus
cover i2c-dev: Fine-tuning for four function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 21:38:21 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Use kmalloc_array() in i2cdev_ioctl_rdwr() Improve another size determination in i2cdev_ioctl_rdwr() Rename jump labels in i2cdev_attach_adapter() Adjust checks for null pointers in three functions
drivers/i2c/i2c-dev.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/4 i2c-dev: Use kmalloc_array() in i2cdev_ioctl_rdwr()
From: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 20:30:07 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/i2c/i2c-dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/i2c-dev.c +3 -1
@@ -260,7 +260,9 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,if (IS_ERR (rdwr_pa))return PTR_ERR (rdwr_pa); - data_ptrs =kmalloc (rdwr_arg.nmsgs *sizeof (u8 __user *),GFP_KERNEL ); + data_ptrs =kmalloc_array (rdwr_arg.nmsgs, +sizeof (*data_ptrs), +GFP_KERNEL );if (data_ptrs =NULL ) {kfree (rdwr_pa);return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/4 i2c-dev: Improve another size determination in i2cdev_ioctl_rdwr()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 20:45:40 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/i2c/i2c-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-dev.c +1 -1
@@ -256,7 +256,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,return -EINVAL ; rdwr_pa =memdup_user (rdwr_arg.msgs, - rdwr_arg.nmsgs *sizeof (struct i2c_msg )); + rdwr_arg.nmsgs *sizeof (*rdwr_pa));if (IS_ERR (rdwr_pa))return PTR_ERR (rdwr_pa);
Signature · 1 line
2.10.0
PATCH 3/4 i2c-dev: Rename jump labels in i2cdev_attach_adapter()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 21:21:39 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/i2c/i2c-dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/i2c-dev.c +4 -4
@@ -555,7 +555,7 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) i2c_dev->cdev.owner =THIS_MODULE ; res =cdev_add (&i2c_dev->cdev,MKDEV (I2C_MAJOR , adap->nr),1 );if (res) - goto error_cdev; + goto put_i2c;/* register this i2c device with the driver core */ i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
@@ -563,15 +563,15 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) "i2c-%d", adap->nr);if (IS_ERR (i2c_dev->dev)) { res =PTR_ERR (i2c_dev->dev); - goto error; + goto delete_cdev; }pr_debug ("i2c-dev: adapter [%s] registered as minor %d\n" , adap->name, adap->nr);return 0 ; -error: +delete_cdev:cdev_del (&i2c_dev->cdev); -error_cdev: +put_i2c:put_i2c_dev (i2c_dev);return res; }
Signature · 1 line
2.10.0
PATCH 4/4 i2c-dev: Adjust checks for null pointers in three functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 21:30:20 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/i2c/i2c-dev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/i2c-dev.c +3 -3
@@ -147,7 +147,7 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count, count =8192 ; tmp =kmalloc (count,GFP_KERNEL ); -if (tmp =NULL ) +if (!tmp)return -ENOMEM ; pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
@@ -263,7 +263,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, data_ptrs =kmalloc_array (rdwr_arg.nmsgs,sizeof (*data_ptrs),GFP_KERNEL ); -if (data_ptrs =NULL ) { +if (!data_ptrs) {kfree (rdwr_pa);return -ENOMEM ; }
@@ -374,7 +374,7 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client, client->flags, data_arg.read_write, data_arg.command, data_arg.size, NULL); -if (data_arg.data =NULL ) { +if (!data_arg.data) {dev_dbg (&client->adapter->dev,"data is NULL pointer in ioctl I2C_SMBUS.\n" );return -EINVAL ;
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
cover iio: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 08:10:08 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (7):
Use kmalloc_array() in iio_scan_mask_set() Rename a jump label in iio_buffer_store_watermark() Rename a jump label in iio_buffer_store_enable() Rename a jump label in iio_buffer_write_length() Rename a jump label in iio_scan_el_ts_store() Rename a jump label in iio_scan_el_store() Adjust checks for null pointers in six functions
drivers/iio/industrialio-buffer.c | 55 ++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 29 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/7 iio: Use kmalloc_array() in iio_scan_mask_set()
From: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 22:30:32 +0200
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/iio/industrialio-buffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/industrialio-buffer.c +3 -4
@@ -307,10 +307,9 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,const unsigned long *mask;unsigned long *trialmask; - trialmask =kmalloc (sizeof (*trialmask)* -BITS_TO_LONGS (indio_dev->masklength), -GFP_KERNEL ); - + trialmask =kmalloc_array (BITS_TO_LONGS (indio_dev->masklength), +sizeof (*trialmask), +GFP_KERNEL );if (trialmask =NULL )return -ENOMEM ;if (!indio_dev->masklength) {
Signature · 1 line
2.10.0
PATCH 2/7 iio: Rename a jump label in iio_buffer_store_watermark()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 06:54:49 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/iio/industrialio-buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/industrialio-buffer.c +3 -3
@@ -1028,16 +1028,16 @@ static ssize_t iio_buffer_store_watermark(struct device *dev,if (val > buffer->length) { ret = -EINVAL ; - goto out; + goto unlock; }if (iio_buffer_is_active (indio_dev->buffer)) { ret = -EBUSY ; - goto out; + goto unlock; } buffer->watermark = val; -out: +unlock:mutex_unlock (&indio_dev->mlock);return ret ? ret : len;
Signature · 1 line
2.10.0
PATCH 3/7 iio: Rename a jump label in iio_buffer_store_enable()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 07:11:32 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/iio/industrialio-buffer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/industrialio-buffer.c +2 -3
@@ -982,7 +982,7 @@ static ssize_t iio_buffer_store_enable(struct device *dev, inlist =iio_buffer_is_active (indio_dev->buffer);/* Already in desired state */ if (inlist = requested_state) - goto done; + goto unlock;if (requested_state) ret = __iio_update_buffers(indio_dev,
@@ -990,8 +990,7 @@ static ssize_t iio_buffer_store_enable(struct device *dev,else ret =__iio_update_buffers (indio_dev,NULL , indio_dev->buffer); - -done: +unlock:mutex_unlock (&indio_dev->mlock);return (ret <0 ) ? ret : len; }
Signature · 1 line
2.10.0
PATCH 4/7 iio: Rename a jump label in iio_buffer_write_length()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 07:17:44 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/iio/industrialio-buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/industrialio-buffer.c +2 -2
@@ -505,10 +505,10 @@ static ssize_t iio_buffer_write_length(struct device *dev, ret =0 ; }if (ret) - goto out; + goto unlock;if (buffer->length && buffer->length < buffer->watermark) buffer->watermark = buffer->length; -out: +unlock:mutex_unlock (&indio_dev->mlock);return ret ? ret : len;
Signature · 1 line
2.10.0
PATCH 5/7 iio: Rename a jump label in iio_scan_el_ts_store()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 07:27:26 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/iio/industrialio-buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/industrialio-buffer.c +2 -2
@@ -409,10 +409,10 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,mutex_lock (&indio_dev->mlock);if (iio_buffer_is_active (indio_dev->buffer)) { ret = -EBUSY ; - goto error_ret; + goto unlock; } indio_dev->buffer->scan_timestamp = state; -error_ret: +unlock:mutex_unlock (&indio_dev->mlock);return ret ? ret : len;
Signature · 1 line
2.10.0
PATCH 6/7 iio: Rename a jump label in iio_scan_el_store()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 07:40:59 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/iio/industrialio-buffer.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/industrialio-buffer.c +5 -6
@@ -363,22 +363,21 @@ static ssize_t iio_scan_el_store(struct device *dev,mutex_lock (&indio_dev->mlock);if (iio_buffer_is_active (indio_dev->buffer)) { ret = -EBUSY ; - goto error_ret; + goto unlock; } ret =iio_scan_mask_query (indio_dev, buffer, this_attr->address);if (ret <0 ) - goto error_ret; + goto unlock;if (!state && ret) { ret =iio_scan_mask_clear (buffer, this_attr->address);if (ret) - goto error_ret; + goto unlock; }else if (state && !ret) { ret =iio_scan_mask_set (indio_dev, buffer, this_attr->address);if (ret) - goto error_ret; + goto unlock; } - -error_ret: +unlock:mutex_unlock (&indio_dev->mlock);return ret <0 ? ret : len;
Signature · 1 line
2.10.0
PATCH 7/7 iio: Adjust checks for null pointers in six functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 08:00:07 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/iio/industrialio-buffer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/iio/industrialio-buffer.c +9 -9
@@ -310,7 +310,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, trialmask =kmalloc_array (BITS_TO_LONGS (indio_dev->masklength),sizeof (*trialmask),GFP_KERNEL ); -if (trialmask =NULL ) +if (!trialmask)return -ENOMEM ;if (!indio_dev->masklength) {WARN (1 ,"Trying to set scanmask prior to registering buffer\n" );
@@ -711,7 +711,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,/* What scan mask do we actually have? */ compound_mask =kcalloc (BITS_TO_LONGS (indio_dev->masklength),sizeof (long ),GFP_KERNEL ); -if (compound_mask =NULL ) +if (!compound_mask)return -ENOMEM ; scan_timestamp = false;
@@ -736,7 +736,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, compound_mask, strict_scanmask);kfree (compound_mask); -if (scan_mask =NULL ) +if (!scan_mask)return -EINVAL ; }else { scan_mask = compound_mask;
@@ -940,7 +940,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, goto out_unlock; } -if (indio_dev->info =NULL ) { +if (!indio_dev->info) { ret = -ENODEV ; goto out_unlock; }
@@ -1130,11 +1130,11 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) indio_dev->scan_index_timestamp channels[i].scan_index; } -if (indio_dev->masklength && buffer->scan_mask =NULL ) { +if (indio_dev->masklength && !buffer->scan_mask) { buffer->scan_mask =kcalloc (BITS_TO_LONGS (indio_dev->masklength),sizeof (*buffer->scan_mask),GFP_KERNEL ); -if (buffer->scan_mask =NULL ) { +if (!buffer->scan_mask) { ret = -ENOMEM ; goto error_cleanup_dynamic; }
@@ -1146,7 +1146,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) buffer->scan_el_group.attrs =kcalloc (attrcount +1 ,sizeof (buffer->scan_el_group.attrs[0 ]),GFP_KERNEL ); -if (buffer->scan_el_group.attrs =NULL ) { +if (!buffer->scan_el_group.attrs) { ret = -ENOMEM ; goto error_free_scan_mask; }
@@ -1291,7 +1291,7 @@ static int iio_buffer_add_demux(struct iio_buffer *buffer, (*p)->length += length; }else { *p =kmalloc (sizeof (**p),GFP_KERNEL ); -if (*p =NULL ) +if (!*p)return -ENOMEM ; (*p)->from = in_loc; (*p)->to = out_loc;
@@ -1356,7 +1356,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev, in_loc += length; } buffer->demux_bounce =kzalloc (out_loc,GFP_KERNEL ); -if (buffer->demux_bounce =NULL ) { +if (!buffer->demux_bounce) { ret = -ENOMEM ; goto error_clear_mux_table; }
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
cover Input-evdev: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 13:03:13 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Use kmalloc_array()
Rename a jump label in two functions
drivers/input/evdev.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/2 Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
From: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 12:42:45 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
* Delete the local variable "len" which became unnecessary with this refactoring.
--- drivers/input/evdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/input/evdev.c +2 -6
@@ -919,18 +919,14 @@ static int evdev_handle_get_val(struct evdev_client *client, {int ret;unsigned long *mem; -size_t len; - len =BITS_TO_LONGS (maxbit) *sizeof (unsigned long ); - mem =kmalloc (len,GFP_KERNEL ); + mem =kmalloc_array (BITS_TO_LONGS (maxbit),sizeof (*mem),GFP_KERNEL );if (!mem)return -ENOMEM ;spin_lock_irq (&dev->event_lock);spin_lock (&client->buffer_lock); - -memcpy (mem, bits, len); - +memcpy (mem, bits,sizeof (*mem) *BITS_TO_LONGS (maxbit));spin_unlock (&dev->event_lock);__evdev_flush_queue (client, type);
Signature · 1 line
2.10.0
PATCH 2/2 Input-evdev: Rename a jump label in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 12:50:31 +0200
Adjust a jump label according to the current Linux coding style convention. Thus replace the identifier "out" by "unlock".
--- drivers/input/evdev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/input/evdev.c +5 -7
@@ -545,22 +545,21 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,if (!evdev->exist || client->revoked) { retval = -ENODEV ; - goto out; + goto unlock; }while (retval +input_event_size () <= count) {if (input_event_from_user (buffer + retval, &event)) { retval = -EFAULT ; - goto out; + goto unlock; } retval +=input_event_size ();input_inject_event (&evdev->handle, event.type, event.code, event.value); } - - out: +unlock:mutex_unlock (&evdev->mutex);return retval; }
@@ -1292,12 +1291,11 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,if (!evdev->exist || client->revoked) { retval = -ENODEV ; - goto out; + goto unlock; } retval =evdev_do_ioctl (file, cmd, p, compat_mode); - - out: +unlock:mutex_unlock (&evdev->mutex);return retval; }
Signature · 1 line
2.10.0
Re: [PATCH 01/] firewire-net: Use kmalloc_array() in fwnet_broadcast_start()
In reply to SF Markus ElfringQuoted 23 lines · On Sep 18 SF Markus Elfring wrote:
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 21:55:42 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firewire/net.c +0
-0
drivers/firewire/net.c static int fwnet_broadcast_start(struct fwnet_device *dev) · line 1109
Quoted 9 lines
drivers/firewire/net.c +1
-2@@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) max_receive =1U << (dev->card->max_receive +1 ); num_packets = (FWNET_ISO_PAGE_COUNT *PAGE_SIZE ) / max_receive; - - ptrptr =kmalloc (sizeof (void *) * num_packets,GFP_KERNEL ); + ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; goto failed;
Coccinelle enabled you to determine that kmalloc_array /could/ be used here. But whether it /should/ be used here is another question, and it is not addressed in your changelog. (You state that there is an "issue" but do not explain.)
kmalloc_array is a kmalloc wrapper which adds an inline check for integer overflow. So, can sizeof(void *) * num_packets ever overflow size_t?
If yes,
do we want a runtime check here (which kmalloc_array provides), or do we want a compile-time check?
If no,
then the remaining benefit of the patch is that it is more obvious to the reader that dev->broadcast_rcv_buffer_ptrs is an array, but possibly at the cost of superfluous code. Is gcc's optimizer able to resolve kmalloc_array's check at compile time as always false, such that the superfluous code is eliminated as dead code?
I believe I know answers to this but prefer to hear what you as the patch author think about it.
Signature · 3 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/
Re: [PATCH 10/10] firewire-net: Adjust checks for null pointers in five functions
In reply to SF Markus ElfringQuoted 1 line · On Sep 18 SF Markus Elfring wrote:
The script "checkpatch.pl" can point information out like the following.
A side note: checkpatch.pl is for authors to help prepare their submissions of new code (or their refactoring of existing code if for some reason a refactoring is undertaken).
Quoted 1 line
Comparison to NULL could be written !…
Yes it could, or it could remain as is. Both styles are used in drivers/firewire/net.c, so it is indeed preferable to normalize it to one of them. I keep your patch for the next occasion when related work is being done on drivers/firewire/net.c or drivers/firewire.
Quoted 1 line
Thus fix the affected source code places.
It is not a "fix", it is a stylistic change.
Quoted 16 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/firewire/net.c +1
-1@@ -366,13 +366,13 @@ static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net,INIT_LIST_HEAD (&new->fi_list); fi =fwnet_frag_new (new, frag_off, frag_len); -if (fi =NULL ) +if (!fi) goto free_new;
[...]
Signature · 7 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/ -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 02/10] firewire-net: Rename a jump label in fwnet_broadcast_start()
In reply to SF Markus ElfringQuoted 2 lines · On Sep 18 SF Markus Elfring wrote:
Adjust jump labels according to the current Linux coding style convention.
The current CodingStyle says: "Choose label names which say what the goto does or why the goto exists." Given the choice between /what/ and /why/, I for one lean towards /why/.
In this instance, the what and why is "clean up and exit after an error occurred". 'failed' looks to me to be a better shorthand of this than 'stop_broadcast'. The latter merely says /how/ the cleanup is done.
Quoted 25 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)drivers/firewire/net.c +2
-2@@ -1106,7 +1106,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) ptrptr = kmalloc_array(num_packets, sizeof(*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; - goto failed; + goto stop_broadcast; } dev->broadcast_rcv_buffer_ptrs = ptrptr;@@ -1116,13 +1116,13 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) fwnet_receive_broadcast, dev);if (IS_ERR (context)) { retval =PTR_ERR (context); - goto failed; + goto stop_broadcast; }
[...]
drivers/firewire/net.c static int fwnet_broadcast_start(struct · line 1172
Quoted 10 lines
drivers/firewire/net.c +1
-2@@ -1166,8 +1166,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) dev->broadcast_state = FWNET_BROADCAST_RUNNING;return 0 ; - - failed: + stop_broadcast:__fwnet_broadcast_stop (dev);return retval; }
I see no reason to remove the blank line between the return statement and the label.
Signature · 3 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/
Re: [PATCH 01/10] firewire-net: Use kmalloc_array() in fwnet_broadcast_start()
In reply to Stefan RichterQuoted 12 lines
drivers/firewire/net.c static int fwnet_broadcast_start(struct fwnet_device *dev) · line 1109
Quoted 10 lines
drivers/firewire/net.c +1
-2@@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) max_receive =1U << (dev->card->max_receive +1 ); num_packets = (FWNET_ISO_PAGE_COUNT *PAGE_SIZE ) / max_receive; - - ptrptr =kmalloc (sizeof (void *) * num_packets,GFP_KERNEL ); + ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; goto failed;Coccinelle enabled you to determine that
kmalloc_array/could/ be used here.
A script for the semantic patch language pointed hundreds of source files out with such software update opportunities.
Quoted 2 lines
But whether it /should/ be used here is another question, and it is not addressed in your changelog.
I can expand the corresponding description when it will be desired.
Quoted 1 line
(You state that there is an "issue" but do not explain.)
Do you prefer an other wording for such an update candidate?
Quoted 4 lines
kmalloc_arrayis a kmalloc wrapper which adds an inline check for integer overflow. So, cansizeof(void *)*num_packetsever overflowsize_t?If yes,
Is there a probability that the calculated number of packets will become too big for the preferred system limits anyhow?
Quoted 1 line
do we want a runtime check here (which
kmalloc_arrayprovides),
Did you notice the information from the commit "mm: faster kmalloc_array(), kcalloc()" (from 2016-07-26) already?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id‘c6a05f72a996bee5133e76374ab3ad7d3b9b72
Quoted 1 line
or do we want a compile-time check?
I guess that some software developers and subsystem maintainers are looking for a bit more clarification around involved design dependencies.
Quoted 3 lines
If no,
then the remaining benefit of the patch is that it is more obvious to the reader that dev->broadcast_rcv_buffer_ptrs is an array,
How do you value such a kind of source code annotation?
Quoted 1 line
but possibly at the cost of superfluous code.
How do you think about to care for a bit more consistent use of Linux programming interfaces?
Quoted 2 lines
Is gcc's optimizer able to resolve kmalloc_array's check at compile time as always false, such that the superfluous code is eliminated as dead code?
Which versions of compiler implementations would you like to check further?
Quoted 2 lines
I believe I know answers to this but prefer to hear what you as the patch author think about it.
I presented another update suggestion also for this software module as a result from a general source code search pattern.
The corresponding change acceptance varies and is evolving as usual.
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jonathan Cameron
maintainerRe: [PATCH 2/7] iio: Rename a jump label in iio_buffer_store_watermark()
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 06:54:49 +0200Adjust jump labels according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>
I'm not necessarily against this change which does perhaps clarify the code ever so slightly, but I am interested to know where
'current Linux coding style convention' comes from?
Jonathan
Quoted 29 lines
--- drivers/iio/industrialio-buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/industrialio-buffer.c +3
-3@@ -1028,16 +1028,16 @@ static ssize_t iio_buffer_store_watermark(struct device *dev,if (val > buffer->length) { ret = -EINVAL ; - goto out; + goto unlock; }if (iio_buffer_is_active (indio_dev->buffer)) { ret = -EBUSY ; - goto out; + goto unlock; } buffer->watermark = val; -out: +unlock:mutex_unlock (&indio_dev->mlock);return ret ? ret : len;
Re: [PATCH 1/7] iio: Use kmalloc_array() in iio_scan_mask_set()
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 23 Sep 2016 22:30:32 +0200A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 23 lines
--- drivers/iio/industrialio-buffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/iio/industrialio-buffer.c +3
-4@@ -307,10 +307,9 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,const unsigned long *mask;unsigned long *trialmask; - trialmask =kmalloc (sizeof (*trialmask)* -BITS_TO_LONGS (indio_dev->masklength), -GFP_KERNEL ); - + trialmask =kmalloc_array (BITS_TO_LONGS (indio_dev->masklength), +sizeof (*trialmask), +GFP_KERNEL );if (trialmask =NULL )return -ENOMEM ;if (!indio_dev->masklength) {
Re: [PATCH 1/7] iio: Use kmalloc_array() in iio_scan_mask_set()
Quoted 2 lines
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks for your positive response.
Do you see any need to improve the software situation around the macro "BITS_TO_LONGS" further?
Do you fiddle with a programming interface like "bitmap_alloc" occasionally?
Regards,
Markus
Jonathan Cameron
maintainerRe: [PATCH 1/7] iio: Use kmalloc_array() in iio_scan_mask_set()
Quoted 10 lines · SF Markus Elfring
Quoted 2 lines
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks for your positive response.
Do you see any need to improve the software situation around the macro "
BITS_TO_LONGS" further?Do you fiddle with a programming interface like "
bitmap_alloc" occasionally?
It might be clearer than having an array allocation as we do after this patch. Obviously the representation is an array, but it is a little ugly as it stands!
Quoted 8 lines
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input-evdev: Rename a jump label in two functions
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 12:50:31 +0200Adjust a jump label according to the current Linux coding style convention. Thus replace the identifier "out" by "unlock".
No, just no.
Quoted 54 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/input/evdev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/input/evdev.c +5
-8@@ -545,22 +545,21 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,if (!evdev->exist || client->revoked) { retval = -ENODEV ; - goto out; + goto unlock; }while (retval +input_event_size () <= count) {if (input_event_from_user (buffer + retval, &event)) { retval = -EFAULT ; - goto out; + goto unlock; } retval +=input_event_size ();input_inject_event (&evdev->handle, event.type, event.code, event.value); } - - out: +unlock:mutex_unlock (&evdev->mutex);return retval; }@@ -1292,12 +1291,11 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,if (!evdev->exist || client->revoked) { retval = -ENODEV ; - goto out; + goto unlock; } retval =evdev_do_ioctl (file, cmd, p, compat_mode); - - out: +unlock:mutex_unlock (&evdev->mutex);return retval; } --2.10.0
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/2] Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 12:42:45 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 8 lines
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
* Delete the local variable "len" which became unnecessary with this refactoring.
So we have to multiply twice now, once in kmalloc_array, the second time in memcpy(). No, thank you.
Also, please note that we do not really treat the allocated "mem" as an array, but rather area of memory that holds all bits that we need to transfer, and so I consider using kmalloc_array() actually wrong here.
Please do not blindly follow checkpatch and coccinelle suggestions. They are just that: suggestions and not hared rules.
Thanks.
Signature · 1 line
Dmitry
Re: Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
Quoted 2 lines
So we have to multiply twice now, once in
kmalloc_array, the second time inmemcpy().
It looks so in the source code after the suggested refactoring.
Quoted 1 line
No, thank you.
Would you like to check any further if a specific compiler implementation will still optimise common subexpressions as you desired it?
Quoted 3 lines
Also, please note that we do not really treat the allocated "mem" as an array, but rather area of memory that holds all bits that we need to transfer, and so I consider using
kmalloc_array()actually wrong here.
Thanks for your explanation.
Quoted 2 lines
Please do not blindly follow checkpatch and coccinelle suggestions. They are just that: suggestions and not hared rules.
I am curious on how to clarify corresponding deviations further.
Would you like to suggest any other details so that the evolving scripts can become better and safer for static source code analysis?
Do you know any special properties which should be additionally checked at call sites which are similar to the discussed place?
Regards,
Markus
Dmitry Torokhov
maintainerRe: Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
Quoted 22 lines · SF Markus Elfring
Quoted 2 lines
So we have to multiply twice now, once in
kmalloc_array, the second time inmemcpy().It looks so in the source code after the suggested refactoring.
Quoted 1 line
No, thank you.
Would you like to check any further if a specific compiler implementation will still optimise common subexpressions as you desired it?
Quoted 3 lines
Also, please note that we do not really treat the allocated "mem" as an array, but rather area of memory that holds all bits that we need to transfer, and so I consider using
kmalloc_array()actually wrong here.Thanks for your explanation.
Quoted 2 lines
Please do not blindly follow checkpatch and coccinelle suggestions. They are just that: suggestions and not hared rules.
Quoted 8 lines
I am curious on how to clarify corresponding deviations further.
Would you like to suggest any other details so that the evolving scripts can become better and safer for static source code analysis?
Do you know any special properties which should be additionally checked at call sites which are similar to the discussed place?
If you are asking for some formal rules then no.
Again, what is the purpose of the changes? Are you working on the code and the fact that the driver is older-style hinders your progress? Or there are runtime improvements from your changes? Correctness issues?
I do not very much appreciate changes just to satisfy checkpatch rule du jour.
Thanks.
Signature · 1 line
Dmitry
Re: Input-evdev: Use kmalloc_array() in evdev_handle_get_val()
Quoted 1 line
Again, what is the purpose of the changes?
I came also along a few source code places where their maintainers requested the usage of a function like "kmalloc_array".
How do you think about to clarify the consistent use of programming interfaces for Linux a bit more?
Quoted 1 line
Are you working on the code
I am trying to improve various free software (including Linux).
Quoted 1 line
and the fact that the driver is older-style hinders your progress?
Not for me directly.
Quoted 1 line
Or there are runtime improvements from your changes?
It depends on some factors.
Can an array memory allocator organise the desired data in a safer and more efficient way than a "default approach"?
Quoted 1 line
Correctness issues?
This can be.
Do you care for source code annotations?
Quoted 2 lines
I do not very much appreciate changes just to satisfy checkpatch rule du jour.
Do these rules contain knowledge which you give a significant value?
Regards,
Markus
Re: iio: Rename a jump label in iio_buffer_store_watermark()
In reply to Jonathan CameronQuoted 2 lines
I'm not necessarily against this change which does perhaps clarify the code ever so slightly,
Thanks for another bit of positive feedback.
Quoted 1 line
but I am interested to know where 'current Linux coding style convention' comes from?
How often do you check the status of a document like "CodingStyle" for example? ;-)
How do you think about information from a commit like
"docs: Remove space-before-label guidance from CodingStyle" (on 2016-09-21)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817a
Regards,
Markus
Jonathan Cameron
maintainerRe: iio: Rename a jump label in iio_buffer_store_watermark()
Quoted 9 lines · SF Markus Elfring
Quoted 2 lines
I'm not necessarily against this change which does perhaps clarify the code ever so slightly,
Thanks for another bit of positive feedback.
Quoted 1 line
but I am interested to know where 'current Linux coding style convention' comes from?
How often do you check the status of a document like "CodingStyle" for example? ;-)
Every time I see a patch doing a style change I don't remember being there last time I looked ;)
I'm not seeing this one in there. Which tool is spitting it out? Or is the test yours?
Quoted 4 lines
How do you think about information from a commit like
"docs: Remove space-before-label guidance from CodingStyle" (on 2016-09-21)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817a
Yeah, I saw the discussion / flame war that resulted in that revert...
Quoted 4 lines
Regards,
Markus
Re: iio: Rename a jump label in iio_buffer_store_watermark()
Quoted 1 line
I'm not seeing this one in there.
How much do you care about selection of appropriate identifiers in source files?
Quoted 1 line
Which tool is spitting it out?
Are you looking for any special tool?
Quoted 1 line
Or is the test yours?
Which test do you mean?
Quoted 1 line
Yeah, I saw the discussion / flame war that resulted in that revert...
Would you like to share any more constructive ideas for this software evolution?
Regards,
Markus
Jonathan Cameron
maintainerRe: iio: Rename a jump label in iio_buffer_store_watermark()
Quoted 3 lines · SF Markus Elfring
Quoted 1 line
I'm not seeing this one in there.
How much do you care about selection of appropriate identifiers in source files?
It's not an inappropriate identifier as it stands. The point is that it could be better.
Quoted 5 lines
Quoted 3 lines
Which tool is spitting it out?
Are you looking for any special tool?
I was wondering how you identified these particular issues as I wanted to know the logic behind the test.
Quoted 5 lines
Quoted 3 lines
Or is the test yours?
Which test do you mean?
Whatever you used to find these jump labels (the patch series description suggested it was a static checker).
Quoted 5 lines
Quoted 3 lines
Yeah, I saw the discussion / flame war that resulted in that revert...
Would you like to share any more constructive ideas for this software evolution?
Not a lot of time at the moment, sorry.
Jonathan
Quoted 4 lines
Regards,
Markus
Jonathan Cameron
maintainerRe: [PATCH 7/7] iio: Adjust checks for null pointers in six functions
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 24 Sep 2016 08:00:07 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Quoted 7 lines
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
Signed-off-by Markus Elfring <[email protected]>
This is a more worthwhile change in my mind to the jump label changes. Would you mind resending with it not based on top of those?
Thanks,
Jonathan
Quoted 77 lines
--- drivers/iio/industrialio-buffer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/iio/industrialio-buffer.c +8
-8@@ -310,7 +310,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, trialmask =kmalloc_array (BITS_TO_LONGS (indio_dev->masklength),sizeof (*trialmask),GFP_KERNEL ); -if (trialmask =NULL ) +if (!trialmask)return -ENOMEM ;if (!indio_dev->masklength) {WARN (1 ,"Trying to set scanmask prior to registering buffer\n" );@@ -711,7 +711,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,/* What scan mask do we actually have? */ compound_mask =kcalloc (BITS_TO_LONGS (indio_dev->masklength),sizeof (long ),GFP_KERNEL ); -if (compound_mask =NULL ) +if (!compound_mask)return -ENOMEM ; scan_timestamp = false;@@ -736,7 +736,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, compound_mask, strict_scanmask);kfree (compound_mask); -if (scan_mask =NULL ) +if (!scan_mask)return -EINVAL ; }else { scan_mask = compound_mask;@@ -940,7 +940,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, goto out_unlock; } -if (indio_dev->info =NULL ) { +if (!indio_dev->info) { ret = -ENODEV ; goto out_unlock; }@@ -1130,11 +1130,11 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) indio_dev->scan_index_timestamp > channels[i].scan_index; } -if (indio_dev->masklength && buffer->scan_mask =NULL ) { +if (indio_dev->masklength && !buffer->scan_mask) { buffer->scan_mask =kcalloc (BITS_TO_LONGS (indio_dev->masklength),sizeof (*buffer->scan_mask),GFP_KERNEL ); -if (buffer->scan_mask =NULL ) { +if (!buffer->scan_mask) { ret = -ENOMEM ; goto error_cleanup_dynamic; }@@ -1146,7 +1146,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) buffer->scan_el_group.attrs =kcalloc (attrcount +1 ,sizeof (buffer->scan_el_group.attrs[0 ]),GFP_KERNEL ); -if (buffer->scan_el_group.attrs =NULL ) { +if (!buffer->scan_el_group.attrs) { ret = -ENOMEM ; goto error_free_scan_mask; }@@ -1291,7 +1291,7 @@ static int iio_buffer_add_demux(struct iio_buffer *buffer, (*p)->length += length; }else { *p =kmalloc (sizeof (**p),GFP_KERNEL ); -if (*p =NULL ) +if (!*p)return -ENOMEM ; (*p)->from = in_loc; (*p)->to = out_loc;
drivers/iio/industrialio-buffer.c static int iio_buffer_update_demux(struct iio_dev *indio_dev, · line 1362
Quoted 8 lines
drivers/iio/industrialio-buffer.c +1
-1@@ -1356,7 +1356,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev, in_loc += length; } buffer->demux_bounce =kzalloc (out_loc,GFP_KERNEL ); -if (buffer->demux_bounce =NULL ) { +if (!buffer->demux_bounce) { ret = -ENOMEM ; goto error_clear_mux_table; }
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: iio: Adjust checks for null pointers in six functions
Quoted 1 line
This is a more worthwhile change in my mind to the jump label changes.
Thanks for another bit of positive feedback for this refactoring.
Quoted 1 line
Would you mind resending with it not based on top of those?
Is a resend really needed?
Does the tool "Git" let you also apply this update step before the other suggestions?
Would you dare a reordering of items according to your change preferences?
Regards,
Markus
Re: iio: Rename a jump label in iio_buffer_store_watermark()
In reply to Jonathan CameronQuoted 2 lines
It's not an inappropriate identifier as it stands. The point is that it could be better.
Thanks for your interest in clarifying further improvement possibilities.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Which tool is spitting it out?
Are you looking for any special tool?
I was wondering how you identified these particular issues as I wanted to know the logic behind the test.
Do you get any related ideas from information in a message like "Source code review around jump label usage" (from 2015-12-11)?
https://lkml.org/lkml/2015/12/11/378
https://lkml.kernel.org/r/<[email protected]>
Quoted 2 lines
Quoted 1 line
Which test do you mean?
Whatever you used to find these jump labels
There is a general possibility that dedicated scripts for the semantic patch language can also adjust jump labels as I suggested it for five functions in this software.
Quoted 1 line
(the patch series description suggested it was a static checker).
The corresponding five patches are just a result of a source code review by the means of a current text editor wit extra support for programming.
How do you think about to improve the capabilities of tools for advanced static source code analysis any further?
Regards,
Markus
Jonathan Cameron
maintainerRe: iio: Rename a jump label in iio_buffer_store_watermark()
Quoted 27 lines · SF Markus Elfring
Quoted 2 lines
It's not an inappropriate identifier as it stands. The point is that it could be better.
Thanks for your interest in clarifying further improvement possibilities.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Which tool is spitting it out?
Are you looking for any special tool?
I was wondering how you identified these particular issues as I wanted to know the logic behind the test.
Do you get any related ideas from information in a message like "Source code review around jump label usage" (from 2015-12-11)?
https://lkml.org/lkml/2015/12/11/378
https://lkml.kernel.org/r/<[email protected]>Quoted 2 lines
Quoted 1 line
Which test do you mean?
Whatever you used to find these jump labels
There is a general possibility that dedicated scripts for the semantic patch language can also adjust jump labels as I suggested it for five functions in this software.
Quoted 4 lines
Quoted 1 line
(the patch series description suggested it was a static checker).
The corresponding five patches are just a result of a source code review by the means of a current text editor wit extra support for programming.
To my mind there is a divide between the cost of making changes like this as a result of initial review and that of doing it on existing code.
I don't think this one is worth while for existing code.
Quoted 11 lines
How do you think about to improve the capabilities of tools for advanced static source code analysis any further?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jonathan Cameron
maintainerRe: iio: Adjust checks for null pointers in six functions
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 1 line
This is a more worthwhile change in my mind to the jump label changes.
Thanks for another bit of positive feedback for this refactoring.
Quoted 1 line
Would you mind resending with it not based on top of those?
Is a resend really needed?
It's a question of time. Maintainers regularly push back stuff they could fix up themselves purely to save their time.
Also, I'm afraid I don't care enough to put the time in for this one. I care enough to review / apply the patch though.
Quoted 3 lines
Does the tool "Git" let you also apply this update step before the other suggestions?
It rarely copes with this sort of reordering as it doesn't have the semantic knowledge of what matters in the other patches.
Quoted 6 lines
Would you dare a reordering of items according to your change preferences?
Regards,
Markus
Re: iio: Rename a jump label in iio_buffer_store_watermark()
In reply to Jonathan CameronQuoted 2 lines
To my mind there is a divide between the cost of making changes like this as a result of initial review and that of doing it on existing code.
I can follow this view.
Quoted 1 line
I don't think this one is worth while for existing code.
How do you think about once more to increase the usage of the jump label "unlock" also for this software module?
Regards,
Markus
Re: iio: Adjust checks for null pointers in six functions
In reply to Jonathan CameronQuoted 1 line
Also, I'm afraid I don't care enough to put the time in for this one.
It's a pity.
Quoted 4 lines
Quoted 2 lines
Does the tool "Git" let you also apply this update step before the other suggestions?
It rarely copes with this sort of reordering as it doesn't have the semantic knowledge of what matters in the other patches.
I assume that the involved software developers got a specific impression about the discussed patch series for this software module so that a few relevant dependencies became clearer eventually.
I proposed some update steps where I chose a specific patch granularity once more. So I imagine that a bit of variation in the patch order could be supported already.
Will it be possible to apply also this one a bit later just because the patch hunk contexts might be still valid in the (near) future?
Regards,
Markus
Re: iio: Adjust checks for null pointers in six functions
Quoted 10 lines · SF Markus Elfring
I assume that the involved software developers got a specific impression about the discussed patch series for this software module so that a few relevant dependencies became clearer eventually.
I proposed some update steps where I chose a specific patch granularity once more. So I imagine that a bit of variation in the patch order could be supported already.
Will it be possible to apply also this one a bit later just because the patch hunk contexts might be still valid in the (near) future?
I wonder if you realize that your postings _reek_ with the Strong Programme intellectual offal... Are you, by any chance, some kind of sociology grad? You can't study development purely on the process level, ignoring the actual usefulness of contributions and the fact that there are objective criteria of their worth.
Re: iio: Adjust checks for null pointers in six functions
Quoted 1 line
Are you, by any chance, some kind of sociology grad?
Not yet. ;-) - It looks also unlikely at the moment that my life will evolve
in such direction.
Quoted 1 line
You can't study development purely on the process level,
I find that I am not studying this topic. Am I practically contributing small improvements to free software (including Linux) for years?
Quoted 1 line
ignoring the actual usefulness of contributions
I guess their usefulness is varying over time.
Quoted 1 line
and the fact that there are objective criteria of their worth.
Are there any source code quality goals left over which would be nice to achieve also for this software module?
Regards,
Markus
Re: [1/3] hostap: Use memdup_user() rather than duplicating its implementation
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 18:19:43 +0200Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Patch set to Rejected.
[1/3] hostap: Use memdup_user() rather than duplicating i... 2016-08-20 SF Markus El Rejected
Reason: A similar patch is already applied.
Applying: hostap: Use memdup_user() rather than duplicating its implementation Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging drivers/net/wireless/intersil/hostap/hostap_ioctl.c
CONFLICT (content): Merge conflict in drivers/net/wireless/intersil/hostap/hostap_ioctl.c Failed to merge in the changes.
Patch failed at 0001 hostap: Use memdup_user() rather than duplicating its implementation
Signature · 6 lines
https://patchwork.kernel.org/patch/9306999/ Documentation about submitting wireless patches and checking status from patchwork: https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Re: [2/3] hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 18:21:29 +0200Remove a jump label which is unneeded in this function at the end.
Signed-off-by Markus Elfring <[email protected]>
2 patches set to Rejected.
9291771 [2/3] hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd() 9291775 [3/3] hostap: Delete unnecessary initialisations for the variable "ret"
Reason: The benefit is not clear.
Signature · 6 lines
https://patchwork.kernel.org/patch/9291771/ Documentation about submitting wireless patches and checking status from patchwork: https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
cover ISDN-Gigaset: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 17:27:17 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Use kmalloc_array() in two functions
Improve another size determination in gigaset_initcs() Delete an error message for a failed memory allocation Release memory in gigaset_initcs() after an allocation failure Enclose two expressions for the sizeof operator by parentheses
drivers/isdn/gigaset/common.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/5 ISDN-Gigaset: Use kmalloc_array() in two functions
From: Markus Elfring <[email protected]>
Date: Sun, 25 Sep 2016 22:22:04 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/isdn/gigaset/common.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/isdn/gigaset/common.c +2 -4
@@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, cs->mode =M_UNKNOWN ; cs->mstate =MS_UNINITIALIZED ; - - cs->bcs =kmalloc (channels *sizeof (struct bc_state ),GFP_KERNEL ); + cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL ); cs->inbuf =kmalloc (sizeof (struct inbuf_t ),GFP_KERNEL );if (!cs->bcs || !cs->inbuf) {pr_err ("out of memory\n" );
@@ -1089,8 +1088,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, drv->ops = ops; drv->owner = owner;INIT_LIST_HEAD (&drv->list); - - drv->cs =kmalloc (minors *sizeof *drv->cs,GFP_KERNEL ); + drv->cs =kmalloc_array (minors,sizeof (*drv->cs),GFP_KERNEL );if (!drv->cs) goto error;
Signature · 1 line
2.10.0
PATCH 2/5 ISDN-Gigaset: Improve another size determination in gigaset_initcs()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 25 Sep 2016 22:32:14 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/isdn/gigaset/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/isdn/gigaset/common.c +1 -1
@@ -710,7 +710,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, cs->mode =M_UNKNOWN ; cs->mstate =MS_UNINITIALIZED ; cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL ); - cs->inbuf =kmalloc (sizeof (struct inbuf_t ),GFP_KERNEL ); + cs->inbuf =kmalloc (sizeof (*cs->inbuf),GFP_KERNEL );if (!cs->bcs || !cs->inbuf) {pr_err ("out of memory\n" ); goto error;
Signature · 1 line
2.10.0
PATCH 3/5 ISDN-Gigaset: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 15:35:47 +0200
Omit an extra message for a memory allocation failure in this function.
--- drivers/isdn/gigaset/common.c | 1 - 1 file changed, 1 deletion(-)
drivers/isdn/gigaset/common.c +0 -1
@@ -712,7 +712,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL ); cs->inbuf =kmalloc (sizeof (*cs->inbuf),GFP_KERNEL );if (!cs->bcs || !cs->inbuf) { -pr_err ("out of memory\n" ); goto error; } ++cs->cs_init;
Signature · 1 line
2.10.0
PATCH 4/5 ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 16:30:50 +0200
Memory was not released (as it would be expected) when one call of further resource reservations failed.
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
* Adjust jump targets according to the Linux coding style convention.
--- drivers/isdn/gigaset/common.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/isdn/gigaset/common.c +12 -8
@@ -710,10 +710,13 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, cs->mode =M_UNKNOWN ; cs->mstate =MS_UNINITIALIZED ; cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL ); +if (!cs->bcs) + goto report_failure; + cs->inbuf =kmalloc (sizeof (*cs->inbuf),GFP_KERNEL ); -if (!cs->bcs || !cs->inbuf) { - goto error; - } +if (!cs->inbuf) + goto free_bcs; + ++cs->cs_init;gig_dbg (DEBUG_INIT ,"setting up at_state" );
@@ -737,14 +740,14 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,gig_dbg (DEBUG_INIT ,"setting up iif" );if (gigaset_isdn_regdev (cs, modulename) <0 ) {pr_err ("error registering ISDN device\n" ); - goto error; + goto free_bcs; }make_valid (cs,VALID_ID ); ++cs->cs_init;gig_dbg (DEBUG_INIT ,"setting up hw" );if (cs->ops->initcshw (cs) <0 ) - goto error; + goto free_bcs; ++cs->cs_init;
@@ -759,7 +762,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,gig_dbg (DEBUG_INIT ,"setting up bcs[%d]" , i);if (gigaset_initbcs (cs->bcs + i, cs, i) <0 ) {pr_err ("could not allocate channel %d data\n" , i); - goto error; + goto free_bcs; } }
@@ -772,8 +775,9 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,gig_dbg (DEBUG_INIT ,"cs initialized" );return cs; - -error: +free_bcs: +kfree (cs->bcs); +report_failure:gig_dbg (DEBUG_INIT ,"failed" );gigaset_freecs (cs);return NULL ;
Signature · 1 line
2.10.0
PATCH 5/5 ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 17:03:56 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
WARNING: sizeof … should be sizeof(…)
Thus fix the affected source code places.
--- drivers/isdn/gigaset/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/isdn/gigaset/common.c +2 -2
@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );unsigned char *out = outbuf;size_t numin = len;
@@ -1079,7 +1079,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,unsigned long flags;unsigned i; - drv =kmalloc (sizeof *drv,GFP_KERNEL ); + drv =kmalloc (sizeof (*drv),GFP_KERNEL );if (!drv)return NULL ;
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
From: SF Markus Elfring
Quoted 1 line
Sent: 26 September 2016 16:45
...
Quoted 3 lines
The script "checkpatch.pl" can point information out like the following.
WARNING: sizeof … should be sizeof(…)
...
Quoted 9 lines
--- drivers/isdn/gigaset/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/isdn/gigaset/common.c +0
-0
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 5 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );
wrong ...
think that is 7 instead of 79.
David
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
In reply to a message not in the archiveQuoted 4 lines
9291771 [2/3] hostap: Delete an unnecessary jump label in
prism2_ioctl_priv_hostapd()9291775 [3/3] hostap: Delete unnecessary initialisations for the variable "ret"Reason: The benefit is not clear.
How do you think about to reduce the source code a bit at these places?
Regards,
Markus
Joe Perches
maintainerRe: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to David LaightQuoted 5 lines · David Laight
From: SF Markus Elfring Sent: 26 September 2016 16:45
Quoted 2 lines
The script "checkpatch.pl" can point information out like the following.
WARNING: sizeof … should be sizeof(…)[]
drivers/isdn/gigaset/common.c
Quoted 1 line
drivers/isdn/gigaset/common.c +0
-0
[]
Quoted 9 lines
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, { unsigned char outbuf[80]; unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );wrong ...
think that is 7 instead of 79.
Well, it's sizeof(pointer) so either 4 or 8, but still, what Markus proposes here is _wrong_.
Markus, do you know the script probably has a lower style conversion defect introduction rate than you do when doing these mechanical things.
Please use it to verify what you are doing before submitting more defective patches.
Excuses and apologies aren't good enough at this point.
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
Quoted 11 lines
Quoted 9 lines
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );wrong ...
think that is 7 instead of 79.
Quoted 2 lines
Well, it's sizeof(pointer) so either 4 or 8, but still, what Markus proposes here is _wrong_.
You are right at this place.
Quoted 3 lines
Markus, do you know the script probably has a lower style conversion defect introduction rate than you do when doing these mechanical things.
Would it be nice if the script "checkpatch.pl" could avoid to point such a false positive out anyhow?
Quoted 2 lines
Please use it to verify what you are doing before submitting more defective patches.
Do you expect a resend for this update step so that an other statement in the function "gigaset_initdriver" would eventually be adjusted?
Regards,
Markus
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
Quoted 17 lines · SF Markus Elfring
Quoted 11 lines
Quoted 9 lines
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );wrong ...
think that is 7 instead of 79.Quoted 2 lines
Well, it's sizeof(pointer) so either 4 or 8, but still, what Markus proposes here is _wrong_.
You are right at this place.
Quoted 6 lines
Quoted 3 lines
Markus, do you know the script probably has a lower style conversion defect introduction rate than you do when doing these mechanical things.
Would it be nice if the script "checkpatch.pl" could avoid to point such a false positive out anyhow?
checkpatch reports:
WARNING: sizeof outbuf should be sizeof(outbuf)
#56: FILE: drivers/isdn/gigaset/common.c:56:
+ size_t space = sizeof outbuf - 1;
There is nothing wrong with the report,
julia
Quoted 15 lines
Quoted 4 lines
Please use it to verify what you are doing before submitting more defective patches.
Do you expect a resend for this update step so that an other statement in the function "
gigaset_initdriver" would eventually be adjusted?Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Vinod Koul
AppliedRe: [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:56:56 +0200Several update suggestions were taken into account from static source code analysis.
Applied all, thanks
Signature · 1 line
~Vinod
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringHello.
Quoted 22 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 17:03:56 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThe script "checkpatch.pl" can point information out like the following.
WARNING: sizeof … should be sizeof(…)
Thus fix the affected source code places.
Signed-off-by Markus Elfring <[email protected]>--- drivers/isdn/gigaset/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/isdn/gigaset/common.c +0
-0
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 5 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );
What?! Does that compile?
[...]
MBR, Sergei
PATCH v2 5/5 ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to Joe PerchesFrom: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 19:34:27 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
WARNING: sizeof … should be sizeof(…)
Thus fix the affected source code places.
---
v2: Position the desired closing parenthesis behind the variable name for
a character buffer.
drivers/isdn/gigaset/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/isdn/gigaset/common.c +2 -2
@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf) -1 ;unsigned char *out = outbuf;size_t numin = len;
@@ -1079,7 +1079,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,unsigned long flags;unsigned i; - drv =kmalloc (sizeof *drv,GFP_KERNEL ); + drv =kmalloc (sizeof (*drv),GFP_KERNEL );if (!drv)return NULL ;
Signature · 1 line
2.10.0
Re: ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to Sergei ShtylyovQuoted 8 lines
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );What?! Does that compile?
Yes, of course. - The calculated value will be lower than intended.
Unfortunately, I stumbled on one of my own programming mistakes once again.
I sent a corrected update suggestion for further considerations a few minutes ago.
Regards,
Markus
Re: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
Quoted 4 lines
9291771 [2/3] hostap: Delete an unnecessary jump label in
prism2_ioctl_priv_hostapd()9291775 [3/3] hostap: Delete unnecessary initialisations for the variable "ret"Reason: The benefit is not clear.
How do you think about to reduce the source code a bit at these places?
hostap is an obsolete driver, it's waste of time doing style fixes to it as nobody maintains it anymore.
Signature · 1 line
Kalle Valo
Re: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
Quoted 2 lines
hostap is an obsolete driver, it's waste of time doing style fixes to it as nobody maintains it anymore.
Thanks for another bit of your software development attention and this information.
Is it easier to understand than the previous response "Reason: The benefit is not clear."?
Regards,
Markus
Joe Perches
maintainerRe: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
In reply to Kalle ValoQuoted 2 lines · Kalle Valo
hostap is an obsolete driver, it's waste of time doing style fixes to it as nobody maintains it anymore.
Dunno know if Jouni is still maintaining this at all but maybe a MAINTAINERS update to mark it obsolete so checkpatch warns on unnecessary changes.
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -5722,7 +5722,7 @@ M: Jouni Malinen L: [email protected] (subscribers-only) L: [email protected] W: http://hostap.epitest.fi/ -S: Maintained +S: Maintained / Obsolete F: drivers/net/wireless/intersil/hostap/ HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringQuoted 2 lines · SF Markus Elfring
v2: Position the desired closing parenthesis behind the variable name for a character buffer.
Please wait a reasonable amount of time (say a week or two) to collect all feedback on all patches of a series. If there's feedback you should resend the entire series (minus those patches that have been NAK-ed, of course) as an update (v2, v3, etc.).
Don't resubmit one single patch of a series (within hours!) as you did here.
I hope to have a look at your series within a few days. Show some patience.
Thanks,
Paul Bolle
Re: ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringWhere did the [PATCH 5/5] part of the subject go? You didn't drop it, did you? Because that's surprisingly annoying.
Paul Bolle
Re: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
In reply to Joe PerchesQuoted 16 lines · Joe Perches
Quoted 2 lines · Kalle Valo
hostap is an obsolete driver, it's waste of time doing style fixes to it as nobody maintains it anymore.
Dunno know if Jouni is still maintaining this at all but maybe a
MAINTAINERSupdate to mark it obsolete so checkpatch warns on unnecessary changes.--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)MAINTAINERS +0
-0
MAINTAINERS M: Jouni Malinen · line 5726
Quoted 6 lines
MAINTAINERS +1
-1@@ -5722,7 +5722,7 @@ M: Jouni Malinen L: [email protected] (subscribers-only) L: [email protected] W: http://hostap.epitest.fi/ -S: Maintained +S: Maintained / Obsolete F: drivers/net/wireless/intersil/hostap/
I talked with Jouni and we concluded marking this fully obsolete is the best (so removing the "Maintained" part completely). Also the shmoo list is not used anymore, that can be removed.
Signature · 1 line
Kalle Valo
Joe Perches
maintainerRe: hostap: Delete an unnecessary jump label in prism2_ioctl_priv_hostapd()
Quoted 3 lines · Kalle Valo
I talked with Jouni and we concluded marking this fully obsolete is the best (so removing the "Maintained" part completelo the shmoo list is not used anymore, that can be removed.
Well, it would be best if Jouni submitted something.
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to Paul BolleQuoted 2 lines
Don't resubmit one single patch of a series (within hours!) as you did here.
I hope that I could reduce the confusion a bit which I introduced with a change in the last step of my questionable update suggestion.
Quoted 2 lines
I hope to have a look at your series within a few days. Show some patience.
Yes, of course.
Regards,
Markus
Re: [PATCH 0/5] ISDN-Gigaset: Fine-tuning for three function implementations
In reply to SF Markus ElfringQuoted 11 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 17:27:17 +0200Some update suggestions were taken into account
from static source code analysis.Markus Elfring (5):
Usekmalloc_array()in two functions
Improve another size determination ingigaset_initcs()Delete an error message for a failed memory allocation Release memory ingigaset_initcs()after an allocation failure
Which "static source code analysis" was used for that discovery?
Quoted 4 lines
Enclose two expressions for the sizeof operator by parentheses
drivers/isdn/gigaset/common.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
Paul Bolle
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringMarkus,
Quoted 2 lines · SF Markus Elfring
Memory was not released (as it would be expected) when one call of further resource reservations failed.
This was the only thing in this series that triggered more than a, very uninspired, "meh" on first read.
Quoted 6 lines
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
A quick scan of that link suggests we can do without the above "background information" in the commit explanation.
Quoted 1 line
* Adjust jump targets according to the Linux coding style convention.
Another "meh".
Quoted 62 lines
Signed-off-by Markus Elfring <[email protected]>---
drivers/isdn/gigaset/common.c | 20 ++++++++++++--------1 file changed, 12 insertions(+), 8 deletions(-)drivers/isdn/gigaset/common.c +6
-3@@ -710,10 +710,13 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, cs->mode = M_UNKNOWN; cs->mstate = MS_UNINITIALIZED; cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL ); +if (!cs->bcs) + goto report_failure; + cs->inbuf = kmalloc(sizeof(*cs->inbuf), GFP_KERNEL); -if (!cs->bcs || !cs->inbuf) { - goto error; - } +if (!cs->inbuf) + goto free_bcs; + ++cs->cs_init;
gig_dbg(DEBUG_INIT, "setting up at_state");drivers/isdn/gigaset/common.c +1
-1@@ -737,14 +740,14 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, gig_dbg(DEBUG_INIT, "setting up iif"); if (gigaset_isdn_regdev(cs, modulename) < 0) { pr_err("error registering ISDN device\n"); - goto error; + goto free_bcs; }
make_valid(cs, VALID_ID);
++cs->cs_init;
gig_dbg(DEBUG_INIT, "setting up hw");
if (cs->ops->initcshw(cs)< 0)drivers/isdn/gigaset/common.c +1
-1- goto error; + goto free_bcs;
++cs->cs_init;drivers/isdn/gigaset/common.c +1
-1@@ -759,7 +762,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, gig_dbg(DEBUG_INIT, "setting up bcs[%d]", i); if (gigaset_initbcs(cs->bcs + i, cs, i) < 0) {pr_err ("could not allocate channel %d data\n" , i); - goto error; + goto free_bcs; } }drivers/isdn/gigaset/common.c +0
-0@@ -772,8 +775,9 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
gig_dbg(DEBUG_INIT, "cs initialized");
return cs;drivers/isdn/gigaset/common.c +3
-2- -error: +free_bcs: +kfree (cs->bcs); +report_failure:
Quoted 2 lines
gig_dbg(DEBUG_INIT, "failed");
gigaset_freecs(cs);
gigaset_freecs() is not a function I look at for the fun of it. But still, in it we find:
case 0: /* error in basic setup */ [...] kfree(cs->inbuf); kfree(cs->bcs);
As far as I can tell we will call those two kfree()'s if we jump to "error". So, contrary to your analysis, I don't think we leak cs->bcs.
Quoted 1 line
return NULL;
Paul Bolle
David Miller
maintainerRe: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringWhen you need to make changes to patches that are part of a series, you must resubmit the entire series, not just the things that are changes.
Re: ISDN-Gigaset: Fine-tuning for three function implementations
In reply to Paul BolleQuoted 6 lines
Quoted 4 lines
Use
kmalloc_array()in two functions
Improve another size determination ingigaset_initcs()Delete an error message for a failed memory allocation Release memory ingigaset_initcs()after an allocation failureWhich "static source code analysis" was used for that discovery?
Are you eventually asking more for the development tools which were involved here?
* Coccinelle software
* Script "checkpatch.pl"
* My own eyes with help of a current text editor and its programming support
Regards,
Markus
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to Paul BolleQuoted 5 lines
Quoted 2 lines
Memory was not released (as it would be expected) when one call of further resource reservations failed.
This was the only thing in this series that triggered more than a, very uninspired, "meh" on first read.
Will it matter here if the function "kfree" will be called for the data structure members "bcs" and "inbuf" after a later function call failed within the implementation of "gigaset_initcs"?
Regards,
Markus
Re: [PATCH v2 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to David MillerQuoted 2 lines
When you need to make changes to patches that are part of a series, you must resubmit the entire series,
I imagine that will happen when the patch review time passed by a bit more as Paul Bolle requested it yesterday.
Quoted 1 line
not just the things that are changes.
Thanks for your reminder.
Regards,
Markus
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to Sergei ShtylyovQuoted 10 lines · Sergei Shtylyov
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );What?! Does that compile?
[...]
It prints a Smatch warning. Smatch ignores these if they happen inside a macro where you pass a pointer and it takes the sizeof() the argument.
regards,
dan carpenter
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringThis patch creates new bugs.
I have a policy of not telling Markus where the bug is, because otherwise he'll just resend the patch and I have told him many times to stop sending these cleanup patches that just introduce bugs and waste maintainer time.
regards,
dan carpenter
Re: [PATCH 5/5] ISDN-Gigaset: Enclose two expressions for the sizeof operator by parentheses
In reply to Dan CarpenterQuoted 10 lines · Dan Carpenter
Quoted 9 lines · Sergei Shtylyov
drivers/isdn/gigaset/common.c void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, · line 56
Quoted 6 lines
drivers/isdn/gigaset/common.c +1
-1@@ -53,7 +53,7 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, {unsigned char outbuf[80 ];unsigned char c; -size_t space =sizeof outbuf -1 ; +size_t space =sizeof (outbuf -1 );What?! Does that compile?
Quoted 4 lines
Quoted 1 line
[...]
It prints a Smatch warning. Smatch ignores these if they happen inside a macro where you pass a pointer and it takes the
sizeof()the argument.
Reading that again, I realize it's not clear. Smatch ignores these any time they happen in a macro whether they're valid or not. (Many times they are valid).
regards,
dan carpenter
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to Dan CarpenterQuoted 1 line
This patch creates new bugs.
Thanks for your information.
Quoted 1 line
I have a policy of not telling Markus where the bug is,
I find this kind of response strange.
Quoted 1 line
because otherwise he'll just resend the patch
This can also happen when the other contributors request it.
Quoted 1 line
and I have told him many times to stop sending these cleanup patches
Software "cleanups" seem to stress the review process to some degree.
Quoted 1 line
that just introduce bugs and waste maintainer time.
I guess that the situation is mixed depending on the subsystem or concrete software module, isn't it?
Regards,
Markus
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to Paul BolleAh well... Someone else discovered the double free bug first and gave it away. Reassuring, I guess.
regards,
dan carpenter
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
Will it matter here if the function "kfree" will be called for the data structure members "bcs" and "inbuf" after a later function call failed within the implementation of "
gigaset_initcs"?
My translation of this question is: could you please hold my hand while I read the code of a driver I do not use - a driver for hardware that I don't even have, and therefor cannot really test - after I submitted a patch that appears to be broken?
My answer to that question is: no, sorry, I won't do that.
Paul Bolle
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
Quoted 8 lines
Quoted 3 lines
Will it matter here if the function "kfree" will be called for the data structure members "bcs" and "inbuf" after a later function call failed within the implementation of "
gigaset_initcs"?My translation of this question is: could you please hold my hand while I read the code of a driver I do not use - a driver for hardware that I don't even have, and therefor cannot really test - after I submitted a patch that appears to be broken?
I got the impression that the exception handling was incomplete in the implementation of the function "gigaset_initcs".
Does anybody (besides me) care for improving the software situation there?
Quoted 1 line
My answer to that question is: no, sorry, I won't do that.
I find that the process has just started once more to clarify in which directions this software module could evolve.
Do we discuss a potential memory leak under special conditions here?
Regards,
Markus
Re: ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringHi,
as longtime maintainer of the code in question I feel compelled to chime in at this point.
Quoted 11 lines · SF Markus Elfring
Quoted 8 lines
Quoted 3 lines
Will it matter here if the function "kfree" will be called for the data structure members "bcs" and "inbuf" after a later function call failed within the implementation of "
gigaset_initcs"?My translation of this question is: could you please hold my hand while I read the code of a driver I do not use - a driver for hardware that I don't even have, and therefor cannot really test - after I submitted a patch that appears to be broken?
I got the impression that the exception handling was incomplete in the implementation of the function "
gigaset_initcs".
That impression is wrong. Careful reading of the code will confirm that.
Quoted 2 lines
Does anybody (besides me) care for improving the software situation there?
There's no urgent need for improvement. The code is stable and there's no demonstrated bug to be fixed.
You could improve the coding style, but that is of secondary importance, and if you want to do that, as a minimum you have to make sure that you don't introduce new bugs.
Thanks,
Tilman
Signature · 2 lines
Tilman Schmidt [email protected]
Re: [PATCH 3/5] ISDN-Gigaset: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 26 Sep 2016 15:35:47 +0200Omit an extra message for a memory allocation failure in this function.
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdfSigned-off-by Markus Elfring <[email protected]>
The patch is fine but the link in the commit message is irrelevant. Please remove it.
(Yes, I read through the whole presentation to verify that. It was fun, even.)
Signature · 2 lines
Tilman Schmidt [email protected]
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to Tilman SchmidtQuoted 4 lines
Quoted 2 lines
I got the impression that the exception handling was incomplete in the implementation of the function "
gigaset_initcs".That impression is wrong. Careful reading of the code will confirm that.
* Is it still correct nowadays that the function "gigaset_initcs" did not call the function "kfree" after a later function call failed?
* Do you expect that allocated memory will be automatically reclaimed after it would return a null pointer?
Regards,
Markus
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
Quoted 7 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
I got the impression that the exception handling was incomplete in the implementation of the function "
gigaset_initcs".That impression is wrong. Careful reading of the code will confirm that.
* Is it still correct nowadays that the function "
gigaset_initcs" did not call the function "kfree" after a later function call failed?
Wrong premise. That statement was never correct.
Quoted 2 lines
* Do you expect that allocated memory will be automatically reclaimed after it would return a null pointer?
No. Should I? Do you?
Regards,
Tilman
Signature · 2 lines
Tilman Schmidt [email protected]
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to SF Markus ElfringAm 27.09.2016 um 13:32 schrieb SF Markus Elfring:
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I got the impression that the exception handling was incomplete in the implementation of the function "
gigaset_initcs".That impression is wrong. Careful reading of the code will confirm that.
* Is it still correct nowadays that the function "
gigaset_initcs" did not call the function "kfree" after a later function call failed?
Yes, if it is handled in another place, Paul already did show you the place.
Quoted 3 lines
* Do you expect that allocated memory will be automatically reclaimed after it would return a null pointer?
Of course not
Best regards
Karsten
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
Quoted 4 lines
Quoted 2 lines
* Is it still correct nowadays that the function "
gigaset_initcs" did not call the function "kfree" after a later function call failed?Yes, if it is handled in another place, Paul already did show you the place.
To which source code place do you refer here?
Quoted 4 lines
Quoted 3 lines
* Do you expect that allocated memory will be automatically reclaimed after it would return a null pointer?
Of course not
Thanks for this acknowledgement.
Regards,
Markus
Re: [Gigaset307x-common] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
* Is it still correct nowadays that the function "
gigaset_initcs" did not call the function "kfree" after a later function call failed?Yes, if it is handled in another place, Paul already did show you the place.
To which source code place do you refer here?
Obviously the one Paul pointed out to you in detail in his mail dated Mon, 26 Sep 2016 23:13:54 +0200.
HTH,
Tilman
Signature · 2 lines
Tilman Schmidt [email protected]
Re: [PATCH 4/5] ISDN-Gigaset: Release memory in gigaset_initcs() after an allocation failure
In reply to Paul BolleQuoted 15 lines
drivers/isdn/gigaset/common.c struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, · line 782
Quoted 11 lines
drivers/isdn/gigaset/common.c +3
-2@@ -772,8 +775,9 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,gig_dbg (DEBUG_INIT ,"cs initialized" );return cs; - -error: +free_bcs: +kfree (cs->bcs); +report_failure:gig_dbg (DEBUG_INIT ,"failed" );gigaset_freecs (cs);
gigaset_freecs()is not a function I look at for the fun of it. But still, in it we find:
Quoted 7 lines
case 0: /* error in basic setup */ [...] kfree(cs->inbuf); kfree(cs->bcs);As far as I can tell we will call those two kfree()'s if we jump to "error". So, contrary to your analysis, I don't think we leak
cs->bcs.
You are right.
Thanks that you pointed this source code place out again.
I imagined that the exception handling implementation could be more direct somehow for a while. But this function takes extra care for data synchronisation by a mutex.
Now I recognise also that this proposed update step "4" was inappropriate. I'm sorry for the confusion I introduced here.
Regards,
Markus
cover md/bitmap: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 18:29:08 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (16):
Use kmalloc_array() in bitmap_storage_alloc()
Move an assignment for the variable "offset" in bitmap_storage_alloc() Delete an unnecessary variable initialisation in bitmap_storage_alloc() Improve another size determination in bitmap_storage_alloc() Return directly after a failed bitmap_storage_alloc() in bitmap_resize() Return directly after a failed kzalloc() in bitmap_resize() Replace a kzalloc() call by kcalloc() in bitmap_resize() Rename a jump label in location_store()
Rename a jump label in bitmap_copy_from_slot()
Rename a jump label in bitmap_create()
Rename a jump label in bitmap_init_from_disk()
One check less in read_page() at the end
Adjust checks for null pointers in 11 functions
Delete unnecessary braces in bitmap_resize()
Add spaces around three comparison operators
Delete an unwanted space in read_sb_page()
drivers/md/bitmap.c | 110 +++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 58 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/16 md/bitmap: Use kmalloc_array() in bitmap_storage_alloc()
From: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 13:01:07 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bitmap.c +3 -3
@@ -760,9 +760,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store, num_pages =DIV_ROUND_UP (bytes,PAGE_SIZE ); offset = slot_number * num_pages; - - store->filemap =kmalloc (sizeof (struct page *) - * num_pages,GFP_KERNEL ); + store->filemap =kmalloc_array (num_pages, +sizeof (*store->filemap), +GFP_KERNEL );if (!store->filemap)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/16 md/bitmap: Move an assignment for the variable "offset" in bitmap_storage_alloc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 13:10:05 +0200
Move the assignment for the local variable "offset" behind the source code for memory allocations by this function.
--- drivers/md/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bitmap.c +1 -1
@@ -759,7 +759,6 @@ static int bitmap_storage_alloc(struct bitmap_storage *store, bytes +=sizeof (bitmap_super_t); num_pages =DIV_ROUND_UP (bytes,PAGE_SIZE ); - offset = slot_number * num_pages; store->filemap =kmalloc_array (num_pages,sizeof (*store->filemap),GFP_KERNEL );
@@ -772,6 +771,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,return -ENOMEM ; } + offset = slot_number * num_pages; pnum =0 ;if (store->sb_page) { store->filemap[0 ] = store->sb_page;
Signature · 1 line
2.10.0
PATCH 3/16 md/bitmap: Delete an unnecessary variable initialisation in bitmap_storage_alloc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 13:20:23 +0200
The local variable "offset" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bitmap.c +1 -1
@@ -750,7 +750,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store, unsigned long chunks, int with_super, int slot_number) { - int pnum, offset = 0; + int pnum, offset;unsigned long num_pages;unsigned long bytes;
Signature · 1 line
2.10.0
PATCH 4/16 md/bitmap: Improve another size determination in bitmap_storage_alloc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 14:19:00 +0200
Replace the specification of a data type by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bitmap.c +3 -3
@@ -791,9 +791,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,/* We need 4 bits per page, rounded up to a multiple * of sizeof(unsigned long) */ - store->filemap_attr =kzalloc ( -roundup (DIV_ROUND_UP (num_pages*4 ,8 ),sizeof (unsigned long )), -GFP_KERNEL ); + store->filemap_attr =kzalloc (roundup (DIV_ROUND_UP (num_pages *4 ,8 ), +sizeof (*store->filemap_attr)), +GFP_KERNEL );if (!store->filemap_attr)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 5/16 md/bitmap: Return directly after a failed bitmap_storage_alloc() in bitmap_resize()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 14:47:29 +0200
Return directly after a memory allocation failed in this function at the beginning.
--- drivers/md/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bitmap.c +1 -1
@@ -2032,7 +2032,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,mddev_is_clustered (bitmap->mddev) ? bitmap->cluster_slot : 0);if (ret) - goto err; +return ret; pages =DIV_ROUND_UP (chunks,PAGE_COUNTER_RATIO );
Signature · 1 line
2.10.0
PATCH 6/16 md/bitmap: Return directly after a failed kzalloc() in bitmap_resize()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:21:23 +0200
* Return directly after a call of the function "kzalloc" failed here.
* Delete two assignments for the local variable "ret" and the jump target "err" which became unnecessary with this refactoring.
--- drivers/md/bitmap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/md/bitmap.c +1 -4
@@ -2037,10 +2037,9 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks, pages =DIV_ROUND_UP (chunks,PAGE_COUNTER_RATIO ); new_bp =kzalloc (pages *sizeof (*new_bp),GFP_KERNEL ); - ret = -ENOMEM ;if (!new_bp) {bitmap_file_unmap (&store); - goto err; +return -ENOMEM ; }if (!init)
@@ -2160,8 +2159,6 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,bitmap_unplug (bitmap); bitmap->mddev->pers->quiesce (bitmap->mddev,0 ); } - ret =0 ; -err:return ret; }EXPORT_SYMBOL_GPL (bitmap_resize);
Signature · 1 line
2.10.0
PATCH 7/16 md/bitmap: Replace a kzalloc() call by kcalloc() in bitmap_resize()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:26:51 +0200
The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer kcalloc over kzalloc with multiply
Thus fix the affected source code place.
--- drivers/md/bitmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/bitmap.c +1 -2
@@ -2035,8 +2035,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,return ret; pages =DIV_ROUND_UP (chunks,PAGE_COUNTER_RATIO ); - - new_bp =kzalloc (pages *sizeof (*new_bp),GFP_KERNEL ); + new_bp =kcalloc (pages,sizeof (*new_bp),GFP_KERNEL );if (!new_bp) {bitmap_file_unmap (&store);return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 8/16 md/bitmap: Rename a jump label in location_store()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:46:22 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/bitmap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/md/bitmap.c +9 -9
@@ -2187,11 +2187,11 @@ location_store(struct mddev *mddev, const char *buf, size_t len)if (mddev->pers) {if (!mddev->pers->quiesce) { rv = -EBUSY ; - goto out; + goto unlock; }if (mddev->recovery || mddev->sync_thread) { rv = -EBUSY ; - goto out; + goto unlock; } }
@@ -2200,7 +2200,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)/* bitmap already configured. Only option is to clear it */ if (strncmp (buf,"none" ,4 ) !=0 ) { rv = -EBUSY ; - goto out; + goto unlock; }if (mddev->pers) { mddev->pers->quiesce (mddev,1 );
@@ -2221,23 +2221,23 @@ location_store(struct mddev *mddev, const char *buf, size_t len)else if (strncmp (buf,"file:" ,5 ) =0 ) {/* Not supported yet */ rv = -EINVAL ; - goto out; + goto unlock; }else {if (buf[0 ] ='+' ) rv =kstrtoll (buf+1 ,10 , &offset);else rv =kstrtoll (buf,10 , &offset);if (rv) - goto out; + goto unlock;if (offset =0 ) { rv = -EINVAL ; - goto out; + goto unlock; }if (mddev->bitmap_info.external =0 && mddev->major_version =0 && offset != mddev->bitmap_info.default_offset) { rv = -EINVAL ; - goto out; + goto unlock; } mddev->bitmap_info.offset = offset;if (mddev->pers) {
@@ -2255,7 +2255,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len) mddev->pers->quiesce (mddev,0 );if (rv) {bitmap_destroy (mddev); - goto out; + goto unlock; } } }
@@ -2268,7 +2268,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)md_wakeup_thread (mddev->thread); } rv =0 ; -out: +unlock:mddev_unlock (mddev);if (rv)return rv;
Signature · 1 line
2.10.0
PATCH 9/16 md/bitmap: Rename a jump label in bitmap_copy_from_slot()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:55:01 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/md/bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/bitmap.c +2 -2
@@ -1910,7 +1910,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot, rv =bitmap_init_from_disk (bitmap,0 );if (rv) - goto err; + goto free_bitmap; counts = &bitmap->counts;for (j =0 ; j < counts->chunks; j++) {
@@ -1937,7 +1937,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,bitmap_unplug (mddev->bitmap); *low = lo; *high = hi; -err: +free_bitmap:bitmap_free (bitmap);return rv; }
Signature · 1 line
2.10.0
PATCH 10/16 md/bitmap: Rename a jump label in bitmap_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 16:06:35 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/bitmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/bitmap.c +4 -4
@@ -1818,22 +1818,22 @@ struct bitmap *bitmap_create(struct mddev *mddev, int slot) err = -EINVAL ; }if (err) - goto error; + goto free_bitmap; bitmap->daemon_lastrun = jiffies; err =bitmap_resize (bitmap, blocks, mddev->bitmap_info.chunksize,1 );if (err) - goto error; + goto free_bitmap;printk (KERN_INFO "created bitmap (%lu pages) for device %s\n" , bitmap->counts.pages,bmname (bitmap)); err =test_bit (BITMAP_WRITE_ERROR , &bitmap->flags) ? -EIO :0 ;if (err) - goto error; + goto free_bitmap;return bitmap; - error: +free_bitmap:bitmap_free (bitmap);return ERR_PTR (err); }
Signature · 1 line
2.10.0
PATCH 11/16 md/bitmap: Rename a jump label in bitmap_init_from_disk()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 16:12:47 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/bitmap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +4 -5
@@ -1064,7 +1064,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)bmname (bitmap), (unsigned long )i_size_read (file->f_mapping->host), store->bytes); - goto err; + goto report_failure; } oldindex = ~0L ;
@@ -1098,7 +1098,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) index + node_offset, count);if (ret) - goto err; + goto report_failure; oldindex = index;
@@ -1116,7 +1116,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) ret = -EIO ;if (test_bit (BITMAP_WRITE_ERROR , &bitmap->flags)) - goto err; + goto report_failure; } } paddr =kmap_atomic (page);
@@ -1143,8 +1143,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) bit_cnt, chunks);return 0 ; - - err: +report_failure:printk (KERN_INFO "%s: bitmap initialisation failed: %d\n" ,bmname (bitmap), ret);return ret;
Signature · 1 line
2.10.0
PATCH 12/16 md/bitmap: One check less in read_page() at the end
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 16:30:25 +0200
* Adjust a jump target.
* Delete a repeated check which became unnecessary with this refactoring.
--- drivers/md/bitmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +5 -5
@@ -367,7 +367,7 @@ static int read_page(struct file *file, unsigned long index, bh =alloc_page_buffers (page,1 <<inode->i_blkbits,0 );if (!bh) { ret = -ENOMEM ; - goto out; + goto report_failure; }attach_page_buffers (page, bh); block = index << (PAGE_SHIFT - inode->i_blkbits);
@@ -379,7 +379,7 @@ static int read_page(struct file *file, unsigned long index,if (bh->b_blocknr =0 ) {/* Cannot use this file! */ ret = -EINVAL ; - goto out; + goto report_failure; } bh->b_bdev = inode->i_sb->s_bdev;if (count < (1 <<inode->i_blkbits))
@@ -401,14 +401,14 @@ static int read_page(struct file *file, unsigned long index,wait_event (bitmap->write_wait,atomic_read (&bitmap->pending_writes)=0 ); -if (test_bit (BITMAP_WRITE_ERROR , &bitmap->flags)) +if (test_bit (BITMAP_WRITE_ERROR , &bitmap->flags)) { ret = -EIO ; -out: -if (ret) +report_failure:printk (KERN_ALERT "md: bitmap read error: (%dB @ %llu): %d\n" , (int )PAGE_SIZE , (unsigned long long )index <<PAGE_SHIFT , ret); + }return ret; }
Signature · 1 line
2.10.0
PATCH 13/16 md/bitmap: Adjust checks for null pointers in 11 functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 17:40:12 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/md/bitmap.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/md/bitmap.c +12 -12
@@ -88,7 +88,7 @@ __acquires(bitmap->lock) mappage =kzalloc (PAGE_SIZE ,GFP_NOIO );spin_lock_irq (&bitmap->lock); -if (mappage =NULL ) { +if (!mappage) {pr_debug ("md/bitmap: map page allocation failed, hijacking\n" );/* We don't support hijack for cluster raid */ if (no_hijack)
@@ -186,7 +186,7 @@ static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mdde* list_for_each_entry_continue_rcu() to find the first entry. */ rcu_read_lock (); -if (rdev =NULL ) +if (!rdev)/* start at the beginning */ rdev = list_entry(&mddev->disks, struct md_rdev, same_set);else {
@@ -284,7 +284,7 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait) {struct buffer_head *bh; -if (bitmap->storage.file =NULL ) { +if (!bitmap->storage.file) {switch (write_sb_page (bitmap, page, wait)) {case -EINVAL :set_bit (BITMAP_WRITE_ERROR , &bitmap->flags);
@@ -493,7 +493,7 @@ static int bitmap_new_disk_sb(struct bitmap *bitmap)unsigned long chunksize, daemon_sleep, write_behind; bitmap->storage.sb_page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (bitmap->storage.sb_page =NULL ) +if (!bitmap->storage.sb_page)return -ENOMEM ; bitmap->storage.sb_page->index =0 ;
@@ -767,7 +767,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,if (with_super && !store->sb_page) { store->sb_page =alloc_page (GFP_KERNEL |__GFP_ZERO); -if (store->sb_page =NULL ) +if (!store->sb_page)return -ENOMEM ; }
@@ -1209,7 +1209,7 @@ void bitmap_daemon_work(struct mddev *mddev)*/ mutex_lock (&mddev->bitmap_info.mutex); bitmap = mddev->bitmap; -if (bitmap =NULL ) { +if (!bitmap) {mutex_unlock (&mddev->bitmap_info.mutex);return ; }
@@ -1336,7 +1336,7 @@ __acquires(bitmap->lock) err =bitmap_checkpage (bitmap, page, create,0 );if (bitmap->bp[page].hijacked || - bitmap->bp[page].map =NULL ) + !bitmap->bp[page].map) csize = ((sector_t )1 ) << (bitmap->chunkshift +PAGE_COUNTER_SHIFT -1 );else
@@ -1481,7 +1481,7 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t {bitmap_counter_t *bmc;int rv; -if (bitmap =NULL ) {/* FIXME or bitmap set as 'failed' */ +if (!bitmap) {/* FIXME or bitmap set as 'failed' */ *blocks =1024 ;return 1 ;/* always resync if no bitmap */ }
@@ -1533,13 +1533,13 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, ibitmap_counter_t *bmc;unsigned long flags; -if (bitmap =NULL ) { +if (!bitmap) { *blocks =1024 ;return ; }spin_lock_irqsave (&bitmap->counts.lock, flags); bmc =bitmap_get_counter (&bitmap->counts, offset, blocks,0 ); -if (bmc =NULL ) +if (!bmc) goto unlock;/* locked */ if (RESYNC (*bmc)) {
@@ -2455,7 +2455,7 @@ static ssize_t can_clear_show(struct mddev *mddev, char *page)static ssize_t can_clear_store (struct mddev *mddev,const char *buf,size_t len) { -if (mddev->bitmap =NULL ) +if (!mddev->bitmap)return -ENOENT ;if (strncmp (buf,"false" ,5 ) =0 ) mddev->bitmap->need_sync =1 ;
@@ -2476,7 +2476,7 @@ behind_writes_used_show(struct mddev *mddev, char *page) {ssize_t ret;spin_lock (&mddev->lock); -if (mddev->bitmap =NULL ) +if (!mddev->bitmap) ret =sprintf (page,"0\n" );else ret = sprintf(page, "%lu\n",
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 14/16 md/bitmap: Delete unnecessary braces in bitmap_resize()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 17:53:07 +0200
Do not use curly brackets at one source code place where a single statement should be sufficient.
--- drivers/md/bitmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/bitmap.c +1 -2
@@ -2075,9 +2075,8 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,unsigned long k;/* deallocate the page memory */ -for (k =0 ; k < page; k++) { +for (k =0 ; k < page; k++)kfree (new_bp[k].map); - }/* restore some fields from old_counts */ bitmap->counts.bp = old_counts.bp;
Signature · 1 line
2.10.0
PATCH 15/16 md/bitmap: Add spaces around three comparison operators
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 18:08:04 +0200
The script "checkpatch.pl" can point information out like the following.
ERROR: spaces required around that '=' (ctx:VxV)
Thus fix the affected source code places.
--- drivers/md/bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/bitmap.c +3 -3
@@ -303,7 +303,7 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait)if (wait)wait_event (bitmap->write_wait, -atomic_read (&bitmap->pending_writes)=0 ); +atomic_read (&bitmap->pending_writes) =0 ); }if (test_bit (BITMAP_WRITE_ERROR , &bitmap->flags))bitmap_file_kick (bitmap);
@@ -400,7 +400,7 @@ static int read_page(struct file *file, unsigned long index, page->index = index;wait_event (bitmap->write_wait, -atomic_read (&bitmap->pending_writes)=0 ); +atomic_read (&bitmap->pending_writes) =0 );if (test_bit (BITMAP_WRITE_ERROR , &bitmap->flags)) { ret = -EIO ; report_failure:
@@ -1003,7 +1003,7 @@ void bitmap_unplug(struct bitmap *bitmap) }if (bitmap->storage.file)wait_event (bitmap->write_wait, -atomic_read (&bitmap->pending_writes)=0 ); +atomic_read (&bitmap->pending_writes) =0 );else md_super_wait (bitmap->mddev);
Signature · 1 line
2.10.0
PATCH 16/16 md/bitmap: Delete an unwanted space in read_sb_page()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 18:18:16 +0200
The script "checkpatch.pl" can point information out like the following.
ERROR: space prohibited after that '!' (ctx:BxW)
Thus fix the affected source code place.
--- drivers/md/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bitmap.c +1 -1
@@ -154,7 +154,7 @@ static int read_sb_page(struct mddev *mddev, loff_t offset,sector_t target;rdev_for_each (rdev, mddev) { -if (!test_bit (In_sync, &rdev->flags) +if (!test_bit (In_sync, &rdev->flags) ||test_bit (Faulty, &rdev->flags))continue ;
Signature · 1 line
2.10.0
Re: [PATCH 12/16] md/bitmap: One check less in read_page() at the end
In reply to SF Markus ElfringThis makes the code ugly.
regards,
dan carpenter
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Was the current code incorrect? What makes kmalloc_array() better? None of this is obvious to me.
I'm not going to change code just because some checker suggests to do so.
Quoted 1 line
This issue was detected by using the Coccinelle software.
So? And which coccinelle script was actually used? I couldn't spot a coccinelle script doing that in the current tree.
Quoted 3 lines
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
I'm not happy with you mixing this with the above, less trivial, change.
Quoted 9 lines
Signed-off-by Markus Elfring <[email protected]>drivers/isdn/gigaset/common.c +0
-0@@ -709,8 +709,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
cs->mode=M_UNKNOWN;
cs->mstate=MS_UNINITIALIZED;
-
Unrelated whitespace change.
drivers/isdn/gigaset/common.c struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, · line 712
Quoted 2 lines
drivers/isdn/gigaset/common.c +1
-1- cs->bcs =kmalloc (channels *sizeof (struct bc_state ),GFP_KERNEL ); + cs->bcs =kmalloc_array (channels,sizeof (*cs->bcs),GFP_KERNEL );
For the record: "channels" is basically hardcoded in the three gigaset hardware drivers.
drivers/isdn/gigaset/common.c struct gigaset_driver · line 1093
Quoted 9 lines
cs->inbuf=kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); if (!cs->bcs || !cs->inbuf) {
pr_err("out of memory\n");drivers/isdn/gigaset/common.c +0
-1@@ -1089,8 +1088,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, drv->ops = ops; drv->owner = owner; INIT_LIST_HEAD(&drv->list); -
Again unrelated whitespace change.
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1091
Quoted 2 lines
drivers/isdn/gigaset/common.c +1
-1- drv->cs =kmalloc (minors *sizeof *drv->cs,GFP_KERNEL ); + drv->cs =kmalloc_array (minors,sizeof (*drv->cs),GFP_KERNEL );
For "minors" the same holds as for "channels", above.
And you snuck in a parentheses change. That should have probably been merged with 5/5.
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1093
Quoted 2 lines
drivers/isdn/gigaset/common.c +0
-0if (!drv->cs) goto error;
Paul Bolle
Re: [PATCH 3/5] ISDN-Gigaset: Delete an error message for a failed memory allocation
In reply to Tilman SchmidtQuoted 8 lines · Tilman Schmidt
Quoted 7 lines · SF Markus Elfring
Omit an extra message for a memory allocation failure in this function.
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-R
efactor_Strings-WSang_0.pdf
Quoted 6 lines
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>The patch is fine but the link in the commit message is irrelevant. Please remove it.
(Yes, I read through the whole presentation to verify that. It was fun, even.)
Agree.
Except this patch assumes the superfluous braces would be removed in 4/5. But it turns out that other patch must be dropped. It would have been better to remove the braces in this patch.
Paul Bolle
Re: [PATCH 0/5] ISDN-Gigaset: Fine-tuning for three function implementations
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Some update suggestions were taken into account
from static source code analysis.Markus Elfring (5):
Usekmalloc_array()in two functions
Improve another size determination ingigaset_initcs()Delete an error message for a failed memory allocation Release memory ingigaset_initcs()after an allocation failure Enclose two expressions for the sizeof operator by parentheses
Quoted 2 lines
drivers/isdn/gigaset/common.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
Two of the five patches introduced bugs. The rest of the series isn't free of various nits either. Of course, I was in no mood to be lenient when I looked at those three patches.
I won't take any of these patches, sorry.
Paul Bolle
cover md/dm-crypt: Fine-tuning for five function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 17:25:17 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (10):
Use kcalloc() in crypt_alloc_tfms()
Reduce the scope for a variable in crypt_alloc_tfms()
Rename a jump label in crypt_message()
Delete an unnecessary variable initialisation in crypt_message() Rename a jump label in crypt_set_key()
Delete an unnecessary variable initialisation in crypt_set_key() Rename a jump label in crypt_iv_tcw_whitening()
Return directly after a failed crypto_alloc_ahash() in crypt_iv_essiv_ctr() Two checks and one function call less in crypt_iv_essiv_ctr() after error detection Delete unnecessary variable initialisations in crypt_iv_essiv_ctr()
drivers/md/dm-crypt.c | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/10 md/dm-crypt: Use kcalloc() in crypt_alloc_tfms()
From: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 13:26:22 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/dm-crypt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-crypt.c +1 -2
@@ -1454,8 +1454,7 @@ static int crypt_alloc_tfms(struct crypt_config *cc, char *ciphermode)unsigned i;int err; - cc->tfms =kzalloc (cc->tfms_count *sizeof (struct crypto_skcipher *), -GFP_KERNEL ); + cc->tfms =kcalloc (cc->tfms_count,sizeof (*cc->tfms),GFP_KERNEL );if (!cc->tfms)return -ENOMEM ;
Signature · 1 line
2.10.0
Mike Snitzer
NAKRe: [PATCH 00/10] md/dm-crypt: Fine-tuning for five function implementations
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 17:25:17 +0200Some update suggestions were taken into account
from static source code analysis.Markus Elfring (10):
Usekcalloc()incrypt_alloc_tfms()
Reduce the scope for a variable incrypt_alloc_tfms()
Rename a jump label incrypt_message()
Delete an unnecessary variable initialisation incrypt_message()Rename a jump label incrypt_set_key()
Delete an unnecessary variable initialisation incrypt_set_key()Rename a jump label incrypt_iv_tcw_whitening()
Return directly after a failedcrypto_alloc_ahash()incrypt_iv_essiv_ctr()Two checks and one function call less incrypt_iv_essiv_ctr()after error detection Delete unnecessary variable initialisations incrypt_iv_essiv_ctr()
Quoted 2 lines
drivers/md/dm-crypt.c | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-)
These are _not_ the kind of changes I want to be seeing. Churn in the name of "fine-tuning".
Nack.
PATCH 2/10 md/dm-crypt: Reduce the scope for a variable in crypt_alloc_tfms()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 14:05:25 +0200
Move the definition for the variable "err" (including its declaration) into an if branch (so that the corresponding setting will only be performed if a call of the function "crypto_alloc_skcipher" failed as before this refactoring).
--- drivers/md/dm-crypt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-crypt.c +2 -2
@@ -1452,7 +1452,6 @@ static void crypt_free_tfms(struct crypt_config *cc)static int crypt_alloc_tfms (struct crypt_config *cc,char *ciphermode) {unsigned i; -int err; cc->tfms =kcalloc (cc->tfms_count,sizeof (*cc->tfms),GFP_KERNEL );if (!cc->tfms)
@@ -1461,7 +1460,8 @@ static int crypt_alloc_tfms(struct crypt_config *cc, char *ciphermode)for (i =0 ; i < cc->tfms_count; i++) { cc->tfms[i] =crypto_alloc_skcipher (ciphermode,0 ,0 );if (IS_ERR (cc->tfms[i])) { - err =PTR_ERR (cc->tfms[i]); +int err =PTR_ERR (cc->tfms[i]); +crypt_free_tfms (cc);return err; }
Signature · 1 line
2.10.0
PATCH 3/10 md/dm-crypt: Rename a jump label in crypt_message()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 14:54:39 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/md/dm-crypt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/dm-crypt.c +2 -3
@@ -2016,7 +2016,7 @@ static int crypt_message(struct dm_target *ti, unsigned argc, char **argv)int ret = -EINVAL ;if (argc <2 ) - goto error; + goto show_warning;if (!strcasecmp (argv[0 ],"key" )) {if (!test_bit (DM_CRYPT_SUSPENDED , &cc->flags)) {
@@ -2040,8 +2040,7 @@ static int crypt_message(struct dm_target *ti, unsigned argc, char **argv)return crypt_wipe_key (cc); } } - -error: +show_warning:DMWARN ("unrecognised message received." );return -EINVAL ; }
Signature · 1 line
2.10.0
PATCH 4/10 md/dm-crypt: Delete an unnecessary variable initialisation in crypt_message()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:06:05 +0200
The local variable "ret" will be set to an appropriate value in if branches. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-crypt.c +1 -1
@@ -2013,7 +2013,7 @@ static void crypt_resume(struct dm_target *ti)static int crypt_message (struct dm_target *ti,unsigned argc,char **argv) {struct crypt_config *cc = ti->private; -int ret = -EINVAL ; +int ret;if (argc <2 ) goto show_warning;
Signature · 1 line
2.10.0
PATCH 5/10 md/dm-crypt: Rename a jump label in crypt_set_key()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:21:18 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/dm-crypt.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/dm-crypt.c +4 -5
@@ -1496,20 +1496,19 @@ static int crypt_set_key(struct crypt_config *cc, char *key)/* The key size may not be changed. */ if (cc->key_size != (key_string_len >>1 )) - goto out; + goto set_memory;/* Hyphen (which gives a key_size of zero) means there is no key. */ if (!cc->key_size &&strcmp (key,"-" )) - goto out; + goto set_memory;if (cc->key_size &&crypt_decode_key (cc->key, key, cc->key_size) <0 ) - goto out; + goto set_memory;set_bit (DM_CRYPT_KEY_VALID , &cc->flags); r =crypt_setkey_allcpus (cc); - -out: +set_memory:/* Hex key string not needed after here, so wipe it. */ memset (key,'0' , key_string_len);
Signature · 1 line
2.10.0
PATCH 6/10 md/dm-crypt: Delete an unnecessary variable initialisation in crypt_set_key()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:24:13 +0200
The local variable "r" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-crypt.c +1 -1
@@ -1491,7 +1491,7 @@ static int crypt_setkey_allcpus(struct crypt_config *cc)static int crypt_set_key (struct crypt_config *cc,char *key) { -int r = -EINVAL ; +int r;int key_string_len =strlen (key);/* The key size may not be changed. */
Signature · 1 line
2.10.0
PATCH 7/10 md/dm-crypt: Rename a jump label in crypt_iv_tcw_whitening()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:32:15 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/dm-crypt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/dm-crypt.c +4 -4
@@ -698,13 +698,13 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,for (i =0 ; i <4 ; i++) { r =crypto_shash_init (desc);if (r) - goto out; + goto zero_memory; r =crypto_shash_update (desc, &buf[i *4 ],4 );if (r) - goto out; + goto zero_memory; r =crypto_shash_final (desc, &buf[i *4 ]);if (r) - goto out; + goto zero_memory; }crypto_xor (&buf[0 ], &buf[12 ],4 );crypto_xor (&buf[4 ], &buf[8 ],4 );
@@ -712,7 +712,7 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,/* apply whitening (8 bytes) to whole sector */ for (i =0 ; i < ((1 <<SECTOR_SHIFT ) /8 ); i++)crypto_xor (data + i *8 , buf,8 ); -out: +zero_memory:memzero_explicit (buf,sizeof (buf));return r; }
Signature · 1 line
2.10.0
PATCH 8/10 md/dm-crypt: Return directly after a failed crypto_alloc_ahash() in crypt_iv_essiv_ctr()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:55:47 +0200
Return directly after a call of the function "crypto_alloc_ahash" failed here.
--- drivers/md/dm-crypt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-crypt.c +1 -2
@@ -375,8 +375,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti, hash_tfm =crypto_alloc_ahash (opts,0 ,CRYPTO_ALG_ASYNC );if (IS_ERR (hash_tfm)) { ti->error ="Error initializing ESSIV hash" ; - err =PTR_ERR (hash_tfm); - goto bad; +return PTR_ERR (hash_tfm); } salt =kzalloc (crypto_ahash_digestsize (hash_tfm),GFP_KERNEL );
Signature · 1 line
2.10.0
PATCH 9/10 md/dm-crypt: Two checks and one function call less in crypt_iv_essiv_ctr() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 16:38:37 +0200
The kfree() function was called in one case by the crypt_iv_essiv_ctr() function during error handling even if the passed variable "salt" contained a null pointer.
* Adjust a jump target according to the Linux coding style convention.
* Delete this function call and a condition check which became unnecessary with this refactoring.
--- drivers/md/dm-crypt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/md/dm-crypt.c +3 -6
@@ -382,7 +382,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,if (!salt) { ti->error ="Error kmallocing salt storage in ESSIV" ; err = -ENOMEM ; - goto bad; + goto free_hash; } cc->iv_gen_private.essiv.salt = salt;
@@ -397,11 +397,8 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti, cc->iv_private = essiv_tfm;return 0 ; - -bad: -if (hash_tfm && !IS_ERR (hash_tfm)) -crypto_free_ahash (hash_tfm); -kfree (salt); +free_hash: +crypto_free_ahash (hash_tfm);return err; }
Signature · 1 line
2.10.0
PATCH 10/10 md/dm-crypt: Delete unnecessary variable initialisations in crypt_iv_essiv_ctr()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 16:44:32 +0200
Three local variables will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation which became unnecessary with a previous update step.
--- drivers/md/dm-crypt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-crypt.c +3 -3
@@ -361,9 +361,9 @@ static void crypt_iv_essiv_dtr(struct crypt_config *cc)static int crypt_iv_essiv_ctr (struct crypt_config *cc,struct dm_target *ti,const char *opts) { -struct crypto_cipher *essiv_tfm =NULL ; -struct crypto_ahash *hash_tfm =NULL ; -u8 *salt =NULL ; +struct crypto_cipher *essiv_tfm; +struct crypto_ahash *hash_tfm; +u8 *salt;int err;if (!opts) {
Signature · 1 line
2.10.0
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions
In reply to Paul BolleQuoted 5 lines
Quoted 3 lines
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".Was the current code incorrect?
I suggest to use a safer interface for array allocations.
Quoted 1 line
What makes
kmalloc_array()better?
1. How do you think about the safety checks that this function provides?
2. Will you be also affected by further software evolution here? 2016-07-26
mm: faster kmalloc_array(), kcalloc()
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id‘c6a05f72a996bee5133e76374ab3ad7d3b9b72
Quoted 1 line
I'm not going to change code just because some checker suggests to do so.
The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer kmalloc_array over kmalloc with multiply
Quoted 3 lines
Quoted 1 line
This issue was detected by using the Coccinelle software.
So? And which coccinelle script was actually used?
How do you think about to look into related information sources?
https://github.com/coccinelle/coccinelle/issues/81
Would you like to experiment any further with an excerpt?
@replacement1@
expression count, target;
type T;
@@
target - kmalloc(sizeof(T) * (count)
+ kmalloc_array(count, sizeof(T)
, ...);
@replacement2@
expression count, pointer, target;
@@
target - kmalloc(sizeof(*pointer) * (count)
+ kmalloc_array(count, sizeof(*pointer)
, ...);
Quoted 1 line
I couldn't spot a coccinelle script doing that in the current tree.
This is true for such a software update opportunity.
Quoted 5 lines
Quoted 3 lines
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
I'm not happy with you mixing this with the above, less trivial, change.
I find that it is a useful combination. - A parameter is adjusted together with a special function name.
Quoted 7 lines
drivers/isdn/gigaset/common.c struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, · line 1091
Quoted 2 lines
drivers/isdn/gigaset/common.c +1
-1- drv->cs =kmalloc (minors *sizeof *drv->cs,GFP_KERNEL ); + drv->cs =kmalloc_array (minors,sizeof (*drv->cs),GFP_KERNEL );For "minors" the same holds as for "channels", above.
And you snuck in a parentheses change. That should have probably been merged with 5/5.
Would you prefer to add them in another update step?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: ISDN-Gigaset: Fine-tuning for three function implementations
In reply to Paul BolleQuoted 5 lines
Two of the five patches introduced bugs. The rest of the series isn't free of various nits either. Of course, I was in no mood to be lenient when I looked at those three patches.
I won't take any of these patches, sorry.
Would you like to look once more into an improved patch series for this software module a bit later?
Regards,
Markus
Re: [PATCH 1/5] ISDN-Gigaset: Use kmalloc_array() in two functions
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
Quoted 2 lines
I'm not going to change code just because some checker suggests to do so.
The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer
kmalloc_arrayover kmalloc with multiply
Am I being trolled?
Paul Bolle
Re: ISDN-Gigaset: Fine-tuning for three function implementations
In reply to SF Markus ElfringQuoted 2 lines · SF Markus Elfring
Would you like to look once more into an improved patch series for this software module a bit later?
I'm afraid I'm not looking forward to receiving an update of this series, sorry.
Thanks,
Paul Bolle
Re: [PATCH 01/16] md/bitmap: Use kmalloc_array() in bitmap_storage_alloc()
In reply to SF Markus ElfringQuoted 23 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 13:01:07 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/md/bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/md/bitmap.c +0
-0
drivers/md/bitmap.c static int bitmap_storage_alloc(struct bitmap_storage *store, · line 765
Quoted 9 lines
drivers/md/bitmap.c +3
-3@@ -760,9 +760,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store, num_pages =DIV_ROUND_UP (bytes,PAGE_SIZE ); offset = slot_number * num_pages; - - store->filemap =kmalloc (sizeof (struct page *) - * num_pages,GFP_KERNEL ); + store->filemap =kmalloc_array (num_pages, +sizeof (*store->filemap), +GFP_KERNEL );
If you have to make cosmetic changes for the sake of it, then at least use the 80 characters per line that you have available.
This one makes the code uglier.
Jes
Re: [PATCH 08/16] md/bitmap: Rename a jump label in location_store()
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:46:22 +0200Adjust jump labels according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/md/bitmap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
Sorry but this patch is just plain ridiculous. It does not improve the code in any shape or form.
'out' as a label is perfectly legitimate and just as good as 'unlock'.
Jes
Quoted 73 lines
drivers/md/bitmap.c +9
-9@@ -2187,11 +2187,11 @@ location_store(struct mddev *mddev, const char *buf, size_t len)if (mddev->pers) {if (!mddev->pers->quiesce) { rv = -EBUSY ; - goto out; + goto unlock; }if (mddev->recovery || mddev->sync_thread) { rv = -EBUSY ; - goto out; + goto unlock; } }@@ -2200,7 +2200,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)/* bitmap already configured. Only option is to clear it */ if (strncmp (buf,"none" ,4 ) !=0 ) { rv = -EBUSY ; - goto out; + goto unlock; }if (mddev->pers) { mddev->pers->quiesce (mddev,1 );@@ -2221,23 +2221,23 @@ location_store(struct mddev *mddev, const char *buf, size_t len)else if (strncmp (buf,"file:" ,5 ) =0 ) {/* Not supported yet */ rv = -EINVAL ; - goto out; + goto unlock; }else {if (buf[0 ] ='+' ) rv =kstrtoll (buf+1 ,10 , &offset);else rv =kstrtoll (buf,10 , &offset);if (rv) - goto out; + goto unlock;if (offset =0 ) { rv = -EINVAL ; - goto out; + goto unlock; }if (mddev->bitmap_info.external =0 && mddev->major_version =0 && offset != mddev->bitmap_info.default_offset) { rv = -EINVAL ; - goto out; + goto unlock; } mddev->bitmap_info.offset = offset;if (mddev->pers) {@@ -2255,7 +2255,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len) mddev->pers->quiesce (mddev,0 );if (rv) {bitmap_destroy (mddev); - goto out; + goto unlock; } } }@@ -2268,7 +2268,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)md_wakeup_thread (mddev->thread); } rv =0 ; -out: +unlock:mddev_unlock (mddev);if (rv)return rv;
Re: [PATCH 08/16] md/bitmap: Rename a jump label in location_store()
Quoted 6 lines · Jes Sorensen
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 27 Sep 2016 15:46:22 +0200Adjust jump labels according to the current Linux coding style convention.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/md/bitmap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)Sorry but this patch is just plain ridiculous. It does not improve the code in any shape or form.
'out' as a label is perfectly legitimate and just as good as 'unlock'.
Agree, I also curious which document recorded the coding style convention.
Thanks,
Guoqing
cover dm snapshot: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 10:35:43 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (10):
Use kmalloc_array() in init_origin_hash()
Delete two error messages for a failed memory allocation
Delete an unnecessary variable initialisation in snapshot_map() Rename a jump label in pending_complete()
Delete unnecessary variable initialisations in pending_complete() Delete an unnecessary variable initialisation in snapshot_ctr() Delete an unnecessary variable initialisation in merge_callback() Delete an unnecessary variable initialisation in remove_single_exception_chunk() Combine substrings for seven error messages
Delete five unwanted spaces behind "list_for_each_entry"
drivers/md/dm-snap.c | 69 +++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 39 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/10 dm snapshot: Use kmalloc_array() in init_origin_hash()
From: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 22:20:08 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/dm-snap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/md/dm-snap.c +6 -4
@@ -326,8 +326,9 @@ static int init_origin_hash(void) {int i; - _origins =kmalloc (ORIGIN_HASH_SIZE *sizeof (struct list_head ), -GFP_KERNEL ); + _origins =kmalloc_array (ORIGIN_HASH_SIZE , +sizeof (*_origins), +GFP_KERNEL );if (!_origins) {DMERR ("unable to allocate memory for _origins" );return -ENOMEM ;
@@ -335,8 +336,9 @@ static int init_origin_hash(void)for (i =0 ; i <ORIGIN_HASH_SIZE ; i++)INIT_LIST_HEAD (_origins + i); - _dm_origins =kmalloc (ORIGIN_HASH_SIZE *sizeof (struct list_head ), -GFP_KERNEL ); + _dm_origins =kmalloc_array (ORIGIN_HASH_SIZE , +sizeof (*_dm_origins), +GFP_KERNEL );if (!_dm_origins) {DMERR ("unable to allocate memory for _dm_origins" );kfree (_origins);
Signature · 1 line
2.10.0
PATCH 2/10 dm snapshot: Delete two error messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 22:33:09 +0200
Omit extra messages for a memory allocation failure in this function.
--- drivers/md/dm-snap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/md/dm-snap.c +1 -4
@@ -329,10 +329,8 @@ static int init_origin_hash(void) _origins =kmalloc_array (ORIGIN_HASH_SIZE ,sizeof (*_origins),GFP_KERNEL ); -if (!_origins) { -DMERR ("unable to allocate memory for _origins" ); +if (!_origins)return -ENOMEM ; - }for (i =0 ; i <ORIGIN_HASH_SIZE ; i++)INIT_LIST_HEAD (_origins + i);
@@ -340,7 +338,6 @@ static int init_origin_hash(void)sizeof (*_dm_origins), GFP_KERNEL);if (!_dm_origins) { -DMERR ("unable to allocate memory for _dm_origins" );kfree (_origins);return -ENOMEM ; }
Signature · 1 line
2.10.0
PATCH 3/10 dm snapshot: Delete an unnecessary variable initialisation in snapshot_map()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 08:00:29 +0200
The local variable "pe" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-snap.c +1 -1
@@ -1675,7 +1675,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)struct dm_snapshot *s = ti->private;int r =DM_MAPIO_REMAPPED ;chunk_t chunk; -struct dm_snap_pending_exception *pe =NULL ; +struct dm_snap_pending_exception *pe;init_tracked_chunk (bio);
Signature · 1 line
2.10.0
PATCH 4/10 dm snapshot: Rename a jump label in pending_complete()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 08:18:51 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/dm-snap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/dm-snap.c +4 -5
@@ -1460,7 +1460,7 @@ static void pending_complete(void *context, int success)down_write (&s->lock);__invalidate_snapshot (s, -EIO ); error =1 ; - goto out; + goto remove_exception; } e =alloc_completed_exception (GFP_NOIO );
@@ -1468,7 +1468,7 @@ static void pending_complete(void *context, int success)down_write (&s->lock);__invalidate_snapshot (s, -ENOMEM ); error =1 ; - goto out; + goto remove_exception; } *e = pe->e;
@@ -1476,7 +1476,7 @@ static void pending_complete(void *context, int success)if (!s->valid) {free_completed_exception (e); error =1 ; - goto out; + goto remove_exception; }/* Check for conflicting reads */
@@ -1487,8 +1487,7 @@ static void pending_complete(void *context, int success)* in-flight exception from the list. */ dm_insert_exception (&s->complete, e); - -out: +remove_exception:dm_remove_exception (&pe->e); snapshot_bios =bio_list_get (&pe->snapshot_bios); origin_bios =bio_list_get (&pe->origin_bios);
Signature · 1 line
2.10.0
PATCH 5/10 dm snapshot: Delete unnecessary variable initialisations in pending_complete()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 08:25:47 +0200
Three local variables will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-snap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-snap.c +3 -3
@@ -1450,9 +1450,9 @@ static void pending_complete(void *context, int success)struct dm_snap_pending_exception *pe = context;struct dm_exception *e;struct dm_snapshot *s = pe->snap; -struct bio *origin_bios =NULL ; -struct bio *snapshot_bios =NULL ; -struct bio *full_bio =NULL ; +struct bio *origin_bios; +struct bio *snapshot_bios; +struct bio *full_bio;int error =0 ;if (!success) {
Signature · 1 line
2.10.0
PATCH 6/10 dm snapshot: Delete an unnecessary variable initialisation in snapshot_ctr()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 08:38:29 +0200
The local variable "r" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-snap.c +1 -1
@@ -1102,7 +1102,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) {struct dm_snapshot *s;int i; -int r = -EINVAL ; +int r;char *origin_path, *cow_path;dev_t origin_dev, cow_dev;unsigned args_used, num_flush_bios =1 ;
Signature · 1 line
2.10.0
PATCH 7/10 dm snapshot: Delete an unnecessary variable initialisation in merge_callback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 09:00:06 +0200
The local variable "b" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-snap.c +1 -1
@@ -1046,7 +1046,7 @@ static void error_bios(struct bio *bio);static void merge_callback (int read_err,unsigned long write_err,void *context) {struct dm_snapshot *s = context; -struct bio *b =NULL ; +struct bio *b;if (read_err || write_err) {if (read_err)
Signature · 1 line
2.10.0
PATCH 8/10 dm snapshot: Delete an unnecessary variable initialisation in remove_single_exception_chunk()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 09:06:37 +0200
The local variable "b" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-snap.c +1 -1
@@ -904,7 +904,7 @@ static void flush_bios(struct bio *bio);static int remove_single_exception_chunk (struct dm_snapshot *s) { -struct bio *b =NULL ; +struct bio *b;int r;chunk_t old_chunk = s->first_merging_chunk + s->num_merging_chunks -1 ;
Signature · 1 line
2.10.0
PATCH 9/10 dm snapshot: Combine substrings for seven error messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 09:46:32 +0200
The script "checkpatch.pl" can point information out like the following.
WARNING: quoted string split across lines
Thus fix the affected source code places.
--- drivers/md/dm-snap.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/md/dm-snap.c +7 -14
@@ -468,8 +468,7 @@ static int __validate_exception_handover(struct dm_snapshot *snap)if ((__find_snapshots_sharing_cow (snap, &snap_src, &snap_dest, &snap_merge) ==2 ) || snap_dest) { - snap->ti->error ="Snapshot cow pairing for exception " -"table handover failed" ; + snap->ti->error ="Snapshot cow pairing for exception table handover failed" ;return -EINVAL ; }
@@ -496,8 +495,7 @@ static int __validate_exception_handover(struct dm_snapshot *snap)if (!snap_src->store->type->prepare_merge || !snap_src->store->type->commit_merge) { - snap->ti->error ="Snapshot exception store does not " -"support snapshot-merge." ; + snap->ti->error ="Snapshot exception store does not support snapshot-merge." ;return -EINVAL ; }
@@ -858,8 +856,7 @@ static int __remove_single_exception_chunk(struct dm_snapshot *s, e =dm_lookup_exception (&s->complete, old_chunk);if (!e) { -DMERR ("Corruption detected: exception for block %llu is " -"on disk but not in memory" , +DMERR ("Corruption detected: exception for block %llu is on disk but not in memory" , (unsigned long long )old_chunk);return -EINVAL ; }
@@ -886,8 +883,7 @@ static int __remove_single_exception_chunk(struct dm_snapshot *s, e->new_chunk++; }else if (old_chunk != e->old_chunk +dm_consecutive_chunk_count (e)) { - DMERR("Attempt to merge block %llu from the " - "middle of a chunk range [%llu - %llu]", + DMERR("Attempt to merge block %llu from the middle of a chunk range [%llu - %llu]", (unsigned long long)old_chunk, (unsigned long long)e->old_chunk, (unsigned long long)
@@ -980,8 +976,7 @@ static void snapshot_merge_next_chunks(struct dm_snapshot *s) &new_chunk);if (linear_chunks <=0 ) {if (linear_chunks <0 ) { -DMERR ("Read error in exception store: " -"shutting down merge" ); +DMERR ("Read error in exception store: shutting down merge" );down_write (&s->lock); s->merge_failed =1 ;up_write (&s->lock);
@@ -1877,12 +1872,10 @@ static int snapshot_preresume(struct dm_target *ti)if (snap_src && snap_dest) {down_read (&snap_src->lock);if (s == snap_src) { -DMERR ("Unable to resume snapshot source until " -"handover completes." ); +DMERR ("Unable to resume snapshot source until handover completes." ); r = -EINVAL ; }else if (!dm_suspended (snap_src->ti)) { -DMERR ("Unable to perform snapshot handover until " -"source is suspended." ); +DMERR ("Unable to perform snapshot handover until source is suspended." ); r = -EINVAL ; }up_read (&snap_src->lock);
Signature · 1 line
2.10.0
PATCH 10/10 dm snapshot: Delete five unwanted spaces behind "list_for_each_entry"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 29 Sep 2016 10:14:32 +0200
The script "checkpatch.pl" can point information out like the following.
WARNING: space prohibited between function name and open parenthesis '('
Thus fix the affected source code places.
--- drivers/md/dm-snap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-snap.c +5 -5
@@ -366,7 +366,7 @@ static struct origin *__lookup_origin(struct block_device *origin)struct origin *o; ol = &_origins[origin_hash (origin)]; - list_for_each_entry (o, ol, hash_list) +list_for_each_entry (o, ol, hash_list)if (bdev_equal (o->bdev, origin))return o;
@@ -385,7 +385,7 @@ static struct dm_origin *__lookup_dm_origin(struct block_device *origin)struct dm_origin *o; ol = &_dm_origins[origin_hash (origin)]; - list_for_each_entry (o, ol, hash_list) +list_for_each_entry (o, ol, hash_list)if (bdev_equal (o->dev->bdev, origin))return o;
@@ -625,7 +625,7 @@ static void dm_exception_table_exit(struct dm_exception_table *et,for (i =0 ; i < size; i++) { slot = et->table + i; - list_for_each_entry_safe (ex, next, slot, hash_list) +list_for_each_entry_safe (ex, next, slot, hash_list)kmem_cache_free (mem, ex); }
@@ -653,7 +653,7 @@ static struct dm_exception *dm_lookup_exception(struct dm_exception_table *et,struct dm_exception *e; slot = &et->table[exception_hash (et, chunk)]; - list_for_each_entry (e, slot, hash_list) +list_for_each_entry (e, slot, hash_list)if (chunk >= e->old_chunk && chunk <= e->old_chunk +dm_consecutive_chunk_count (e))return e;
@@ -2068,7 +2068,7 @@ static int __origin_write(struct list_head *snapshots, sector_t sector,chunk_t chunk;/* Do all the snapshots on this origin */ - list_for_each_entry (snap, snapshots, list) { +list_for_each_entry (snap, snapshots, list) {/* * Don't make new exceptions in a merging snapshot * because it has effectively been deleted
Signature · 1 line
2.10.0
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
In reply to SF Markus ElfringAndy, Joe,
Quoted 5 lines · SF Markus Elfring
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
We have no hope of fixing Markus' homegrown coccinelle script. But we could try to fix the checkpatch false positive here. Something like:
scripts/checkpatch.pl +1 -1
@@ -5693,7 +5693,7 @@ sub process { $r2 = $a1; } if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && - !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { + !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*\b/)) { if (WARN("ALLOC_WITH_MULTIPLY", "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) && $fix) {
Does that work for you too?
Quoted 23 lines
drivers/md/dm-snap.c +0
-0@@ -326,8 +326,9 @@ static int init_origin_hash(void) { int i;drivers/md/dm-snap.c +3
-2- _origins =kmalloc (ORIGIN_HASH_SIZE *sizeof (struct list_head ), - GFP_KERNEL); + _origins =kmalloc_array (ORIGIN_HASH_SIZE , + sizeof(*_origins), + GFP_KERNEL);if (!_origins) {
DMERR("unable to allocate memory for _origins"); return-ENOMEM;drivers/md/dm-snap.c +0
-0@@ -335,8 +336,9 @@ static int init_origin_hash(void) for (i = 0; i < ORIGIN_HASH_SIZE; i++) INIT_LIST_HEAD(_origins + i);drivers/md/dm-snap.c +3
-2- _dm_origins =kmalloc (ORIGIN_HASH_SIZE *sizeof (struct list_head ), - GFP_KERNEL); + _dm_origins =kmalloc_array (ORIGIN_HASH_SIZE , + sizeof(*_dm_origins), + GFP_KERNEL);
Quoted 3 lines
if (!_dm_origins) {
DMERR("unable to allocate memory for _dm_origins");kfree(_origins);
Thanks,
Paul Bolle
Joe Perches
maintainerRe: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 7 lines · Paul Bolle
Andy, Joe,
Quoted 4 lines · SF Markus Elfring
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 5 lines
Quoted 1 line
This issue was detected by using the Coccinelle software.
We have no hope of fixing Markus' homegrown coccinelle script. But we could try to fix the checkpatch false positive here.
What's the false positive?
I get:
$ ./scripts/checkpatch.pl -f drivers/md/dm-snap.c --show-types --types=alloc_with_multiply WARNING:ALLOC_WITH_MULTIPLY: Prefer kmalloc_array over kmalloc with multiply #329: FILE: drivers/md/dm-snap.c:329: + _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
WARNING:ALLOC_WITH_MULTIPLY: Prefer kmalloc_array over kmalloc with multiply #338: FILE: drivers/md/dm-snap.c:338:
+ _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
total: 0 errors, 2 warnings, 2490 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
drivers/md/dm-snap.c has style problems, please review.
NOTE: Used message types: ALLOC_WITH_MULTIPLY
NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 18 lines · Joe Perches
What's the false positive?
I get:
$ ./scripts/checkpatch.pl -f drivers/md/dm-snap.c --show-types --types=alloc_with_multiply WARNING:ALLOC_WITH_MULTIPLY: Prefer kmalloc_array over kmalloc with multiply #329: FILE: drivers/md/dm-snap.c:329:(quoted diff) +1
-0+ _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),WARNING:ALLOC_WITH_MULTIPLY: Prefer
kmalloc_arrayover kmalloc with multiply #338: FILE:drivers/md/dm-snap.c:338:(quoted diff) +1
-0+ _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),total: 0 errors, 2 warnings, 2490 lines checked
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
Quoted 6 lines
drivers/md/dm-snap.chas style problems, please review.NOTE: Used message types:
ALLOC_WITH_MULTIPLYNOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
It seems it was intended to be silent about multiplying with constants, where things that look like preprocessor defines are also considered constants. Or did I misread that test?
Paul Bolle
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 1 line · Paul Bolle
Or did I misread that test?
I finally did some digging: commit e367455a9f25 ("checkpatch: emit fewer kmalloc_array/kcalloc conversion warnings") shows I didn't.
Paul Bolle
Re: dm snapshot: Use kmalloc_array() in init_origin_hash()
In reply to Paul BolleQuoted 1 line
We have no hope of fixing Markus' homegrown coccinelle script.
I have got an other impression. I see further possibilities to clarify involved communication and software development challenges for a few source code search patterns.
How do you think about to discuss the corresponding collateral evolution a bit more?
Are there any more constraints to consider?
Regards,
Markus
Re: [dm-devel] [PATCH 03/10] md/dm-crypt: Rename a jump label in crypt_message()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 14:54:39 +0200Adjust a jump label according to the current Linux coding style convention.
In what bizzaro world is the "current Linux coding style convention"
drivers/md/dm-crypt.c static int crypt_message(struct dm_target *ti, unsigned argc, char **argv) · line 2046
Quoted 6 lines
drivers/md/dm-crypt.c +1
-2- -error: +show_warning:DMWARN ("unrecognised message received." );return -EINVAL ; }
"show_warning" is better than "error" when the net result of the goto is that the function returns -EINVAL?!?
Please give it up with these drive-by shooting of auto-generated patches. You're just embarassing yourself.
- Ted
Re: [dm-devel] [PATCH 05/10] md/dm-crypt: Rename a jump label in crypt_set_key()
In reply to SF Markus Elfringdrivers/md/dm-crypt.c static int crypt_set_key(struct crypt_config *cc, char *key) · line 1513
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 28 Sep 2016 15:21:18 +0200Adjust jump labels according to the current Linux coding style convention.
drivers/md/dm-crypt.c +1
-2- -out: +set_memory:/* Hex key string not needed after here, so wipe it. */ memset (key,'0' , key_string_len);
Also not "current Linux coding style convetion".
- Ted
Re: dm snapshot: Use kmalloc_array() in init_origin_hash()
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 1 line
We have no hope of fixing Markus' homegrown coccinelle script.
I have got an other impression. I see further possibilities to clarify involved communication and software development challenges for a few source code search patterns.
How do you think about to discuss the corresponding collateral evolution a bit more?
Here's my suggestion:
https://www.youtube.com/watch?v=xAnVNXaa5oA
Regards,
- Ted
Joe Perches
maintainerRe: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
In reply to Paul BolleQuoted 4 lines · Paul Bolle
Quoted 1 line · Paul Bolle
Or did I misread that test?
I finally did some digging: commit e367455a9f25 ("checkpatch: emit fewer kmalloc_array/kcalloc conversion warnings") shows I didn't.
You still misread it a little.
I think it's fine as-is.
$Constant there is any number and the match regex is any upper case variable.
Re: [dm-devel] [PATCH 03/10] md/dm-crypt: Rename a jump label in crypt_message()
In reply to Theodore Ts'oQuoted 1 line
In what bizzaro world is the "current Linux coding style convention"
Do you look at the evolution for a document like "CodingStyle"?
Quoted 8 lines
drivers/md/dm-crypt.c static int crypt_message(struct dm_target *ti, unsigned argc, char **argv) · line 2046
Quoted 6 lines
drivers/md/dm-crypt.c +1
-2- -error: +show_warning:DMWARN ("unrecognised message received." );return -EINVAL ; }"
show_warning" is better than "error"
I got such an impression.
Quoted 1 line
when the net result of the goto is that the function returns
-EINVAL?!?
Do other identifiers fit better for the desired description of "what" and "why" by jump labels?
Quoted 1 line
Please give it up with these drive-by shooting of auto-generated patches.
This update step was not auto-generated.
There are further change possibilities where special analysis tools can help in the corresponding software development.
Quoted 1 line
You're just embarassing yourself.
Do you find any of my update suggestions worth for further considerations?
Regards,
Markus
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
In reply to Joe PerchesQuoted 2 lines · Joe Perches
$Constant there is any number and the match regex is any upper case variable.
Why doesn't that regex match on "ORIGIN_HASH_SIZE"?
Paul Bolle
Joe Perches
maintainerRe: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 4 lines · Paul Bolle
Quoted 2 lines · Joe Perches
$Constant there is any number and the match regex is any upper case variable.
Why doesn't that regex match on "
ORIGIN_HASH_SIZE"?
It does match.
Did you see my earlier email?
$ ./scripts/checkpatch.pl -f drivers/md/dm-snap.c --show-types --types=alloc_with_multiply WARNING:ALLOC_WITH_MULTIPLY: Prefer kmalloc_array over kmalloc with multiply #329: FILE: drivers/md/dm-snap.c:329: + _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
WARNING:ALLOC_WITH_MULTIPLY: Prefer kmalloc_array over kmalloc with multiply #338: FILE: drivers/md/dm-snap.c:338:
+ _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
total: 0 errors, 2 warnings, 2490 lines checked
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 4 lines · Joe Perches
Quoted 1 line · Paul Bolle
Why doesn't that regex match on "
ORIGIN_HASH_SIZE"?It does match.
If that regex does match, it being part of a negative test, the specific checkpatch rule should be silent, shouldn't it?
Paul Bolle
Joe Perches
maintainerRe: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 6 lines · Paul Bolle
Quoted 3 lines · Joe Perches
Quoted 1 line · Paul Bolle
Why doesn't that regex match on "
ORIGIN_HASH_SIZE"?It does match.
If that regex does match, it being part of a negative test, the specific checkpatch rule should be silent, shouldn't it?
'cause I forgot to trim() the original $4 and $10 matches.
Oh well.
It doesn't matter match either way to me.
The case for the unnecessary multiply with <= gcc 4.8 was removed with:
commit 91c6a05f72a996bee5133e76374ab3ad7d3b9b72
Author: Alexey Dobriyan <[email protected]> Date: Tue Jul 26 15:22:08 2016 -0700
mm: faster kmalloc_array(), kcalloc()
When both arguments to kmalloc_array() or kcalloc() are known at compile time then their product is known at compile time but search for kmalloc cache happens at runtime not at compile time.
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 15 lines · Joe Perches
It doesn't matter match either way to me.
The case for the unnecessary multiply with <= gcc 4.8 was removed with:
commit
91c6a05f72a996bee5133e76374ab3ad7d3b9b72
Author: Alexey Dobriyan <[email protected]>
Date: Tue Jul 26 15:22:08 2016 -0700mm: faster
kmalloc_array(),kcalloc()
When both arguments tokmalloc_array()orkcalloc()are known at compile time then their product is known at compile time but search for kmalloc cache happens at runtime not at compile time.
Quoted 8 lines
Signed-off-by Alexey Dobriyan <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc David Rientjes <[email protected]>Cc Joonsoo Kim <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>
You've lost me.
Why does this stop you fixing an apparently wrong checkpatch rule, crude as parts of it are (ie, uppercase identifier must be a constant)?
Paul Bolle
Joe Perches
maintainerRe: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 4 lines · Paul Bolle
Quoted 1 line · Joe Perches
It doesn't matter match either way to me.
Why does this stop you fixing an apparently wrong checkpatch rule, crude as parts of it are (ie, uppercase identifier must be a constant)?
It doesn't. It just doesn't matter much (match) to me. Here:
--- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +3 -3
@@ -5835,8 +5835,8 @@ sub process { if ($^V && $^V ge 5.10.0 && $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { my $oldfunc = $3; - my $a1 = $4; - my $a2 = $10; + my $a1 = trim($4); + my $a2 = trim($10); my $newfunc = "kmalloc_array"; $newfunc = "kcalloc" if ($oldfunc eq "kzalloc"); my $r1 = $a1;
@@ -5850,7 +5850,7 @@ sub process { if (WARN("ALLOC_WITH_MULTIPLY", "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e; + $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . $r1 . ', ' . $r2/e; } }
Re: [PATCH 01/10] dm snapshot: Use kmalloc_array() in init_origin_hash()
Quoted 6 lines · Joe Perches
Quoted 4 lines
Quoted 1 line
It doesn't matter match either way to me.
Why does this stop you fixing an apparently wrong checkpatch rule, crude as parts of it are (ie, uppercase identifier must be a constant)?
It doesn't. It just doesn't matter much (match) to me.
Joe, please.
I've recently ping-ponged with the kernel's "resident wrong bot of the day" over this very rule (kmalloc_array() is safer than kmalloc(), so change your driver now!). Could we just give wrong bots a bit less ammunition whenever that's feasible?
Even if you don't care about my ping-pong experiences: this checkpatch test is broken, please just fix it!
Paul Bolle
Re: dm snapshot: Use kmalloc_array() in init_origin_hash() ?
Quoted 3 lines
I've recently ping-ponged with the kernel's "resident wrong bot of the day" over this very rule (
kmalloc_array()is safer thankmalloc(), so change your driver now!).
Your bot of the day is going to point more update candidates out in various source files that can "accidentally" belong also to Linux. ;-)
Quoted 1 line
Could we just give wrong bots a bit less ammunition whenever that's feasible?
How do you think about to clarify constraints any further so that the probability for false positives can be reduced as desired for the involved source code analysis tools?
Quoted 2 lines
Even if you don't care about my ping-pong experiences: this checkpatch test is broken, please just fix it!
I am curious how collateral software evolution will be continued.
Regards,
Markus
Re: [dm-devel] [PATCH 03/10] md/dm-crypt: Rename a jump label in crypt_message()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
Quoted 1 line
In what bizzaro world is the "current Linux coding style convention"
Do you look at the evolution for a document like "CodingStyle"?
Again, I wrote the paragraph in CodingStyle. I just said that it's a good idea to think about label names instead of using GW-BASIC style numbered labels, I didn't say go around bothering everyone with waste of time cleanup patches.
I specifically did not say that "out:" or "error:" labels are bad names. Those are common style in the kernel.
Please stop sending these patches.
regards,
dan carpenter
Re: md/dm-crypt: Rename a jump label in crypt_message() ?
Quoted 1 line
Again, I wrote the paragraph in CodingStyle.
This is obvious from the corresponding commit "add some more error handling guidelines" (ea04036032edda6f771c1381d03832d2ed0f6c31 on 2014-12-02).
Quoted 1 line
I just said that it's a good idea to think about label names
I agree also to such a desire.
Quoted 1 line
instead of using GW-BASIC style numbered labels,
Is this kind of wording another weakness in the discussed document? How many guidance do programmers get from such a software specification?
I came a few source code places along where I proposed corresponding changes.
Quoted 1 line
I didn't say
You did not say anything about some details as it is often easier to express several aspects in vague and general terms.
Quoted 1 line
go around bothering everyone with waste of time cleanup patches.
I find it still debatable if the shown software development efforts are really "wasted".
It seems that also the Linux development community is mixed about related interpretations.
Quoted 1 line
I specifically did not say that "out:" or "error:" labels are bad names.
Did you inform me once that you had also a special opinion about an identifier like "out"?
The C compiler will accept them as usual. But do we occasionally prefer to express implementation details a bit better there?
Quoted 1 line
Those are common style in the kernel.
* Which impressions can you get from a statement like "goto fail;" or "goto error;"?
* Do any exception handling implementations should be reconsidered at such places?
Quoted 1 line
Please stop sending these patches.
Could it happen that the change acceptance will increase also for
the suggested renaming of jump labels if maintainers from other subsystems would dare to respond once more in a positive way for such a software refactoring?
Regards,
Markus
Bjørn Mork
maintainerRe: md/dm-crypt: Rename a jump label in crypt_message() ?
Quoted 4 lines · SF Markus Elfring
Quoted 1 line
go around bothering everyone with waste of time cleanup patches.
I find it still debatable if the shown software development efforts are really "wasted".
When someone tells you that you are wasting their time, then that is not a subject for further discussion.
Bjørn
Re: md/dm-crypt: Rename a jump label in crypt_message() ?
Quoted 1 line
When someone tells you that you are wasting their time,
This information can be useful to some degree
Quoted 1 line
then that is not a subject for further discussion.
I got an other impression. I guess that there are constraints for such a response which can become interesting for further considerations.
Is it just usual that other software changes are more welcome?
Regards,
Markus
Re: md/dm-crypt: Rename a jump label in crypt_message() ?
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
Quoted 1 line
I specifically did not say that "out:" or "error:" labels are bad names.
Did you inform me once that you had also a special opinion about an identifier like "out"?
I don't like out labels, but that's my opinion. There is nothing in CodingStyle which says you can't do it.
regards,
dan carpenter
Bjørn Mork
maintainerRe: md/dm-crypt: Rename a jump label in crypt_message() ?
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
Quoted 1 line
When someone tells you that you are wasting their time,
This information can be useful to some degree
Yes. If you continue discussing after that point, then you make a clear statement that it isn't an accident. You are deliberately wasting their time.
A lot of people already know this. But you're right that it would be useful to make it even clearer. Maybe you could add a note about it to each patch? Something along "I will not listen. I will not change. Nothing you tell me will ever make it worth your time to do so"?
Just an idea...
Bjørn
Re: md/dm-crypt: Rename a jump label in crypt_message() ?
In reply to Dan CarpenterQuoted 1 line
I don't like out labels, but that's my opinion.
Thanks for this acknowledgement that you have still got a special opinion about such an identifier.
Quoted 1 line
There is nothing in CodingStyle which says you can't do it.
Does the terse description there try to suggest also to choose better identifiers for source code places?
Does the meaning of such a coding style specification include also the selection of a more pleasing identifier than "error" for this software module?
Regards,
Markus
Re: md/dm-crypt: Rename a jump label in crypt_message() ?
In reply to Bjørn MorkQuoted 1 line
If you continue discussing after that point,
I guess that such a condition is not needed.
Quoted 1 line
then you make a clear statement that it isn't an accident.
I hope that most of my software development activities are not "an accident". Is the intent for any update suggestion (like the renaming of a jump label in this case) reasonable to some degree?
Quoted 1 line
You are deliberately wasting their time.
I imagine that I do not really try to "waste" others time. But I am trying also to change some "things".
There are circumstances when these contributions are interpreted as "wasted efforts". Is the change acceptance usually higher for other update patterns?
Quoted 1 line
Something along "I will not listen.
I am listening while my responses might not fit to your current expectations.
Quoted 1 line
I will not change.
I have got also some personal change opportunities.
Quoted 1 line
Nothing you tell me will ever make it worth your time to do so"?
While you can be so clear about a rejection for this software module at the moment, other contributors showed occasionally more positive information.
Regards,
Markus
cover md-cluster: Fine-tuning for ten function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:38:17 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (15):
Use kcalloc() in lock_all_bitmaps()
Improve another size determination in resync_info_update() Improve another size determination in join()
Improve another size determination in __sendmsg() Improve another size determination in recv_daemon() Rename a jump label in recv_daemon()
Improve another size determination in process_suspend_info() Improve determination of sizes in read_resync_info() Improve another size determination in lockres_init() Delete an unnecessary variable initialisation in lockres_init() Delete four error messages for a failed memory allocation Rename a jump label in area_resyncing()
Less function calls in join() after error detection Less function calls in lockres_init() after error detection Delete unnecessary braces in unlock_all_bitmaps()
drivers/md/md-cluster.c | 114 ++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 58 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/15 md-cluster: Use kcalloc() in lock_all_bitmaps()
From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:18:40 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/md/md-cluster.c +4 -3
@@ -1188,9 +1188,10 @@ static int lock_all_bitmaps(struct mddev *mddev)char str[64 ];struct md_cluster_info *cinfo = mddev->cluster_info; - cinfo->other_bitmap_lockres =kzalloc ((mddev->bitmap_info.nodes -1 ) * -sizeof (struct dlm_lock_resource *), -GFP_KERNEL ); + cinfo->other_bitmap_lockres =kcalloc (mddev->bitmap_info.nodes -1 , +sizeof (*cinfo + ->other_bitmap_lockres), +GFP_KERNEL );if (!cinfo->other_bitmap_lockres) {pr_err ("md: can't alloc mem for other bitmap locks\n" );return 0 ;
Signature · 1 line
2.10.0
PATCH 2/15 md-cluster: Improve another size determination in resync_info_update()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:37:24 +0200
Replace the specification of a data structure by a variable name as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -1057,7 +1057,7 @@ static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)/* do not send zero again, if we have sent before */ if (hi =0 ) { -memcpy (&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr,sizeof (struct resync_info )); +memcpy (&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr,sizeof (ri));if (le64_to_cpu (ri.hi) =0 )return 0 ; }
Signature · 1 line
2.10.0
PATCH 3/15 md-cluster: Improve another size determination in join()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:42:47 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -823,7 +823,7 @@ static int join(struct mddev *mddev, int nodes)int ret, ops_rv;char str[64 ]; - cinfo =kzalloc (sizeof (struct md_cluster_info ),GFP_KERNEL ); + cinfo =kzalloc (sizeof (*cinfo),GFP_KERNEL );if (!cinfo)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 4/15 md-cluster: Improve another size determination in __sendmsg()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:21:48 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -706,7 +706,7 @@ static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg) }memcpy (cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, -sizeof (struct cluster_msg )); +sizeof (*cmsg));/*down-convert EX to CW on Message*/ error =dlm_lock_sync (cinfo->message_lockres,DLM_LOCK_CW );if (error) {
Signature · 1 line
2.10.0
PATCH 5/15 md-cluster: Improve another size determination in recv_daemon()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:28:19 +0200
Replace the specification of a data structure by a variable name as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -617,7 +617,7 @@ static void recv_daemon(struct md_thread *thread) }/* read lvb and wake up thread to process this message_lockres */ -memcpy (&msg, message_lockres->lksb.sb_lvbptr,sizeof (struct cluster_msg )); +memcpy (&msg, message_lockres->lksb.sb_lvbptr,sizeof (msg)); ret =process_recvd_msg (thread->mddev, &msg);if (ret) goto out;
Signature · 1 line
2.10.0
PATCH 6/15 md-cluster: Rename a jump label in recv_daemon()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:36:30 +0200
Adjust a jump label according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md-cluster.c +2 -2
@@ -620,7 +620,7 @@ static void recv_daemon(struct md_thread *thread)memcpy (&msg, message_lockres->lksb.sb_lvbptr,sizeof (msg)); ret =process_recvd_msg (thread->mddev, &msg);if (ret) - goto out; + goto unlock;/*release CR on ack_lockres*/ ret =dlm_unlock_sync (ack_lockres);
@@ -634,7 +634,7 @@ static void recv_daemon(struct md_thread *thread) ret =dlm_lock_sync (ack_lockres,DLM_LOCK_CR );if (unlikely (ret !=0 ))pr_info ("lock CR on ack failed return %d\n" , ret); -out: +unlock:/*release CR on message_lockres*/ ret =dlm_unlock_sync (message_lockres);if (unlikely (ret !=0 ))
Signature · 1 line
2.10.0
PATCH 7/15 md-cluster: Improve another size determination in process_suspend_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:42:50 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/md-cluster.c +1 -2
@@ -482,8 +482,7 @@ static void process_suspend_info(struct mddev *mddev, lo, hi); cinfo->sync_low = lo; cinfo->sync_hi = hi; - - s =kzalloc (sizeof (struct suspend_info ),GFP_KERNEL ); + s =kzalloc (sizeof (*s),GFP_KERNEL );if (!s)return ; s->slot = slot;
Signature · 1 line
2.10.0
PATCH 8/15 md-cluster: Improve determination of sizes in read_resync_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:52:58 +0200
Replace the specification of data structures by either a pointer dereference or a variable name as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md-cluster.c +2 -2
@@ -275,10 +275,10 @@ static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_locsector_t hi =0 ;dlm_lock_sync (lockres,DLM_LOCK_CR ); -memcpy (&ri, lockres->lksb.sb_lvbptr,sizeof (struct resync_info )); +memcpy (&ri, lockres->lksb.sb_lvbptr,sizeof (ri)); hi =le64_to_cpu (ri.hi);if (hi >0 ) { - s =kzalloc (sizeof (struct suspend_info ),GFP_KERNEL ); + s =kzalloc (sizeof (*s),GFP_KERNEL );if (!s) goto out; s->hi = hi;
Signature · 1 line
2.10.0
PATCH 9/15 md-cluster: Improve another size determination in lockres_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:02:18 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -190,7 +190,7 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,int ret, namelen;struct md_cluster_info *cinfo = mddev->cluster_info; - res =kzalloc (sizeof (struct dlm_lock_resource ),GFP_KERNEL ); + res =kzalloc (sizeof (*res),GFP_KERNEL );if (!res)return NULL ;init_waitqueue_head (&res->sync_locking);
Signature · 1 line
2.10.0
PATCH 10/15 md-cluster: Delete an unnecessary variable initialisation in lockres_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:07:52 +0200
The local variable "res" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/md/md-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-cluster.c +1 -1
@@ -186,7 +186,7 @@ static int dlm_lock_sync_interruptible(struct dlm_lock_resource *res, int mode,static struct dlm_lock_resource *lockres_init (struct mddev *mddev,char *name,void (*bastfn)(void *arg,int mode),int with_lvb) { -struct dlm_lock_resource *res =NULL ; +struct dlm_lock_resource *res;int ret, namelen;struct md_cluster_info *cinfo = mddev->cluster_info;
Signature · 1 line
2.10.0
PATCH 11/15 md-cluster: Delete four error messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:46:20 +0200
Omit extra messages for a memory allocation failure in three functions.
--- drivers/md/md-cluster.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/md/md-cluster.c +4 -12
@@ -200,17 +200,13 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, res->mode =DLM_LOCK_IV ; namelen =strlen (name); res->name =kzalloc (namelen +1 ,GFP_KERNEL ); -if (!res->name) { -pr_err ("md-cluster: Unable to allocate resource name for resource %s\n" , name); +if (!res->name) goto out_err; - }strlcpy (res->name, name, namelen +1 );if (with_lvb) { res->lksb.sb_lvbptr =kzalloc (LVB_SIZE ,GFP_KERNEL ); -if (!res->lksb.sb_lvbptr) { -pr_err ("md-cluster: Unable to allocate LVB for resource %s\n" , name); +if (!res->lksb.sb_lvbptr) goto out_err; - } res->flags =DLM_LKF_VALBLK ; }
@@ -852,10 +848,8 @@ static int join(struct mddev *mddev, int nodes)/* Initiate the communication resources */ ret = -ENOMEM ; cinfo->recv_thread =md_register_thread (recv_daemon, mddev,"cluster_recv" ); -if (!cinfo->recv_thread) { -pr_err ("md-cluster: cannot allocate memory for recv_thread!\n" ); +if (!cinfo->recv_thread) goto err; - } cinfo->message_lockres =lockres_init (mddev,"message" ,NULL ,1 );if (!cinfo->message_lockres) goto err;
@@ -1191,10 +1185,8 @@ static int lock_all_bitmaps(struct mddev *mddev)sizeof (*cinfo ->other_bitmap_lockres), GFP_KERNEL); -if (!cinfo->other_bitmap_lockres) { -pr_err ("md: can't alloc mem for other bitmap locks\n" ); +if (!cinfo->other_bitmap_lockres)return 0 ; - } my_slot =slot_number (mddev);for (slot =0 ; slot < mddev->bitmap_info.nodes; slot++) {
Signature · 1 line
2.10.0
PATCH 12/15 md-cluster: Rename a jump label in area_resyncing()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 14:38:12 +0200
Adjust a jump label according to the Linux coding style convention
--- drivers/md/md-cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md-cluster.c +2 -2
@@ -1085,13 +1085,13 @@ static int area_resyncing(struct mddev *mddev, int direction,spin_lock_irq (&cinfo->suspend_lock);if (list_empty (&cinfo->suspend_list)) - goto out; + goto unlock;list_for_each_entry (s, &cinfo->suspend_list, list)if (hi > s->lo && lo < s->hi) { ret =1 ;break ; } -out: +unlock:spin_unlock_irq (&cinfo->suspend_lock);return ret; }
Signature · 1 line
2.10.0
PATCH 13/15 md-cluster: Less function calls in join() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 15:40:32 +0200
A few resource release functions were called in some cases by the join() function during error handling
even if the passed data structure member contained a null pointer.
* Adjust jump targets according to the Linux coding style convention.
* Delete a repeated check which became unnecessary with this refactoring.
--- drivers/md/md-cluster.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
drivers/md/md-cluster.c +26 -21
@@ -837,39 +837,39 @@ static int join(struct mddev *mddev, int nodes)DLM_LSFL_FS ,LVB_SIZE , &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);if (ret) - goto err; + goto free_cluster_info;wait_for_completion (&cinfo->completion);if (nodes < cinfo->slot_number) {pr_err ("md-cluster: Slot allotted(%d) is greater than available slots(%d)." , cinfo->slot_number, nodes); ret = -ERANGE ; - goto err; + goto release_lockspace; }/* Initiate the communication resources */ ret = -ENOMEM ; cinfo->recv_thread =md_register_thread (recv_daemon, mddev,"cluster_recv" );if (!cinfo->recv_thread) - goto err; + goto release_lockspace; cinfo->message_lockres =lockres_init (mddev,"message" ,NULL ,1 );if (!cinfo->message_lockres) - goto err; + goto unregister_recv; cinfo->token_lockres =lockres_init (mddev,"token" ,NULL ,0 );if (!cinfo->token_lockres) - goto err; + goto free_message; cinfo->no_new_dev_lockres =lockres_init (mddev,"no-new-dev" ,NULL ,0 );if (!cinfo->no_new_dev_lockres) - goto err; + goto free_token; ret =dlm_lock_sync (cinfo->token_lockres,DLM_LOCK_EX );if (ret) { ret = -EAGAIN ;pr_err ("md-cluster: can't join cluster to avoid lock issue\n" ); - goto err; + goto free_no_new_dev; } cinfo->ack_lockres =lockres_init (mddev,"ack" , ack_bast,0 );if (!cinfo->ack_lockres) { ret = -ENOMEM ; - goto err; + goto free_no_new_dev; }/* get sync CR lock on ACK. */ if (dlm_lock_sync (cinfo->ack_lockres,DLM_LOCK_CR ))
@@ -886,34 +886,39 @@ static int join(struct mddev *mddev, int nodes) cinfo->bitmap_lockres =lockres_init (mddev, str,NULL ,1 );if (!cinfo->bitmap_lockres) { ret = -ENOMEM ; - goto err; + goto free_ack; }if (dlm_lock_sync (cinfo->bitmap_lockres,DLM_LOCK_PW )) {pr_err ("Failed to get bitmap lock\n" ); ret = -EINVAL ; - goto err; + goto free_bitmap; } cinfo->resync_lockres =lockres_init (mddev,"resync" ,NULL ,0 );if (!cinfo->resync_lockres) { ret = -ENOMEM ; - goto err; + goto free_bitmap; }return 0 ; -err: -md_unregister_thread (&cinfo->recovery_thread); -md_unregister_thread (&cinfo->recv_thread); -lockres_free (cinfo->message_lockres); -lockres_free (cinfo->token_lockres); +free_bitmap: +lockres_free (cinfo->bitmap_lockres); +free_ack:lockres_free (cinfo->ack_lockres); +free_no_new_dev:lockres_free (cinfo->no_new_dev_lockres); -lockres_free (cinfo->resync_lockres); -lockres_free (cinfo->bitmap_lockres); -if (cinfo->lockspace) -dlm_release_lockspace (cinfo->lockspace,2 ); - mddev->cluster_info =NULL ; +free_token: +lockres_free (cinfo->token_lockres); +free_message: +lockres_free (cinfo->message_lockres); +unregister_recv: +md_unregister_thread (&cinfo->recv_thread); +release_lockspace: +dlm_release_lockspace (cinfo->lockspace,2 ); +free_cluster_info:kfree (cinfo); +md_unregister_thread (&cinfo->recovery_thread); + mddev->cluster_info =NULL ;return ret; }
Signature · 1 line
2.10.0
PATCH 14/15 md-cluster: Less function calls in lockres_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:01:05 +0200
The kfree() function was called in up to three cases
by the lockres_init() function during error handling even if the passed data structure member (or variable) contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/md/md-cluster.c +6 -4
@@ -201,12 +201,12 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, namelen =strlen (name); res->name =kzalloc (namelen +1 ,GFP_KERNEL );if (!res->name) - goto out_err; + goto free_resource;strlcpy (res->name, name, namelen +1 );if (with_lvb) { res->lksb.sb_lvbptr =kzalloc (LVB_SIZE ,GFP_KERNEL );if (!res->lksb.sb_lvbptr) - goto out_err; + goto free_name; res->flags =DLM_LKF_VALBLK ; }
@@ -218,15 +218,17 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, ret =dlm_lock_sync (res,DLM_LOCK_NL );if (ret) {pr_err ("md-cluster: Unable to lock NL on new lock resource %s\n" , name); - goto out_err; + goto free_lvb; } res->flags &= ~DLM_LKF_EXPEDITE ; res->flags |=DLM_LKF_CONVERT ;return res; -out_err: +free_lvb:kfree (res->lksb.sb_lvbptr); +free_name:kfree (res->name); +free_resource:kfree (res);return NULL ; }
Signature · 1 line
2.10.0
PATCH 15/15 md-cluster: Delete unnecessary braces in unlock_all_bitmaps()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:15:55 +0200
Do not use curly brackets at one source code place where a single statement should be sufficient.
--- drivers/md/md-cluster.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/md/md-cluster.c +3 -4
@@ -1223,11 +1223,10 @@ static void unlock_all_bitmaps(struct mddev *mddev)/* release other node's bitmap lock if they are existed */ if (cinfo->other_bitmap_lockres) { -for (i =0 ; i < mddev->bitmap_info.nodes -1 ; i++) { -if (cinfo->other_bitmap_lockres[i]) { +for (i =0 ; i < mddev->bitmap_info.nodes -1 ; i++) +if (cinfo->other_bitmap_lockres[i])lockres_free (cinfo->other_bitmap_lockres[i]); - } - } +kfree (cinfo->other_bitmap_lockres); } }
Signature · 1 line
2.10.0
cover md/multipath: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 13:45:35 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (13):
Use kcalloc() in multipath_run()
Improve another size determination in multipath_run() Delete four error messages for a failed memory allocation Reduce indentation for four lines in multipath_run() Less function calls in multipath_run() after error detection Delete 13 unwanted spaces behind function names
Delete two unwanted spaces behind asterisks
Replace a seq_printf() call by seq_puts() in multipath_status() Adjust two function calls together with a variable assignment Add some spaces for better code readability
Move a brace for a designated initialiser
Delete an unnecessary return statement in multipath_make_request() Replace printk() calls by the usage of higher level interfaces
drivers/md/multipath.c | 192 +++++++++++++++++++++++-------------------------- 1 file changed, 88 insertions(+), 104 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/13 md/multipath: Use kcalloc() in multipath_run()
From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:40:42 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/multipath.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/multipath.c +2 -1
@@ -408,7 +408,8 @@ static int multipath_run (struct mddev *mddev) goto out; } - conf->multipaths =kzalloc (sizeof (struct multipath_info )*mddev->raid_disks, + conf->multipaths =kcalloc (mddev->raid_disks, +sizeof (*conf->multipaths),GFP_KERNEL );if (!conf->multipaths) { printk(KERN_ERR
Signature · 1 line
2.10.0
PATCH 2/13 md/multipath: Improve another size determination in multipath_run()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:52:57 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/multipath.c +1 -1
@@ -399,7 +399,7 @@ static int multipath_run (struct mddev *mddev)* should be freed in multipath_free()] */ - conf =kzalloc (sizeof (struct mpconf ),GFP_KERNEL ); + conf =kzalloc (sizeof (*conf),GFP_KERNEL ); mddev->private = conf;if (!conf) { printk(KERN_ERR
Signature · 1 line
2.10.0
PATCH 3/13 md/multipath: Delete four error messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:15:45 +0200
Omit extra messages for a memory allocation failure in this function.
--- drivers/md/multipath.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/md/multipath.c +4 -19
@@ -401,22 +401,14 @@ static int multipath_run (struct mddev *mddev) conf =kzalloc (sizeof (*conf),GFP_KERNEL ); mddev->private = conf; -if (!conf) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf) goto out; - } conf->multipaths =kcalloc (mddev->raid_disks,sizeof (*conf->multipaths),GFP_KERNEL ); -if (!conf->multipaths) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf->multipaths) goto out_free_conf; - } working_disks =0 ;rdev_for_each (rdev, mddev) {
@@ -448,21 +440,14 @@ static int multipath_run (struct mddev *mddev) conf->pool =mempool_create_kmalloc_pool (NR_RESERVED_BUFS ,sizeof (struct multipath_bh )); -if (conf->pool =NULL ) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf->pool) goto out_free_conf; - } { mddev->thread =md_register_thread (multipathd, mddev,"multipath" ); -if (!mddev->thread) { -printk (KERN_ERR "multipath: couldn't allocate thread" -" for %s\n" ,mdname (mddev)); +if (!mddev->thread) goto out_free_conf; - } } printk(KERN_INFO
Signature · 1 line
2.10.0
PATCH 4/13 md/multipath: Reduce indentation for four lines in multipath_run()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:26:00 +0200
* Delete a pair of extra curly brackets.
* Reduce indentation one level for a few lines in this function.
--- drivers/md/multipath.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/md/multipath.c +3 -6
@@ -443,12 +443,9 @@ static int multipath_run (struct mddev *mddev)if (!conf->pool) goto out_free_conf; - { - mddev->thread =md_register_thread (multipathd, mddev, -"multipath" ); -if (!mddev->thread) - goto out_free_conf; - } + mddev->thread =md_register_thread (multipathd, mddev,"multipath" ); +if (!mddev->thread) + goto out_free_conf; printk(KERN_INFO "multipath: array %s active with %d out of %d IO paths\n",
Signature · 1 line
2.10.0
PATCH 5/13 md/multipath: Less function calls in multipath_run() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:48:59 +0200
The functions "kfree" and "mempool_destroy" were called in a few cases by the function "multipath_run" during error handling even if the passed data structure member contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/multipath.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/md/multipath.c +8 -7
@@ -408,7 +408,7 @@ static int multipath_run (struct mddev *mddev)sizeof (*conf->multipaths), GFP_KERNEL);if (!conf->multipaths) - goto out_free_conf; + goto free_conf; working_disks =0 ;rdev_for_each (rdev, mddev) {
@@ -434,18 +434,18 @@ static int multipath_run (struct mddev *mddev)if (!working_disks) {printk (KERN_ERR "multipath: no operational IO paths for %s\n" ,mdname (mddev)); - goto out_free_conf; + goto free_multipaths; } mddev->degraded = conf->raid_disks - working_disks; conf->pool =mempool_create_kmalloc_pool (NR_RESERVED_BUFS ,sizeof (struct multipath_bh ));if (!conf->pool) - goto out_free_conf; + goto free_multipaths; mddev->thread =md_register_thread (multipathd, mddev,"multipath" );if (!mddev->thread) - goto out_free_conf; + goto destroy_pool; printk(KERN_INFO "multipath: array %s active with %d out of %d IO paths\n",
@@ -457,13 +457,14 @@ static int multipath_run (struct mddev *mddev)md_set_array_sectors (mddev,multipath_size (mddev,0 ,0 ));if (md_integrity_register (mddev)) - goto out_free_conf; + goto destroy_pool;return 0 ; - -out_free_conf: +destroy_pool:mempool_destroy (conf->pool); +free_multipaths:kfree (conf->multipaths); +free_conf:kfree (conf); mddev->private =NULL ; out:
Signature · 1 line
2.10.0
PATCH 6/13 md/multipath: Delete 13 unwanted spaces behind function names
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 08:14:48 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: space prohibited between function name and open parenthesis '('
Thus fix the affected source code places.
--- drivers/md/multipath.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/md/multipath.c +16 -14
@@ -31,7 +31,7 @@#define NR_RESERVED_BUFS 32 -static int multipath_map (struct mpconf *conf) +static int multipath_map (struct mpconf *conf) {int i, disks = conf->raid_disks;
@@ -56,7 +56,7 @@ static int multipath_map (struct mpconf *conf)return (-1 ); } -static void multipath_reschedule_retry (struct multipath_bh *mp_bh) +static void multipath_reschedule_retry (struct multipath_bh *mp_bh) {unsigned long flags;struct mddev *mddev = mp_bh->mddev;
@@ -73,7 +73,7 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh)* operation and are ready to return a success/failure code to the buffer * cache layer. */ -static void multipath_end_bh_io (struct multipath_bh *mp_bh,int err) +static void multipath_end_bh_io (struct multipath_bh *mp_bh,int err) {struct bio *bio = mp_bh->master_bio;struct mpconf *conf = mp_bh->mddev->private;
@@ -96,7 +96,7 @@ static void multipath_end_request(struct bio *bio)* oops, IO error: */ char b[BDEVNAME_SIZE ]; -md_error (mp_bh->mddev, rdev); +md_error (mp_bh->mddev, rdev);printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" ,bdevname (rdev->bdev,b), (unsigned long long )bio->bi_iter.bi_sector);
@@ -147,12 +147,14 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)struct mpconf *conf = mddev->private;int i; -seq_printf (seq," [%d/%d] [" , conf->raid_disks, - conf->raid_disks - mddev->degraded); +seq_printf (seq," [%d/%d] [" , conf->raid_disks, + conf->raid_disks - mddev->degraded);rcu_read_lock ();for (i =0 ; i < conf->raid_disks; i++) {struct md_rdev *rdev =rcu_dereference (conf->multipaths[i].rdev); -seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); +seq_printf (seq, +"%s" , + rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock ();seq_printf (seq,"]" );
@@ -183,7 +185,7 @@ static int multipath_congested(struct mddev *mddev, int bits)/* * Careful, this can execute in IRQ contexts as well! */ -static void multipath_error (struct mddev *mddev,struct md_rdev *rdev) +static void multipath_error (struct mddev *mddev,struct md_rdev *rdev) {struct mpconf *conf = mddev->private;char b[BDEVNAME_SIZE ];
@@ -218,7 +220,7 @@ static void multipath_error (struct mddev *mddev, struct md_rdev *rdev) conf->raid_disks - mddev->degraded); } -static void print_multipath_conf (struct mpconf *conf) +static void print_multipath_conf (struct mpconf *conf) {int i;struct multipath_info *tmp;
@@ -377,7 +379,7 @@ static sector_t multipath_size(struct mddev *mddev, sector_t sectors, int raid_dreturn mddev->dev_sectors; } -static int multipath_run (struct mddev *mddev) +static int multipath_run (struct mddev *mddev) {struct mpconf *conf;int disk_idx;
@@ -496,14 +498,14 @@ static struct md_personality multipath_personality .congested = multipath_congested, }; -static int __init multipath_init (void ) +static int __init multipath_init (void ) { -return register_md_personality (&multipath_personality); +return register_md_personality (&multipath_personality); } -static void __exit multipath_exit (void) +static void __exit multipath_exit(void) { -unregister_md_personality (&multipath_personality); +unregister_md_personality (&multipath_personality); }module_init (multipath_init);
Signature · 1 line
2.10.0
PATCH 7/13 md/multipath: Delete two unwanted spaces behind asterisks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 09:39:39 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: "foo * bar" should be "foo *bar"
--- drivers/md/multipath.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/multipath.c +2 -2
@@ -106,10 +106,10 @@ static void multipath_end_request(struct bio *bio)rdev_dec_pending (rdev, conf->mddev); } -static void multipath_make_request (struct mddev *mddev,struct bio * bio) +static void multipath_make_request (struct mddev *mddev,struct bio *bio) {struct mpconf *conf = mddev->private; -struct multipath_bh * mp_bh; +struct multipath_bh *mp_bh;struct multipath_info *multipath;if (unlikely (bio->bi_opf &REQ_PREFLUSH )) {
Signature · 1 line
2.10.0
PATCH 8/13 md/multipath: Replace a seq_printf() call by seq_puts() in multipath_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:00:15 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Prefer seq_puts to seq_printf
--- drivers/md/multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/multipath.c +1 -1
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" ); }static int multipath_congested (struct mddev *mddev,int bits)
Signature · 1 line
2.10.0
PATCH 9/13 md/multipath: Adjust two function calls together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:05:43 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
--- drivers/md/multipath.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/md/multipath.c +6 -3
@@ -258,8 +258,9 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)print_multipath_conf (conf); -for (path = first; path <= last; path++) -if ((p=conf->multipaths+path)->rdev =NULL ) { +for (path = first; path <= last; path++) { + p = conf->multipaths + path; +if (!p->rdev) { q = rdev->bdev->bd_disk->queue;disk_stack_limits (mddev->gendisk, rdev->bdev, rdev->data_offset <<9 );
@@ -276,6 +277,7 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev) err =0 ;break ; } + }print_multipath_conf (conf);
@@ -347,7 +349,8 @@ static void multipathd(struct md_thread *thread) bio = &mp_bh->bio; bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector; -if ((mp_bh->path =multipath_map (conf))<0 ) { + mp_bh->path =multipath_map (conf); +if (mp_bh->path <0 ) { printk(KERN_ALERT "multipath: %s: unrecoverable IO read" " error for block %llu\n", bdevname(bio->bi_bdev,b),
Signature · 1 line
2.10.0
PATCH 10/13 md/multipath: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:20:52 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/multipath.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/md/multipath.c +5 -5
@@ -98,7 +98,7 @@ static void multipath_end_request(struct bio *bio)char b[BDEVNAME_SIZE ];md_error (mp_bh->mddev, rdev);printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" , -bdevname (rdev->bdev,b), +bdevname (rdev->bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_reschedule_retry (mp_bh); }else
@@ -238,8 +238,8 @@ static void print_multipath_conf(struct mpconf *conf) tmp = conf->multipaths + i;if (tmp->rdev)printk (" disk%d, o:%d, dev:%s\n" , - i,!test_bit (Faulty, &tmp->rdev->flags), -bdevname (tmp->rdev->bdev,b)); + i, !test_bit (Faulty, &tmp->rdev->flags), +bdevname (tmp->rdev->bdev, b)); } }
@@ -353,13 +353,13 @@ static void multipathd(struct md_thread *thread)if (mp_bh->path <0 ) {printk (KERN_ALERT "multipath: %s: unrecoverable IO read" " error for block %llu\n" , -bdevname (bio->bi_bdev,b), +bdevname (bio->bi_bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_end_bh_io (mp_bh, -EIO ); }else {printk (KERN_ERR "multipath: %s: redirecting sector %llu" " to another IO path\n" , -bdevname (bio->bi_bdev,b), +bdevname (bio->bi_bdev, b), (unsigned long long )bio->bi_iter.bi_sector); *bio = *(mp_bh->master_bio); bio->bi_iter.bi_sector +@@ -487,18 +487,18 @@ static void multipath_free(struct mddev *mddev, void *priv)
static struct md_personality multipath_personality {
- .name = "multipath",
- .level = LEVEL_MULTIPATH,
- .owner = THIS_MODULE,
- .make_request = multipath_make_request,
- .run = multipath_run,
- .free = multipath_free,
- .status = multipath_status,
- .error_handler = multipath_error,
- .hot_add_disk = multipath_add_disk,
- .hot_remove_disk= multipath_remove_disk,
- .size = multipath_size,
- .congested = multipath_congested,
+ .name = "multipath", + .level = LEVEL_MULTIPATH, + .owner = THIS_MODULE, + .make_request = multipath_make_request, + .run = multipath_run, + .free = multipath_free, + .status = multipath_status, + .error_handler = multipath_error, + .hot_add_disk = multipath_add_disk,
+ .hot_remove_disk = multipath_remove_disk,
+ .size = multipath_size,
+ .congested = multipath_congested,
};
static int __init multipath_init(void)
Signature · 1 line
2.10.0
PATCH 11/13 md/multipath: Move a brace for a designated initialiser
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:43:28 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/multipath.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/multipath.c +1 -1
@@ -485,8 +485,7 @@ static void multipath_free(struct mddev *mddev, void *priv)kfree (conf); } -static struct md_personality multipath_personality -{ +static struct md_personality multipath_personality = { .name ="multipath" , .level =LEVEL_MULTIPATH , .owner =THIS_MODULE ,
Signature · 1 line
2.10.0
PATCH 12/13 md/multipath: Delete an unnecessary return statement in multipath_make_request()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:55:06 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: void function return statements are not generally useful
Thus remove such a statement here.
--- drivers/md/multipath.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/multipath.c +0 -1
@@ -139,7 +139,6 @@ static void multipath_make_request(struct mddev *mddev, struct bio *bio) mp_bh->bio.bi_end_io = multipath_end_request; mp_bh->bio.bi_private = mp_bh;generic_make_request (&mp_bh->bio); -return ; }static void multipath_status (struct seq_file *seq,struct mddev *mddev)
Signature · 1 line
2.10.0
PATCH 13/13 md/multipath: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 12:42:46 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
--- drivers/md/multipath.c | 69 ++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 36 deletions(-)
drivers/md/multipath.c +33 -36
@@ -19,6 +19,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/blkdev.h> #include <linux/module.h> #include <linux/raid/md_u.h>
@@ -51,8 +53,7 @@ static int multipath_map(struct mpconf *conf) } }rcu_read_unlock (); - -printk (KERN_ERR "multipath_map(): no more operational IO paths?\n" ); +pr_err ("map: no more operational IO paths?\n" );return (-1 ); }
@@ -97,7 +98,8 @@ static void multipath_end_request(struct bio *bio)*/ char b[BDEVNAME_SIZE ];md_error (mp_bh->mddev, rdev); -printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" , + +pr_err ("%s: rescheduling sector %llu\n" ,bdevname (rdev->bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_reschedule_retry (mp_bh);
@@ -195,8 +197,7 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev)* first check if this is a queued request for a device * which has just failed. */ -printk (KERN_ALERT -"multipath: only one IO path left and IO error.\n" ); +pr_alert ("only one IO path left and IO error.\n" );/* leave it active... it's all we have */ return ; }
@@ -211,12 +212,10 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev) }set_bit (Faulty, &rdev->flags);set_bit (MD_CHANGE_DEVS , &mddev->flags); -printk (KERN_ALERT "multipath: IO failure on %s," -" disabling IO path.\n" -"multipath: Operation continuing" -" on %d IO paths.\n" , -bdevname (rdev->bdev, b), - conf->raid_disks - mddev->degraded); +pr_alert ("IO failure on %s, disabling IO path.\n" +MY_LOG_PREFIX "Operation continuing on %d IO paths.\n" , +bdevname (rdev->bdev, b), + conf->raid_disks - mddev->degraded); }static void print_multipath_conf (struct mpconf *conf)
@@ -224,21 +223,22 @@ static void print_multipath_conf(struct mpconf *conf)int i;struct multipath_info *tmp; -printk ("MULTIPATH conf printout:\n" ); +pr_info ("conf printout:\n" );if (!conf) { -printk ("(conf=NULL)\n" ); +pr_info ("(conf=NULL)\n" );return ; } -printk (" --- wd:%d rd:%d\n" , conf->raid_disks - conf->mddev->degraded, - conf->raid_disks); +pr_info ("--- wd:%d rd:%d\n" , + conf->raid_disks - conf->mddev->degraded, + conf->raid_disks);for (i =0 ; i < conf->raid_disks; i++) {char b[BDEVNAME_SIZE ]; tmp = conf->multipaths + i;if (tmp->rdev) -printk (" disk%d, o:%d, dev:%s\n" , - i, !test_bit (Faulty, &tmp->rdev->flags), -bdevname (tmp->rdev->bdev, b)); +pr_info ("disk%d, o:%d, dev:%s\n" , + i, !test_bit (Faulty, &tmp->rdev->flags), +bdevname (tmp->rdev->bdev, b)); } }
@@ -295,8 +295,8 @@ static int multipath_remove_disk(struct mddev *mddev, struct md_rdev *rdev)if (rdev = p->rdev) {if (test_bit (In_sync, &rdev->flags) ||atomic_read (&rdev->nr_pending)) { -printk (KERN_ERR "hot-remove-disk, slot %d is identified" -" but is still operational!\n" , number); +pr_err ("hot-remove-disk, slot %d is identified but is still operational!\n" , + number); err = -EBUSY ; goto abort; }
@@ -350,16 +350,14 @@ static void multipathd(struct md_thread *thread) mp_bh->path =multipath_map (conf);if (mp_bh->path <0 ) { -printk (KERN_ALERT "multipath: %s: unrecoverable IO read" -" error for block %llu\n" , -bdevname (bio->bi_bdev, b), - (unsigned long long )bio->bi_iter.bi_sector); +pr_alert ("%s: unrecoverable IO read error for block %llu\n" , +bdevname (bio->bi_bdev, b), + (unsigned long long )bio->bi_iter.bi_sector);multipath_end_bh_io (mp_bh, -EIO ); }else { -printk (KERN_ERR "multipath: %s: redirecting sector %llu" -" to another IO path\n" , -bdevname (bio->bi_bdev, b), - (unsigned long long )bio->bi_iter.bi_sector); +pr_err ("%s: redirecting sector %llu to another IO path\n" , +bdevname (bio->bi_bdev, b), + (unsigned long long )bio->bi_iter.bi_sector); *bio = *(mp_bh->master_bio); bio->bi_iter.bi_sector + conf->multipaths[mp_bh->path].rdev->data_offset;
@@ -393,8 +391,8 @@ static int multipath_run(struct mddev *mddev)return -EINVAL ;if (mddev->level !=LEVEL_MULTIPATH ) { -printk ("multipath: %s: raid level not set to multipath IO (%d)\n" , -mdname (mddev), mddev->level); +pr_notice ("%s: raid level not set to multipath IO (%d)\n" , +mdname (mddev), mddev->level); goto out; }/*
@@ -436,8 +434,7 @@ static int multipath_run(struct mddev *mddev)INIT_LIST_HEAD (&conf->retry_list);if (!working_disks) { -printk (KERN_ERR "multipath: no operational IO paths for %s\n" , -mdname (mddev)); +pr_err ("no operational IO paths for %s\n" ,mdname (mddev)); goto free_multipaths; } mddev->degraded = conf->raid_disks - working_disks;
@@ -451,10 +448,10 @@ static int multipath_run(struct mddev *mddev)if (!mddev->thread) goto destroy_pool; -printk (KERN_INFO -"multipath: array %s active with %d out of %d IO paths\n" , -mdname (mddev), conf->raid_disks - mddev->degraded, - mddev->raid_disks); +pr_info ("array %s active with %d out of %d IO paths\n" , +mdname (mddev), + conf->raid_disks - mddev->degraded, + mddev->raid_disks);/* * Ok, everything is just fine now */
Signature · 1 line
2.10.0
Re: [PATCH 4/4] virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <linux/jump_label.h>.
Quoted 10 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 9 lines
drivers/block/virtio_blk.c +2
-2@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:
I checked Documentation/CodingStyle and see no reason to rename the label.
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Re: [PATCH 4/4] virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <linux/jump_label.h>.
Quoted 10 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 9 lines
drivers/block/virtio_blk.c +2
-2@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:
I checked Documentation/CodingStyle and see no reason to rename the label.
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Re: [PATCH 3/4] virtio_blk: Delete an unnecessary initialisation in init_vq()
In reply to SF Markus ElfringQuoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static void virtblk_config_changed(struct virtio_device *vdev) · line 382
Quoted 8 lines
drivers/block/virtio_blk.c +1
-1@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
Re: [PATCH 3/4] virtio_blk: Delete an unnecessary initialisation in init_vq()
In reply to SF Markus ElfringQuoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static void virtblk_config_changed(struct virtio_device *vdev) · line 382
Quoted 8 lines
drivers/block/virtio_blk.c +1
-1@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
Re: [PATCH 1/4] virtio_blk: Use kmalloc_array() in init_vq()
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Re: [PATCH 1/4] virtio_blk: Use kmalloc_array() in init_vq()
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Re: virtio_blk: Clarification for communication difficulties?
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Quoted 8 lines
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion. Your communication style is exhausting and you've pushed into the territory where any benefits of taking the patches are not worth the time and hassle of dealing with you.
I left Reviewed-bys on two patches. Maybe they will get picked up. But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
Stefan
Re: virtio_blk: Clarification for communication difficulties?
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Quoted 8 lines
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion. Your communication style is exhausting and you've pushed into the territory where any benefits of taking the patches are not worth the time and hassle of dealing with you.
I left Reviewed-bys on two patches. Maybe they will get picked up. But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
Stefan
Re: virtio_blk: Clarification for communication difficulties?
In reply to Stefan HajnocziQuoted 3 lines
Quoted 1 line
I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion.
Thanks for another feedback.
Quoted 1 line
Your communication style is exhausting
How did you get this impression?
Quoted 1 line
and you've pushed into the territory where any benefits of taking
Would you dare to acknowledge benefits from my update suggestions for any other software components?
Quoted 1 line
the patches are not worth the time and hassle of dealing with you.
How are the chances that such a conclusion will change?
Quoted 1 line
I left Reviewed-bys on two patches.
Thanks for your constructive responses.
Quoted 1 line
Maybe they will get picked up.
I am also curious on how the software evolution will be continued.
Quoted 2 lines
But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
I risk something just by proposing so many software updates for places where change opportunities were found by special source code search patterns.
Regards,
Markus
Re: virtio_blk: Rename a jump label in virtblk_get_id()
In reply to Stefan HajnocziQuoted 4 lines
Quoted 1 line
Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <
linux/jump_label.h>.
Does a "goto" statement jump to the code position finally which is specified by the label?
Quoted 7 lines
Quoted 7 lines
drivers/block/virtio_blk.c +1
-1@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request;
Quoted 5 lines
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 3 lines
drivers/block/virtio_blk.c +1
-1err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:I checked
Documentation/CodingStyleand see no reason to rename the label.
Can the suggested longer identifier explain better the "what" and "why" for this software situation?
Quoted 2 lines
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Do you find information from a commit like "docs: Remove space-before-label guidance
from CodingStyle" (from 2016-09-21) interesting? ;-)
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817a
Regards,
Markus
Re: virtio_blk: Rename a jump label in virtblk_get_id()
In reply to Stefan HajnocziQuoted 4 lines
Quoted 1 line
Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <
linux/jump_label.h>.
Does a "goto" statement jump to the code position finally which is specified by the label?
Quoted 7 lines
Quoted 7 lines
drivers/block/virtio_blk.c +1
-1@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request;
Quoted 5 lines
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 3 lines
drivers/block/virtio_blk.c +1
-1err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:I checked
Documentation/CodingStyleand see no reason to rename the label.
Can the suggested longer identifier explain better the "what" and "why" for this software situation?
Quoted 2 lines
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Do you find information from a commit like "docs: Remove space-before-label guidance
from CodingStyle" (from 2016-09-21) interesting? ;-)
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id=79c70c304b0b443429b2a0019518532c5162817a
Regards,
Markus