Source code review around jump label usage
Subsystems (101)
Hello,
I have tried another specific analysis out on the source files of "Linux next-20151211" with help of the software "Coccinelle 1.0.4". I have taken a more detailed look on the use of the goto statement and corresponding jump labels.
Can statistics like the following support software evolution and further constructive considerations?
╔═════════════════════════════════════════╤═══════════╗ ║ target │ incidence ║ ╠═════════════════════════════════════════╪═══════════╣ ║ out │ 9782 ║ ║ done │ 1344 ║ ║ exit │ 950 ║ ║ out_unlock │ 538 ║ ║ unlock │ 509 ║ ║ bail │ 486 ║ ║ error │ 418 ║ ║ retry │ 414 ║ ║ err │ 400 ║ ║ end │ 332 ║ ║ … │ … ║ ║ abts_pending │ 1 ║ ║ abts_err │ 1 ║ ║ absolute_address │ 1 ║ ║ abort2 │ 1 ║ ║ abort_fail │ 1 ║ ║ abort_end │ 1 ║ ║ abituguru_probe_error │ 1 ║ ║ abituguru_detect_no_pwms_exit │ 1 ║ ║ abituguru_detect_bank1_sensor_type_exit │ 1 ║ ╚═════════════════════════════════════════╧═══════════╝
How often are different jump targets used within function implementations? (Functions without jump labels were not searched for this analysis approach.)
╔═════════╤═══════════╗ ║ counter │ incidence ║ ╠═════════╪═══════════╣ ║ 1 │ 18442 ║ ║ 2 │ 2002 ║ ║ 3 │ 356 ║ ║ 4 │ 106 ║ ║ 5 │ 31 ║ ║ 6 │ 7 ║ ║ 7 │ 2 ║ ║ 8 │ 3 ║ ╚═════════╧═══════════╝
How does the text length distribution look like for the used jump targets?
╔════════╤═══════════╗ ║ length │ incidence ║ ╠════════╪═══════════╣ ║ 1 │ 2 ║ ║ 2 │ 29 ║ ║ 3 │ 10640 ║ ║ 4 │ 3564 ║ ║ 5 │ 1714 ║ ║ 6 │ 1162 ║ ║ 7 │ 1245 ║ ║ 8 │ 881 ║ ║ 9 │ 787 ║ ║ 10 │ 1252 ║ ║ … │ … ║ ║ 35 │ 4 ║ ║ 36 │ 1 ║ ║ 37 │ 2 ║ ║ 38 │ 1 ║ ║ 39 │ 1 ║ ╚════════╧═══════════╝
How often are jump targets called within specific function implementations?
╔══════════════════════════╤═════════════════════════════════════════╤══════╤══════════════════════╤═════════╗ ║ function │ source file │ line │ go to │ counter ║ ╠══════════════════════════╪═════════════════════════════════════════╪══════╪══════════════════════╪═════════╣ ║ do_ipv6_setsockopt │ net/ipv6/ipv6_sockglue.c │ 140 │ e_inval │ 52 ║ ║ dvb_register │ drivers/media/pci/cx88/cx88-dvb.c │ 1005 │ frontend_detach │ 43 ║ ║ dvb_init │ drivers/media/pci/saa7134/saa7134-dvb.c │ 1210 │ detach_frontend │ 40 ║ ║ gdbstub_single_step │ arch/mn10300/kernel/gdb-stub.c │ 491 │ fault │ 38 ║ ║ uinput_ioctl_handler │ drivers/input/misc/uinput.c │ 701 │ out │ 32 ║ ║ … │ … │ … │ … │ … ║ ║ kvm_vm_compat_ioctl │ virt/kvm/kvm_main.c │ 2916 │ out │ 1 ║ ║ kvm_vm_ioctl │ virt/kvm/kvm_main.c │ 2742 │ out_free_irq_routing │ 1 ║ ║ kvm_vm_ioctl_create_vcpu │ virt/kvm/kvm_main.c │ 2257 │ vcpu_destroy │ 1 ║ ╚══════════════════════════╧═════════════════════════════════════════╧══════╧══════════════════════╧═════════╝
Do any of these numbers indicate update candidates which correspond to the "one error jump label bug" symptom that is mentioned in the Linux coding style documentation?
Regards,
Markus
Quoted 3 lines
Do any of these numbers indicate update candidates which correspond to the "one error jump label bug" symptom that is mentioned in the Linux coding style documentation?
I don't think that numbers could indicate that. The point of that is a single label followed by a bunch of ifs, or by calls to functions that perform tests on input validity. That is, it is the content of the code that causes the problem, not its size. Dan also discourages the use of labels like out, that don't indicate anything about anything, or kmalloc_err, which don't indicate anything about what happens at the label target.
julia
I hate out labels but a lot of people like them and they're not prohibited by kernel style. I only complain about them when they introduce bugs.
regards,
dan carpenter
Quoted 14 lines · SF Markus Elfring
How does the text length distribution look like for the used jump targets?
╔════════╤═══════════╗ ║ length │ incidence ║ ╠════════╪═══════════╣ ║ 1 │ 2 ║ ║ 2 │ 29 ║ ║ 3 │ 10640 ║ ║ 4 │ 3564 ║ ║ 5 │ 1714 ║ ║ 6 │ 1162 ║ ║ 7 │ 1245 ║ ║ 8 │ 881 ║ ║ 9 │ 787 ║
Quoted 9 lines
║ 10 │ 1252 ║ ║ … │ … ║ ║ 35 │ 4 ║ ║ 36 │ 1 ║ ║ 37 │ 2 ║ ║ 38 │ 1 ║ ║ 39 │ 1 ║ ╚════════╧═══════════╝
Maybe having a look at the 1 or 2 chars long labels would make sense. They are likely to be too short for being of any use.
IMHO, too long labels may also reduce readability.
Best regards,
CJ
cover block: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 19:12:34 +0100
A few update suggestions were taken into account from static source code analysis.
Markus Elfring (2):
zram: Less checks in zram_bvec_write() after error detection
z2ram: Delete a jump label in z2_init()
drivers/block/z2ram.c | 4 +--- drivers/block/zram/zram_drv.c | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 zram: Less checks in zram_bvec_write() after error detection
From: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 18:20:59 +0100
This issue was detected by using the Coccinelle software.
A few checks could be repeated by the zram_bvec_write() function at two places even if the passed variables contained a null pointer.
* This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention.
* Let us return directly if a memory allocation failed.
* Drop unnecessary initialisations for the variables "uncmem" and "zstrm" then.
--- drivers/block/zram/zram_drv.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/block/zram/zram_drv.c +13 -13
@@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,size_t clen;unsigned long handle;struct page *page; -unsigned char *user_mem, *cmem, *src, *uncmem =NULL ; +unsigned char *user_mem, *cmem, *src, *uncmem;struct zram_meta *meta = zram->meta; -struct zcomp_strm *zstrm =NULL ; +struct zcomp_strm *zstrm;unsigned long alloced_pages; page = bvec->bv_page;
@@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,* before to write the changes. */ uncmem =kmalloc (PAGE_SIZE ,GFP_NOIO ); -if (!uncmem) { - ret = -ENOMEM ; - goto out; - } +if (!uncmem) +return -ENOMEM ; ret =zram_decompress_page (zram, uncmem, index);if (ret) - goto out; + goto free_uncmem; } zstrm =zcomp_strm_find (zram->comp);
@@ -696,7 +694,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,atomic64_inc (&zram->stats.zero_pages); ret =0 ; - goto out; + goto check_strm; } ret =zcomp_compress (zram->comp, zstrm, uncmem, &clen);
@@ -708,7 +706,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,if (unlikely (ret)) {pr_err ("Compression failed! err=%d\n" , ret); - goto out; + goto check_strm; } src = zstrm->buffer;if (unlikely (clen > max_zpage_size)) {
@@ -722,7 +720,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,pr_err ("Error allocating memory for compressed page: %u, size=%zu\n" , index, clen); ret = -ENOMEM ; - goto out; + goto check_strm; } alloced_pages =zs_get_total_pages (meta->mem_pool);
@@ -731,7 +729,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,if (zram->limit_pages && alloced_pages > zram->limit_pages) {zs_free (meta->mem_pool, handle); ret = -ENOMEM ; - goto out; + goto check_strm; } cmem =zs_map_object (meta->mem_pool, handle,ZS_MM_WO );
@@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,/* Update stats */ atomic64_add (clen, &zram->stats.compr_data_size);atomic64_inc (&zram->stats.pages_stored); -out: +check_strm:if (zstrm)zcomp_strm_release (zram->comp, zstrm); -if (is_partial_io (bvec)) +if (is_partial_io (bvec)) { +free_uncmem:kfree (uncmem); + }return ret; }
Signature · 1 line
2.6.3
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
On (12/11/15 19:24), SF Markus Elfring wrote:
[..]
Quoted 17 lines
drivers/block/zram/zram_drv.c +2
-2@@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,size_t clen;unsigned long handle;struct page *page; -unsigned char *user_mem, *cmem, *src, *uncmem =NULL ; +unsigned char *user_mem, *cmem, *src, *uncmem;struct zram_meta *meta = zram->meta; -struct zcomp_strm *zstrm =NULL ; +struct zcomp_strm *zstrm;unsigned long alloced_pages; page = bvec->bv_page;
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 668
Quoted 9 lines
drivers/block/zram/zram_drv.c +2
-4@@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,* before to write the changes. */ uncmem =kmalloc (PAGE_SIZE ,GFP_NOIO ); -if (!uncmem) { - ret = -ENOMEM ; - goto out; - } +if (!uncmem) +return -ENOMEM ;
ok.
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 671
Quoted 4 lines
drivers/block/zram/zram_drv.c +1
-1ret =zram_decompress_page (zram, uncmem, index);if (ret) - goto out; + goto free_uncmem;
here and later, I don't want to split `out' label.
you still need to do both 'if zstrm' and 'if is_partial_io' checks anyway, what's the gain? the more labels we have the trickier it may get.
Quoted 42 lines
drivers/block/zram/zram_drv.c +4
-4} zstrm =zcomp_strm_find (zram->comp);@@ -696,7 +694,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,atomic64_inc (&zram->stats.zero_pages); ret =0 ; - goto out; + goto check_strm; } ret =zcomp_compress (zram->comp, zstrm, uncmem, &clen);@@ -708,7 +706,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,if (unlikely (ret)) {pr_err ("Compression failed! err=%d\n" , ret); - goto out; + goto check_strm; } src = zstrm->buffer;if (unlikely (clen > max_zpage_size)) {@@ -722,7 +720,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,pr_err ("Error allocating memory for compressed page: %u, size=%zu\n" , index, clen); ret = -ENOMEM ; - goto out; + goto check_strm; } alloced_pages =zs_get_total_pages (meta->mem_pool);@@ -731,7 +729,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,if (zram->limit_pages && alloced_pages > zram->limit_pages) {zs_free (meta->mem_pool, handle); ret = -ENOMEM ; - goto out; + goto check_strm; } cmem =zs_map_object (meta->mem_pool, handle,ZS_MM_WO );@@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,/* Update stats */ atomic64_add (clen, &zram->stats.compr_data_size);
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 769
Quoted 10 lines
drivers/block/zram/zram_drv.c +4
-2atomic64_inc (&zram->stats.pages_stored); -out: +check_strm:if (zstrm)zcomp_strm_release (zram->comp, zstrm); -if (is_partial_io (bvec)) +if (is_partial_io (bvec)) { +free_uncmem:kfree (uncmem); + }
a label inside of `if'? no.
keep it the way it is please.
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 771
Quoted 2 lines
drivers/block/zram/zram_drv.c +0
-0return ret; }
-ss
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
Quoted 15 lines
Quoted 15 lines
drivers/block/zram/zram_drv.c +2
-2@@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,size_t clen;unsigned long handle;struct page *page; -unsigned char *user_mem, *cmem, *src, *uncmem =NULL ; +unsigned char *user_mem, *cmem, *src, *uncmem;struct zram_meta *meta = zram->meta; -struct zcomp_strm *zstrm =NULL ; +struct zcomp_strm *zstrm;unsigned long alloced_pages;
Quoted 13 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 668
Quoted 11 lines
drivers/block/zram/zram_drv.c +2
-4page = bvec->bv_page;@@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,* before to write the changes. */ uncmem =kmalloc (PAGE_SIZE ,GFP_NOIO ); -if (!uncmem) { - ret = -ENOMEM ; - goto out; - } +if (!uncmem) +return -ENOMEM ;ok.
Thanks for your terse acknowledgement.
Quoted 6 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 671
Quoted 4 lines
drivers/block/zram/zram_drv.c +1
-1ret =zram_decompress_page (zram, uncmem, index);if (ret) - goto out; + goto free_uncmem;here and later, I don't want to split `out' label.
I guess that corresponding software design concerns can evolve a bit.
Quoted 1 line
you still need to do both 'if zstrm' and 'if
is_partial_io' checks anyway, what's the gain?
How are the chances to reduce the number of dispensable sanity checks?
Quoted 1 line
the more labels we have the trickier it may get.
I hope that more unique jump labels can make the involved exception handling also clearer.
Quoted 7 lines
Quoted 7 lines
drivers/block/zram/zram_drv.c +1
-1@@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,/* Update stats */ atomic64_add (clen, &zram->stats.compr_data_size);atomic64_inc (&zram->stats.pages_stored); -out: +check_strm:if (zstrm)
Quoted 8 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 769
Quoted 6 lines
drivers/block/zram/zram_drv.c +3
-1zcomp_strm_release (zram->comp, zstrm); -if (is_partial_io (bvec)) +if (is_partial_io (bvec)) { +free_uncmem:kfree (uncmem); + }a label inside of `if'? no.
Do any more software developers find such an use case interesting?
Quoted 1 line
keep it the way it is please.
I suggest to make the affected exception handling a bit more efficient. Such source code fine-tuning has got a few special consequences.
Regards,
Markus
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
Quoted 2 lines
I suggest to make the affected exception handling a bit more efficient. Such source code fine-tuning has got a few special consequences.
Exception handling is by definition exceptional, and thus its efficiency is rarely important. What is important is that it should be correct, and ideally clearly correct, so that someone can check its correctness easily. Optimizations, if they have any effect at all, typically make the correctness less obvious.
julia
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
In reply to SF Markus ElfringOn (12/14/15 07:58), SF Markus Elfring wrote:
[..]
Quoted 4 lines
Quoted 1 line
keep it the way it is please.
I suggest to make the affected exception handling a bit more efficient. Such source code fine-tuning has got a few special consequences.
by 'more efficient' you mean saving cpu cycles on 'bvec->bv_len != PAGE_SIZE' comparison in exception/error path?
...check_strm:
if (zstrm)
zcomp_strm_release(zram->comp, zstrm);
if (is_partial_io(bvec)) {
free_uncmem:
kfree(uncmem);
}...
no.
-ss
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
Quoted 5 lines
Quoted 2 lines
I suggest to make the affected exception handling a bit more efficient. Such source code fine-tuning has got a few special consequences.
by 'more efficient' you mean saving cpu cycles on '
bvec->bv_len!=PAGE_SIZE' comparison in exception/error path?
Yes …
Quoted 9 lines
...
check_strm:if (zstrm) zcomp_strm_release(zram->comp, zstrm); if (is_partial_io(bvec)) { free_uncmem: kfree(uncmem); }...
I propose to jump over two sanity checks.
Quoted 1 line
no.
Thanks for your feedback.
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
PATCH 2/2 z2ram: Delete a jump label in z2_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 18:48:14 +0100
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "register_blkdev" failed.
* Remove the jump label "err" then.
--- drivers/block/z2ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/z2ram.c +1 -3
@@ -345,9 +345,8 @@ z2_init(void)if (!MACH_IS_AMIGA )return -ENODEV ; - ret = -EBUSY ;if (register_blkdev (Z2RAM_MAJOR ,DEVICE_NAME )) - goto err; +return -EBUSY ; ret = -ENOMEM ; z2ram_gendisk =alloc_disk (1 );
@@ -374,7 +373,6 @@ out_queue:put_disk (z2ram_gendisk); out_disk:unregister_blkdev (Z2RAM_MAJOR ,DEVICE_NAME ); -err:return ret; }
Signature · 1 line
2.6.3
Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()
Cc Jens, Andrew, Geert
Quoted 28 lines · SF Markus Elfring
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "
register_blkdev" failed.* Remove the jump label "err" then.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/z2ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/block/z2ram.c +1
-2@@ -345,9 +345,8 @@ z2_init(void)if (!MACH_IS_AMIGA )return -ENODEV ; - ret = -EBUSY ;if (register_blkdev (Z2RAM_MAJOR ,DEVICE_NAME )) - goto err; +return -EBUSY ; ret = -ENOMEM ; z2ram_gendisk =alloc_disk (1 );
drivers/block/z2ram.c out_queue: · line 377
Quoted 6 lines
drivers/block/z2ram.c +0
-1@@ -374,7 +373,6 @@ out_queue:put_disk (z2ram_gendisk); out_disk:unregister_blkdev (Z2RAM_MAJOR ,DEVICE_NAME ); -err:return ret; }
z2ram and zram are different drivers, but the change looks ok to me.
z2ram can be improved in many ways, so my question is - do people still use it?
-ss
Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()
Quoted 11 lines · Sergey Senozhatsky
Cc Jens, Andrew, Geert
Quoted 8 lines · SF Markus Elfring
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "
register_blkdev" failed.* Remove the jump label "err" then.
Signed-off-by Markus Elfring <[email protected]>
Quoted 30 lines
Quoted 20 lines
--- drivers/block/z2ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/block/z2ram.c +1
-2@@ -345,9 +345,8 @@ z2_init(void)if (!MACH_IS_AMIGA )return -ENODEV ; - ret = -EBUSY ;if (register_blkdev (Z2RAM_MAJOR ,DEVICE_NAME )) - goto err; +return -EBUSY ; ret = -ENOMEM ; z2ram_gendisk =alloc_disk (1 );drivers/block/z2ram.c out_queue: · line 377
Quoted 6 lines
drivers/block/z2ram.c +0
-1@@ -374,7 +373,6 @@ out_queue:put_disk (z2ram_gendisk); out_disk:unregister_blkdev (Z2RAM_MAJOR ,DEVICE_NAME ); -err:return ret; }z2ram and zram are different drivers, but the change looks ok to me.
Quoted 2 lines
z2ram can be improved in many ways, so my question is - do people still use it?
I think it's still used.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
PATCH 1/1 uinput: Rename a jump label in uinput_ioctl_handler()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 10:06:00 +0100
This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention.
--- drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-)
drivers/input/misc/uinput.c +33 -33
@@ -717,7 +717,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,if (!udev->dev) { retval =uinput_allocate_device (udev);if (retval) - goto out; + goto unlock; }switch (cmd) {
@@ -725,82 +725,82 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,if (put_user (UINPUT_VERSION , (unsigned int __user *)p)) retval = -EFAULT ; - goto out; + goto unlock;case UI_DEV_CREATE : retval =uinput_create_device (udev); - goto out; + goto unlock;case UI_DEV_DESTROY :uinput_destroy_device (udev); - goto out; + goto unlock;case UI_SET_EVBIT : retval =uinput_set_bit (arg, evbit,EV_MAX ); - goto out; + goto unlock;case UI_SET_KEYBIT : retval =uinput_set_bit (arg, keybit,KEY_MAX ); - goto out; + goto unlock;case UI_SET_RELBIT : retval =uinput_set_bit (arg, relbit,REL_MAX ); - goto out; + goto unlock;case UI_SET_ABSBIT : retval =uinput_set_bit (arg, absbit,ABS_MAX ); - goto out; + goto unlock;case UI_SET_MSCBIT : retval =uinput_set_bit (arg, mscbit,MSC_MAX ); - goto out; + goto unlock;case UI_SET_LEDBIT : retval =uinput_set_bit (arg, ledbit,LED_MAX ); - goto out; + goto unlock;case UI_SET_SNDBIT : retval =uinput_set_bit (arg, sndbit,SND_MAX ); - goto out; + goto unlock;case UI_SET_FFBIT : retval =uinput_set_bit (arg, ffbit,FF_MAX ); - goto out; + goto unlock;case UI_SET_SWBIT : retval =uinput_set_bit (arg, swbit,SW_MAX ); - goto out; + goto unlock;case UI_SET_PROPBIT : retval =uinput_set_bit (arg, propbit,INPUT_PROP_MAX ); - goto out; + goto unlock;case UI_SET_PHYS :if (udev->state =UIST_CREATED ) { retval = -EINVAL ; - goto out; + goto unlock; } phys =strndup_user (p,1024 );if (IS_ERR (phys)) { retval =PTR_ERR (phys); - goto out; + goto unlock; }kfree (udev->dev->phys); udev->dev->phys = phys; - goto out; + goto unlock;case UI_BEGIN_FF_UPLOAD : retval =uinput_ff_upload_from_user (p, &ff_up);if (retval) - goto out; + goto unlock; req =uinput_request_find (udev, ff_up.request_id);if (!req || req->code !=UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL ; - goto out; + goto unlock; } ff_up.retval =0 ;
@@ -811,60 +811,60 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,memset (&ff_up.old,0 ,sizeof (struct ff_effect )); retval =uinput_ff_upload_to_user (p, &ff_up); - goto out; + goto unlock;case UI_BEGIN_FF_ERASE :if (copy_from_user (&ff_erase, p,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } req =uinput_request_find (udev, ff_erase.request_id);if (!req || req->code !=UI_FF_ERASE ) { retval = -EINVAL ; - goto out; + goto unlock; } ff_erase.retval =0 ; ff_erase.effect_id = req->u.effect_id;if (copy_to_user (p, &ff_erase,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } - goto out; + goto unlock;case UI_END_FF_UPLOAD : retval =uinput_ff_upload_from_user (p, &ff_up);if (retval) - goto out; + goto unlock; req =uinput_request_find (udev, ff_up.request_id);if (!req || req->code !=UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL ; - goto out; + goto unlock; } req->retval = ff_up.retval;uinput_request_done (udev, req); - goto out; + goto unlock;case UI_END_FF_ERASE :if (copy_from_user (&ff_erase, p,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } req =uinput_request_find (udev, ff_erase.request_id);if (!req || req->code !=UI_FF_ERASE ) { retval = -EINVAL ; - goto out; + goto unlock; } req->retval = ff_erase.retval;uinput_request_done (udev, req); - goto out; + goto unlock; } size =_IOC_SIZE (cmd);
@@ -874,15 +874,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,case UI_GET_SYSNAME (0 ):if (udev->state !=UIST_CREATED ) { retval = -ENOENT ; - goto out; + goto unlock; } name =dev_name (&udev->dev->dev); retval =uinput_str_to_user (p, name, size); - goto out; + goto unlock; } retval = -EINVAL ; - out: + unlock:mutex_unlock (&udev->mutex);return retval; }
Signature · 1 line
2.6.3
Dmitry Torokhov
maintainerRe: [PATCH] uinput: Rename a jump label in uinput_ioctl_handler()
Hi Markus,
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 10:06:00 +0100This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention.
While I am mildly curious where you found this Coccinelle script complaining about label names I find the current name is perfectly fine.
Thanks.
Quoted 214 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-)drivers/input/misc/uinput.c +33
-33@@ -717,7 +717,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,if (!udev->dev) { retval =uinput_allocate_device (udev);if (retval) - goto out; + goto unlock; }switch (cmd) {@@ -725,82 +725,82 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,if (put_user (UINPUT_VERSION , (unsigned int __user *)p)) retval = -EFAULT ; - goto out; + goto unlock;case UI_DEV_CREATE : retval =uinput_create_device (udev); - goto out; + goto unlock;case UI_DEV_DESTROY :uinput_destroy_device (udev); - goto out; + goto unlock;case UI_SET_EVBIT : retval =uinput_set_bit (arg, evbit,EV_MAX ); - goto out; + goto unlock;case UI_SET_KEYBIT : retval =uinput_set_bit (arg, keybit,KEY_MAX ); - goto out; + goto unlock;case UI_SET_RELBIT : retval =uinput_set_bit (arg, relbit,REL_MAX ); - goto out; + goto unlock;case UI_SET_ABSBIT : retval =uinput_set_bit (arg, absbit,ABS_MAX ); - goto out; + goto unlock;case UI_SET_MSCBIT : retval =uinput_set_bit (arg, mscbit,MSC_MAX ); - goto out; + goto unlock;case UI_SET_LEDBIT : retval =uinput_set_bit (arg, ledbit,LED_MAX ); - goto out; + goto unlock;case UI_SET_SNDBIT : retval =uinput_set_bit (arg, sndbit,SND_MAX ); - goto out; + goto unlock;case UI_SET_FFBIT : retval =uinput_set_bit (arg, ffbit,FF_MAX ); - goto out; + goto unlock;case UI_SET_SWBIT : retval =uinput_set_bit (arg, swbit,SW_MAX ); - goto out; + goto unlock;case UI_SET_PROPBIT : retval =uinput_set_bit (arg, propbit,INPUT_PROP_MAX ); - goto out; + goto unlock;case UI_SET_PHYS :if (udev->state =UIST_CREATED ) { retval = -EINVAL ; - goto out; + goto unlock; } phys =strndup_user (p,1024 );if (IS_ERR (phys)) { retval =PTR_ERR (phys); - goto out; + goto unlock; }kfree (udev->dev->phys); udev->dev->phys = phys; - goto out; + goto unlock;case UI_BEGIN_FF_UPLOAD : retval =uinput_ff_upload_from_user (p, &ff_up);if (retval) - goto out; + goto unlock; req =uinput_request_find (udev, ff_up.request_id);if (!req || req->code !=UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL ; - goto out; + goto unlock; } ff_up.retval =0 ;@@ -811,60 +811,60 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,memset (&ff_up.old,0 ,sizeof (struct ff_effect )); retval =uinput_ff_upload_to_user (p, &ff_up); - goto out; + goto unlock;case UI_BEGIN_FF_ERASE :if (copy_from_user (&ff_erase, p,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } req =uinput_request_find (udev, ff_erase.request_id);if (!req || req->code !=UI_FF_ERASE ) { retval = -EINVAL ; - goto out; + goto unlock; } ff_erase.retval =0 ; ff_erase.effect_id = req->u.effect_id;if (copy_to_user (p, &ff_erase,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } - goto out; + goto unlock;case UI_END_FF_UPLOAD : retval =uinput_ff_upload_from_user (p, &ff_up);if (retval) - goto out; + goto unlock; req =uinput_request_find (udev, ff_up.request_id);if (!req || req->code !=UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL ; - goto out; + goto unlock; } req->retval = ff_up.retval;uinput_request_done (udev, req); - goto out; + goto unlock;case UI_END_FF_ERASE :if (copy_from_user (&ff_erase, p,sizeof (ff_erase))) { retval = -EFAULT ; - goto out; + goto unlock; } req =uinput_request_find (udev, ff_erase.request_id);if (!req || req->code !=UI_FF_ERASE ) { retval = -EINVAL ; - goto out; + goto unlock; } req->retval = ff_erase.retval;uinput_request_done (udev, req); - goto out; + goto unlock; } size =_IOC_SIZE (cmd);@@ -874,15 +874,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,case UI_GET_SYSNAME (0 ):if (udev->state !=UIST_CREATED ) { retval = -ENOENT ; - goto out; + goto unlock; } name =dev_name (&udev->dev->dev); retval =uinput_str_to_user (p, name, size); - goto out; + goto unlock; } retval = -EINVAL ; - out: + unlock:mutex_unlock (&udev->mutex);return retval; }Signature · 1 line
2.6.3
Signature · 1 line
Dmitry
cover iSCSI-target: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:25:20 +0100
Some update suggestions were taken into account from static source code analysis.
Markus Elfring (7):
Use a variable initialisation in iscsi_set_default_param() directly
Less checks in iscsi_set_default_param() after error detection
Delete an unnecessary variable initialisation in iscsi_create_default_params() Make a variable initialisation a bit more obvious in iscsi_create_default_params() Rename a jump label in iscsi_create_default_params()
Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support() Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()
drivers/target/iscsi/iscsi_target_parameters.c | 100 ++++++++++++------------- 1 file changed, 47 insertions(+), 53 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/7 iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100
Omit the unnecessary setting to a null pointer for the variable "param" at the beginning of the function "iscsi_set_default_param" because it can be directly initialized with the return value from the function "kzalloc".
--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -2
@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para char *name, char *value, u8 phase, u8 scope, u8 sender, u16 type_range, u8 use) { - struct iscsi_param *param = NULL; + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL); - param =kzalloc (sizeof (struct iscsi_param ),GFP_KERNEL );if (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); goto out;
Signature · 1 line
2.6.3
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100Omit the unnecessary setting to a null pointer for the variable "param" at the beginning of the function "
iscsi_set_default_param" because it can be directly initialized with the return value from the function "kzalloc".Signed-off-by Markus Elfring <[email protected]>--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 10 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para char *name, char *value, u8 phase, u8 scope, u8 sender, u16 type_range, u8 use) { - struct iscsi_param *param = NULL; + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL); - param =kzalloc (sizeof (struct iscsi_param ),GFP_KERNEL );if (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); goto out;
It's better to just get rid of the initialization but leave the kzalloc() as-is for two reasons.
1) Initializer code normally contains more bugs per line than other code. I am thinking about dereferencing pointers before checking for NULL or not checking the allocation for failure.
2) It puts a blank line between the allocation and the check for failure. It's like a new paragraph. The allocation and the check should be next to each other.
regards,
dan carpenter
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
Quoted 15 lines
drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para char *name, char *value, u8 phase, u8 scope, u8 sender, u16 type_range, u8 use) { - struct iscsi_param *param = NULL; + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL); - param =kzalloc (sizeof (struct iscsi_param ),GFP_KERNEL );if (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); goto out;It's better to just get rid of the initialization but leave the
kzalloc()as-is for two reasons.
Quoted 3 lines
1) Initializer code normally contains more bugs per line than other code. I am thinking about dereferencing pointers before checking for NULL or not checking the allocation for failure.
I can follow your concerns a bit.
Quoted 1 line
2) It puts a blank line between the allocation and the check for failure.
Is there a target conflict between "convenient" variable initialisation in the declaration section and the function outline that seems to be checked by the script "checkpatch.pl" to some degree while corresponding preferences or recommendations are not mentioned in the document "CodingStyle"?
Quoted 1 line
It's like a new paragraph.
I do not see the separation in a strict way so far.
Quoted 1 line
The allocation and the check should be next to each other.
I find that these actions are still close enough in the discussed use case.
Regards,
Markus
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
In reply to Dan CarpenterQuoted 33 lines · Dan Carpenter
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100Omit the unnecessary setting to a null pointer for the variable "param" at the beginning of the function "
iscsi_set_default_param" because it can be directly initialized with the return value from the function "kzalloc".Signed-off-by Markus Elfring <[email protected]>--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 10 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para char *name, char *value, u8 phase, u8 scope, u8 sender, u16 type_range, u8 use) { - struct iscsi_param *param = NULL; + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL); - param =kzalloc (sizeof (struct iscsi_param ),GFP_KERNEL );if (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); goto out;It's better to just get rid of the initialization but leave the
kzalloc()as-is for two reasons.
Quoted 7 lines
1) Initializer code normally contains more bugs per line than other code. I am thinking about dereferencing pointers before checking for NULL or not checking the allocation for failure.
2) It puts a blank line between the allocation and the check for failure. It's like a new paragraph. The allocation and the check should be next to each other.
I agree with Dan here. Please don't do it.
@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
char *name, char *value, u8 phase, u8 scope, u8 sender,
u16 type_range, u8 use)
{
- struct iscsi_param *param = NULL;
+ struct iscsi_param *param;
param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
if (!param) {
pr_err("Unable to allocate memory for parameter.\n");
This way it would be _far_ more readable. IMHO one should have a 1 action per line of code style and only assign values in at declaration time if really necessary.
But what is the benefit from this? Is it fixing a (hypothetical) bug? I somehow fail to see it.
Thanks,
Johannes
Signature · 10 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 -- 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 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
Quoted 12 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-1@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para char *name, char *value, u8 phase, u8 scope, u8 sender, u16 type_range, u8 use) { - struct iscsi_param *param = NULL; + struct iscsi_param *param; param =kzalloc (sizeof (struct iscsi_param ),GFP_KERNEL );if (!param) {pr_err ("Unable to allocate memory for parameter.\n" );
Quoted 1 line
This way it would be _far_ more readable.
I guess that there are some opinions available for this implementation detail.
Quoted 1 line
IMHO one should have a 1 action per line of code style
How often do you care for such style issues?
Quoted 1 line
and only assign values in at declaration time if really necessary.
Which is or might become the official Linux coding style recommendation for this aspect?
Quoted 1 line
But what is the benefit from this? Is it fixing a (hypothetical) bug?
I find the shown null pointer initialisation just needless.
Regards,
Markus
PATCH 2/7 iscsi-target: Less checks in iscsi_set_default_param() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 12:50:10 +0100
This issue was detected by using the Coccinelle software.
A sanity check would be performed by the iscsi_set_default_param() function even if it is known already that the passed variable contained a null pointer.
* This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention.
* Let us return directly if a call of the function "kzalloc" failed.
--- drivers/target/iscsi/iscsi_target_parameters.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +10 -11
@@ -131,20 +131,20 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *paraif (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); - goto out; +return NULL ; }INIT_LIST_HEAD (¶m->p_list); param->name =kstrdup (name,GFP_KERNEL );if (!param->name) {pr_err ("Unable to allocate memory for parameter name.\n" ); - goto out; + goto free_param; } param->value =kstrdup (value,GFP_KERNEL );if (!param->value) {pr_err ("Unable to allocate memory for parameter value.\n" ); - goto out; + goto free_name; } param->phase = phase;
@@ -182,18 +182,17 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *paradefault :pr_err ("Unknown type_range 0x%02x\n" , param->type_range); - goto out; + goto free_value; }list_add_tail (¶m->p_list, ¶m_list->param_list);return param; -out: -if (param) { -kfree (param->value); -kfree (param->name); -kfree (param); - } - +free_value: +kfree (param->value); +free_name: +kfree (param->name); +free_param: +kfree (param);return NULL ; }
Signature · 1 line
2.6.3
PATCH 3/7 iscsi-target: Delete an unnecessary variable initialisation in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:20:08 +0100
The variable "param" will eventually be set to an appropriate pointer from a call of the iscsi_set_default_param() function. Thus let us omit the explicit initialisation at the beginning.
--- drivers/target/iscsi/iscsi_target_parameters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -1
@@ -199,7 +199,7 @@ free_param:/* #warning Add extension keys */ int iscsi_create_default_params (struct iscsi_param_list **param_list_ptr) { -struct iscsi_param *param =NULL ; +struct iscsi_param *param;struct iscsi_param_list *pl; pl =kzalloc (sizeof (struct iscsi_param_list ),GFP_KERNEL );
Signature · 1 line
2.6.3
PATCH 4/7 iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:44:06 +0100
The variable "pl" was declared and immediately assigned a return value from a function call in a separate statement.
* Let us express the desired variable initialisation directly.
* Avoid the repetition of the data type specification for the involved memory allocation according to the Linux coding style convention.
--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -2
@@ -200,9 +200,8 @@ free_param:int iscsi_create_default_params (struct iscsi_param_list **param_list_ptr) {struct iscsi_param *param; -struct iscsi_param_list *pl; +struct iscsi_param_list *pl =kzalloc (sizeof (*pl),GFP_KERNEL ); - pl =kzalloc (sizeof (struct iscsi_param_list ),GFP_KERNEL );if (!pl) {pr_err ("Unable to allocate memory for" " struct iscsi_param_list.\n" );
Signature · 1 line
2.6.3
Re: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
Quoted 22 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:44:06 +0100The variable "pl" was declared and immediately assigned a return value from a function call in a separate statement.
* Let us express the desired variable initialisation directly.
* Avoid the repetition of the data type specification for the involved memory allocation according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c free_param: · line 205
Quoted 7 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -200,9 +200,8 @@ free_param:int iscsi_create_default_params (struct iscsi_param_list **param_list_ptr) {struct iscsi_param *param; -struct iscsi_param_list *pl; +struct iscsi_param_list *pl =kzalloc (sizeof (*pl),GFP_KERNEL ); - pl =kzalloc (sizeof (struct iscsi_param_list ),GFP_KERNEL );
I don't see the benefit of this change, and the pattern assignment -> failure test becomes more obscure.
julia
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c +0
-1if (!pl) {pr_err ("Unable to allocate memory for" " struct iscsi_param_list.\n" ); --2.6.3
--
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 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c free_param: · line 205
Quoted 8 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -200,9 +200,8 @@ free_param:int iscsi_create_default_params (struct iscsi_param_list **param_list_ptr) {struct iscsi_param *param; -struct iscsi_param_list *pl; +struct iscsi_param_list *pl =kzalloc (sizeof (*pl),GFP_KERNEL ); - pl =kzalloc (sizeof (struct iscsi_param_list ),GFP_KERNEL );I don't see the benefit of this change, and the pattern assignment -> failure test becomes more obscure.
Are there any more software developers who prefer to specify such a variable initialisation on a single line?
Does the proposed small source code reduction matter for you?
Regards,
Markus
PATCH 5/7 iscsi-target: Rename a jump label in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 14:12:50 +0100
This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention.
--- drivers/target/iscsi/iscsi_target_parameters.c | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +32 -32
@@ -225,185 +225,185 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)PHASE_SECURITY ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH , TYPERANGE_AUTH, USE_INITIAL_ONLY);if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,HEADERDIGEST ,INITIAL_HEADERDIGEST ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_DIGEST ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,DATADIGEST ,INITIAL_DATADIGEST ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_DIGEST ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,MAXCONNECTIONS ,INITIAL_MAXCONNECTIONS ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_1_TO_65535 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,SENDTARGETS ,INITIAL_SENDTARGETS ,PHASE_FFP0 ,SCOPE_SESSION_WIDE ,SENDER_INITIATOR ,TYPERANGE_UTF8 ,0 );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,TARGETNAME ,INITIAL_TARGETNAME ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_ISCSINAME ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,INITIATORNAME ,INITIAL_INITIATORNAME ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_INITIATOR ,TYPERANGE_ISCSINAME ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,TARGETALIAS ,INITIAL_TARGETALIAS ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_TARGET ,TYPERANGE_UTF8 ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,INITIATORALIAS ,INITIAL_INITIATORALIAS ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_INITIATOR ,TYPERANGE_UTF8 ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,TARGETADDRESS ,INITIAL_TARGETADDRESS ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_TARGET ,TYPERANGE_TARGETADDRESS ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,TARGETPORTALGROUPTAG ,INITIAL_TARGETPORTALGROUPTAG ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_TARGET ,TYPERANGE_0_TO_65535 ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,INITIALR2T ,INITIAL_INITIALR2T ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_BOOL_OR ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,IMMEDIATEDATA ,INITIAL_IMMEDIATEDATA ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_BOOL_AND ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,MAXXMITDATASEGMENTLENGTH ,INITIAL_MAXXMITDATASEGMENTLENGTH ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,MAXRECVDATASEGMENTLENGTH ,INITIAL_MAXRECVDATASEGMENTLENGTH ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,MAXBURSTLENGTH ,INITIAL_MAXBURSTLENGTH ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,FIRSTBURSTLENGTH ,INITIAL_FIRSTBURSTLENGTH ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,DEFAULTTIME2WAIT ,INITIAL_DEFAULTTIME2WAIT ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_0_TO_3600 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,DEFAULTTIME2RETAIN ,INITIAL_DEFAULTTIME2RETAIN ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_0_TO_3600 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,MAXOUTSTANDINGR2T ,INITIAL_MAXOUTSTANDINGR2T ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_1_TO_65535 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,DATAPDUINORDER ,INITIAL_DATAPDUINORDER ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_BOOL_OR ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,DATASEQUENCEINORDER ,INITIAL_DATASEQUENCEINORDER ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_BOOL_OR ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,ERRORRECOVERYLEVEL ,INITIAL_ERRORRECOVERYLEVEL ,PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH ,TYPERANGE_0_TO_2 ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,SESSIONTYPE ,INITIAL_SESSIONTYPE ,PHASE_DECLARATIVE ,SCOPE_SESSION_WIDE ,SENDER_INITIATOR ,TYPERANGE_SESSIONTYPE ,USE_LEADING_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,IFMARKER ,INITIAL_IFMARKER ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_BOOL_AND ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,OFMARKER ,INITIAL_OFMARKER ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_BOOL_AND ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,IFMARKINT ,INITIAL_IFMARKINT ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_UTF8 ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,OFMARKINT ,INITIAL_OFMARKINT ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_UTF8 ,USE_INITIAL_ONLY );if (!param) - goto out; + goto release_list;/* * Extra parameters for ISER from RFC-5046
@@ -412,25 +412,25 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)PHASE_OPERATIONAL ,SCOPE_SESSION_WIDE ,SENDER_BOTH , TYPERANGE_BOOL_AND, USE_LEADING_ONLY);if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,INITIATORRECVDATASEGMENTLENGTH ,INITIAL_INITIATORRECVDATASEGMENTLENGTH ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_ALL );if (!param) - goto out; + goto release_list; param =iscsi_set_default_param (pl,TARGETRECVDATASEGMENTLENGTH ,INITIAL_TARGETRECVDATASEGMENTLENGTH ,PHASE_OPERATIONAL ,SCOPE_CONNECTION_ONLY ,SENDER_BOTH ,TYPERANGE_512_TO_16777215 ,USE_ALL );if (!param) - goto out; + goto release_list; *param_list_ptr = pl;return 0 ; -out: +release_list:iscsi_release_param_list (pl);return -1 ; }
Signature · 1 line
2.6.3
PATCH 6/7 iscsi-target: Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 14:34:26 +0100
The variables "tmp1" and "tmp2" will eventually be set to appropriate pointers from a call of the strchr() function.
Thus let us omit the explicit initialisation at the beginning.
--- drivers/target/iscsi/iscsi_target_parameters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -1
@@ -920,7 +920,7 @@ static char *iscsi_check_valuelist_for_support(struct iscsi_param *param, char *value) { - char *tmp1 = NULL, *tmp2 = NULL; + char *tmp1, *tmp2;char *acceptor_values =NULL , *proposer_values =NULL ; acceptor_values = param->value;
Signature · 1 line
2.6.3
PATCH 7/7 iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:04:57 +0100
The variable "acceptor_values" and "proposer_values" were initialized by null pointers and immediately assigned values from input parameters by separate statements.
Let us express the desired variable initialisations directly.
--- drivers/target/iscsi/iscsi_target_parameters.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -4
@@ -921,10 +921,7 @@ static char *iscsi_check_valuelist_for_support( char *value) {char *tmp1, *tmp2; -char *acceptor_values =NULL , *proposer_values =NULL ; - - acceptor_values = param->value; - proposer_values = value; +char *acceptor_values = param->value, *proposer_values = value; do { if (!proposer_values)
Signature · 1 line
2.6.3
Re: [PATCH 7/7] iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()
Am 12.12.2015 15:45, schrieb SF Markus Elfring:
Quoted 18 lines
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:04:57 +0100The variable "
acceptor_values" and "proposer_values" were initialized by null pointers and immediately assigned values from input parameters by separate statements.
Let us express the desired variable initialisations directly.Signed-off-by Markus Elfring <[email protected]>--- drivers/target/iscsi/iscsi_target_parameters.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c static char *iscsi_check_valuelist_for_support( · line 925
Quoted 9 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-4@@ -921,10 +921,7 @@ static char *iscsi_check_valuelist_for_support( char *value) {char *tmp1, *tmp2; -char *acceptor_values =NULL , *proposer_values =NULL ; - - acceptor_values = param->value; - proposer_values = value; +char *acceptor_values = param->value, *proposer_values = value;
I do not thing that this is a good idea,
i find the first version more readable
but you are right the NULL can be removed.
just my 2 cents,
re,
wh
Quoted 2 lines
drivers/target/iscsi/iscsi_target_parameters.c +0
-0do { if (!proposer_values)
cover staging-Lustre: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 14:40:14 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (7):
Delete unnecessary goto statements in six functions
Rename a jump label for ptlrpc_req_finished() calls
Rename a jump label for a kfree(key) call
Delete an unnecessary variable initialisation in mgc_process_recover_log() Less checks in mgc_process_recover_log() after error detection A few checks less in mgc_process_recover_log() after error detection Rename a jump label for module_put() calls
drivers/staging/lustre/lustre/llite/file.c | 26 ++--- drivers/staging/lustre/lustre/llite/lloop.c | 8 +- drivers/staging/lustre/lustre/llite/namei.c | 13 +-- drivers/staging/lustre/lustre/llite/xattr.c | 20 ++-- drivers/staging/lustre/lustre/mdc/mdc_request.c | 124 ++++++++++----------- drivers/staging/lustre/lustre/mgc/mgc_request.c | 53 ++++----- drivers/staging/lustre/lustre/osc/osc_request.c | 52 ++++----- drivers/staging/lustre/lustre/ptlrpc/llog_client.c | 22 ++-- 8 files changed, 152 insertions(+), 166 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/7 staging: lustre: Delete unnecessary goto statements in six functions
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100
Six goto statements referred to a source code position directly behind them. Thus omit such unnecessary jumps.
This issue was detected by using the Coccinelle software.
--- drivers/staging/lustre/lustre/llite/namei.c | 1 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ------- 2 files changed, 8 deletions(-)
drivers/staging/lustre/lustre/llite/namei.c +0 -1
@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, retval =NULL ; else retval = dentry; - goto out; out:if (req)ptlrpc_req_finished (req);
drivers/staging/lustre/lustre/mdc/mdc_request.c +0 -7
@@ -1181,7 +1181,6 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1216,7 +1215,6 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1282,7 +1280,6 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1362,8 +1359,6 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; - out:ptlrpc_req_finished (req);return rc;
@@ -1427,8 +1422,6 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; - out:ptlrpc_req_finished (req);return rc;
Signature · 1 line
2.6.3
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six goto statements referred to a source code position directly behind them. Thus omit such unnecessary jumps.
I suggest you leave a blank line instead
of deleting the goto.
drivers/staging/lustre/lustre/llite/namei.c
Quoted 1 line
drivers/staging/lustre/lustre/llite/namei.c +0
-0
[]
Quoted 8 lines
drivers/staging/lustre/lustre/llite/namei.c +0
-0@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, retval = NULL;else
retval = dentry;drivers/staging/lustre/lustre/llite/namei.c +0
-1- goto out;out:
if (req)
ptlrpc_req_finished(req);
etc.,,
--
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 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 10 lines · Joe Perches
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six goto statements referred to a source code position directly behind them. Thus omit such unnecessary jumps.
I suggest you leave a blank line instead
of deleting the goto.
What is the point of the little bunny hop?
regards,
dan carpenter
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 8 lines · Dan Carpenter
Quoted 7 lines · Joe Perches
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six goto statements referred to a source code position directly behind them. Thus omit such unnecessary jumps.
Quoted 9 lines
Quoted 3 lines
I suggest you leave a blank line instead
of deleting the goto.What is the point of the little bunny hop?
regards,
dan carpenter
-ENOPARSE little bunny hop
(though I could have said "just leave a blank line)
I think that code blocks are more obvious to read.
This is the original code:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); if (result) goto label;
label:
go on...
He proposes:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); label: go on...
I don't find the test->goto label; label: use offensive, but if he does, I think keeping a blank line in place of the test->goto might be better.
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz();
label:
go on...
Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 14 lines · Joe Perches
This is the original code:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); if (result) goto label;
Quoted 3 lines
label:
go on...
No. There is no test. The original code looks like:
result = foo(); if (result) goto out; result = baz(); goto out; out: go on..
regards,
dan carpenter
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 29 lines · Dan Carpenter
Quoted 14 lines · Joe Perches
This is the original code:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); if (result) goto label;Quoted 3 lines
label:
go on...No. There is no test. The original code looks like:
result = foo(); if (result) goto out; result = baz(); goto out; out: go on..
Quoted 2 lines
regards,
dan carpenter
Here is the original code:
---------------------
/* Copy hsm_progress struct */
req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
if (req_hpk = NULL) {
rc = -EPROTO;
goto out;
}
*req_hpk = *hpk;
req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval);
ptlrpc_request_set_replen(req);
rc = mdc_queue_wait(req);
goto out;
out:
ptlrpc_req_finished(req);
return rc;
}---------------------
I think if the last goto out; is to be removed,
then it should be replaced by a blank line.
It separates the last operation block from the return.
cheers, Joe
--
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: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 7 lines
rc = mdc_queue_wait(req); goto out; out: ptlrpc_req_finished(req); return rc; }
Quoted 6 lines
---------------------
I think if the last goto out; is to be removed,
then it should be replaced by a blank line.It separates the last operation block from the return.
Would you like to point a very specific coding style issue out? How often should jump labels preceded with blank lines?
Regards,
Markus
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 8 lines · SF Markus Elfring
Quoted 8 lines
rc = mdc_queue_wait(req); goto out; out: ptlrpc_req_finished(req); return rc; }---------------------
Quoted 6 lines
Quoted 4 lines
I think if the last goto out; is to be removed,
then it should be replaced by a blank line.It separates the last operation block from the return.
Would you like to point a very specific coding style issue out?
Other than using vertical separation can help readability?
I think there should _not_ be a hardened rule. Style is just a guide. Do what you think appropriate.
Quoted 1 line
How often should jump labels preceded with blank lines?
When other nearby blocks are also separated by blank lines.
Localized consistency can be useful.
Inconsistency can make code harder to follow/predict.
--
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: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 1 line
I think there should _not_ be a hardened rule.
I guess that it can become hard to achieve consensus on a precise rule.
Quoted 1 line
Style is just a guide.
Generally nice …
Quoted 1 line
Do what you think appropriate.
I'm sorry for my evolving understanding. - But I imagine that your feedback can cause further software development troubles if the acceptance for this update suggestion will really depend on the number of blank lines before a jump label.
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
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 2 lines · SF Markus Elfring
Quoted 1 line
I think there should _not_ be a hardened rule.
I guess that it can become hard to achieve consensus on a precise rule.
Consensus isn't unanimity.
Quoted 4 lines
I imagine that your feedback
can cause further software development troubles if the acceptance for this update suggestion will really depend on the number of blank lines before a jump label.
<shrug>
The author of any particular bit of code can do
whatever they want.
Localized consistency is probably more valuable than global consistency.
Re: staging: lustre: Delete unnecessary goto statements in six functions
In reply to Joe PerchesQuoted 1 line
This is the original code:
Really …?
Quoted 6 lines
result = baz(); if (result) goto label;label:
go on...
I do not see such a source code structure
at the six places I propose to clean-up.
Quoted 3 lines
I don't find the
test->gotolabel; label: use offensive, but if he does, I think keeping a blank line in place of thetest->gotomight be better.
I find this an interesting view on source code layout. Are there any more opinions around such implementation details?
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
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 13 lines · SF Markus Elfring
Quoted 1 line
This is the original code:
Really …?
Quoted 6 lines
result = baz(); if (result) goto label;label:
go on...I do not see such a source code structure
at the six places I propose to clean-up.
Quoted 6 lines
Quoted 3 lines
I don't find the
test->gotolabel; label: use offensive, but if he does, I think keeping a blank line in place of thetest->gotomight be better.I find this an interesting view on source code layout. Are there any more opinions around such implementation details?
Or to put it another way, use a blank line before the first or only label in an error/out block.
I don't find it different then commonly written blocks like:
void foo(void)
{
...;
wind1();
val = func1(...);
if (val) {
printk(...);
goto err_type;
}
wind2();
val = func2(...);
if (val) {
printk(...);
goto err_type2;
}
...
return 0;err_type2:
unwind2(); err_type: unwind1(); return -ERR; }
Yes, you can elide all the blank lines, but using them can
help readability.
--
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 2/7 staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 10:33:38 +0100
This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention. I suggest to improve this implementation detail by the reuse of a script like the following for the semantic patch language.
@rename_jump_label exists@
identifier work;
type return_type;
@@
return_type work(...)
{
... when any
goto
-out
+finish_request
;
... when any
-out
+finish_request
:
ptlrpc_req_finished(...);
... when any
}
--- drivers/staging/lustre/lustre/llite/file.c | 26 +++++------ drivers/staging/lustre/lustre/llite/namei.c | 12 ++--- drivers/staging/lustre/lustre/llite/xattr.c | 20 ++++---- drivers/staging/lustre/lustre/mdc/mdc_request.c | 54 +++++++++++----------- drivers/staging/lustre/lustre/osc/osc_request.c | 28 +++++------ drivers/staging/lustre/lustre/ptlrpc/llog_client.c | 22 ++++----- 6 files changed, 81 insertions(+), 81 deletions(-)
drivers/staging/lustre/lustre/llite/file.c +13 -13
@@ -427,27 +427,27 @@ static int ll_intent_file_open(struct dentry *dentry, void *lmm,*/ if (!it_disposition (itp,DISP_OPEN_OPEN ) ||it_open_error (DISP_OPEN_OPEN , itp)) - goto out; + goto finish_request;ll_release_openhandle (inode, itp); - goto out; + goto finish_request; }if (it_disposition (itp,DISP_LOOKUP_NEG )) { rc = -ENOENT ; - goto out; + goto finish_request; }if (rc !=0 ||it_open_error (DISP_OPEN_OPEN , itp)) { rc = rc ? rc :it_open_error (DISP_OPEN_OPEN , itp);CDEBUG (D_VFSTRACE ,"lock enqueue: err: %d\n" , rc); - goto out; + goto finish_request; } rc =ll_prep_inode (&inode, req,NULL , itp);if (!rc && itp->d.lustre.it_lock_mode)ll_set_lock_data (sbi->ll_md_exp, inode, itp,NULL ); -out: +finish_request:ptlrpc_req_finished (req);ll_intent_drop_lock (itp);
@@ -2900,13 +2900,13 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits) oit.it_create_mode &= ~M_CHECK_STALE ;if (rc <0 ) { rc =ll_inode_revalidate_fini (inode, rc); - goto out; + goto finish_request; } rc =ll_revalidate_it_finish (req, &oit, inode);if (rc !=0 ) {ll_intent_release (&oit); - goto out; + goto finish_request; }/* Unlinked? Unhash dentry, so it is not picked up later by
@@ -2946,7 +2946,7 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits) rc =ll_prep_inode (&inode, req,NULL ,NULL ); } -out: +finish_request:ptlrpc_req_finished (req);return rc; }
@@ -3315,25 +3315,25 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) body =req_capsule_server_get (&req->rq_pill, &RMF_MDT_BODY );if (body =NULL ) { rc = -EPROTO ; - goto out; + goto finish_request; } lmmsize = body->eadatasize;if (lmmsize =0 )/* empty layout */ { rc =0 ; - goto out; + goto finish_request; } lmm =req_capsule_server_sized_get (&req->rq_pill, &RMF_EADATA , lmmsize);if (lmm =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; } lvbdata =libcfs_kvzalloc (lmmsize,GFP_NOFS );if (lvbdata =NULL ) { rc = -ENOMEM ; - goto out; + goto finish_request; }memcpy (lvbdata, lmm, lmmsize);
@@ -3345,7 +3345,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) lock->l_lvb_len = lmmsize;unlock_res_and_lock (lock); -out: +finish_request:ptlrpc_req_finished (req);return rc; }
drivers/staging/lustre/lustre/llite/namei.c +6 -6
@@ -686,7 +686,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it) rc =ll_prep_inode (&inode, request, dir->i_sb, it);if (rc) { inode =ERR_PTR (rc); - goto out; + goto finish_request; }LASSERT (hlist_empty (&inode->i_dentry));
@@ -697,7 +697,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)CDEBUG (D_DLMTRACE ,"setting l_ast_data to inode %p (%lu/%u)\n" , inode, inode->i_ino, inode->i_generation);ll_set_lock_data (sbi->ll_md_exp, inode, it,NULL ); - out: + finish_request:ptlrpc_req_finished (request);return inode; }
@@ -960,13 +960,13 @@ static int ll_unlink(struct inode *dir, struct dentry *dentry) rc =md_unlink (ll_i2sbi (dir)->ll_md_exp, op_data, &request);ll_finish_md_op_data (op_data);if (rc) - goto out; + goto finish_request;ll_update_times (request, dir);ll_stats_ops_tally (ll_i2sbi (dir),LPROC_LL_UNLINK ,1 ); rc =ll_objects_destroy (request, dir); - out: + finish_request:ptlrpc_req_finished (request);return rc; }
@@ -1059,11 +1059,11 @@ static int ll_link(struct dentry *old_dentry, struct inode *dir, err =md_link (sbi->ll_md_exp, op_data, &request);ll_finish_md_op_data (op_data);if (err) - goto out; + goto finish_request;ll_update_times (request, dir);ll_stats_ops_tally (sbi,LPROC_LL_LINK ,1 ); -out: +finish_request:ptlrpc_req_finished (request);return err; }
drivers/staging/lustre/lustre/llite/xattr.c +10 -10
@@ -390,19 +390,19 @@ getxattr_nocache:/* only detect the xattr size */ if (size =0 ) { rc = body->eadatasize; - goto out; + goto finish_request; }if (size < body->eadatasize) {CERROR ("server bug: replied size %u > %u\n" , body->eadatasize, (int )size); rc = -ERANGE ; - goto out; + goto finish_request; }if (body->eadatasize =0 ) { rc = -ENODATA ; - goto out; + goto finish_request; }/* do not need swab xattr data */
@@ -410,7 +410,7 @@ getxattr_nocache: body->eadatasize);if (!xdata) { rc = -EFAULT ; - goto out; + goto finish_request; }memcpy (buffer, xdata, body->eadatasize);
@@ -425,14 +425,14 @@ getxattr_nocache: (posix_acl_xattr_header *)buffer, rc);if (IS_ERR (acl)) { rc =PTR_ERR (acl); - goto out; + goto finish_request; } rc =ee_add (&sbi->ll_et,current_pid (),ll_inode2fid (inode), xattr_type, acl);if (unlikely (rc <0 )) {lustre_ext_acl_xattr_free (acl); - goto out; + goto finish_request; } }#endif
@@ -444,7 +444,7 @@ out_xattr: ll_get_fsname(inode->i_sb, NULL, 0), rc); sbi->ll_flags &= ~LL_SBI_USER_XATTR ; } -out: +finish_request:ptlrpc_req_finished (req);return rc; }
@@ -555,7 +555,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) rc =ll_getxattr_common (inode,NULL , buffer, size,OBD_MD_FLXATTRLS );if (rc <0 ) - goto out; + goto finish_request;if (buffer !=NULL ) {struct ll_sb_info *sbi =ll_i2sbi (inode);
@@ -589,7 +589,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)if (rc2 <0 ) { rc2 =0 ; - goto out; + goto finish_request; }else if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)) {const int prefix_len =sizeof (XATTR_LUSTRE_PREFIX ) -1 ;const size_t name_len =sizeof ("lov" ) -1 ;
@@ -608,7 +608,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size) } rc2 = total_len; } -out: +finish_request:ptlrpc_req_finished (request); rc = rc + rc2;
drivers/staging/lustre/lustre/mdc/mdc_request.c +27 -27
203 lines not on this page · raw message
drivers/staging/lustre/lustre/osc/osc_request.c +14 -14
@@ -291,12 +291,12 @@ static int osc_getattr(const struct lu_env *env, struct obd_export *exp, rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; body =req_capsule_server_get (&req->rq_pill, &RMF_OST_BODY );if (body =NULL ) { rc = -EPROTO ; - goto out; + goto finish_request; }CDEBUG (D_INODE ,"mode: %o\n" , body->oa.o_mode);
@@ -306,7 +306,7 @@ static int osc_getattr(const struct lu_env *env, struct obd_export *exp, oinfo->oi_oa->o_blksize =cli_brw_size (exp->exp_obd); oinfo->oi_oa->o_valid |=OBD_MD_FLBLKSZ ; - out: + finish_request:ptlrpc_req_finished (req);return rc; }
@@ -336,18 +336,18 @@ static int osc_setattr(const struct lu_env *env, struct obd_export *exp, rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; body =req_capsule_server_get (&req->rq_pill, &RMF_OST_BODY );if (body =NULL ) { rc = -EPROTO ; - goto out; + goto finish_request; }lustre_get_wire_obdo (&req->rq_import->imp_connect_data, oinfo->oi_oa, &body->oa); -out: +finish_request:ptlrpc_req_finished (req);return rc; }
@@ -1276,7 +1276,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,if (desc =NULL ) { rc = -ENOMEM ; - goto out; + goto finish_request; }/* NB request now owns desc and will free it when it gets freed */
@@ -1407,7 +1407,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli, *reqp = req;return 0 ; - out: + finish_request:ptlrpc_req_finished (req);return rc; }
@@ -2513,17 +2513,17 @@ static int osc_statfs(const struct lu_env *env, struct obd_export *exp, rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; msfs =req_capsule_server_get (&req->rq_pill, &RMF_OBD_STATFS );if (msfs =NULL ) { rc = -EPROTO ; - goto out; + goto finish_request; } *osfs = *msfs; - out: + finish_request:ptlrpc_req_finished (req);return rc; }
@@ -2718,16 +2718,16 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp,ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; reply =req_capsule_server_get (&req->rq_pill, &RMF_OBD_ID );if (reply =NULL ) { rc = -EPROTO ; - goto out; + goto finish_request; } *((u64 *)val) = *reply; - out: + finish_request:ptlrpc_req_finished (req);return rc; }else if (KEY_IS (KEY_FIEMAP )) {
drivers/staging/lustre/lustre/ptlrpc/llog_client.c +11 -11
@@ -176,26 +176,26 @@ static int llog_client_next_block(const struct lu_env *env,ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; body =req_capsule_server_get (&req->rq_pill, &RMF_LLOGD_BODY );if (body =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; }/* The log records are swabbed as they are processed */ ptr =req_capsule_server_get (&req->rq_pill, &RMF_EADATA );if (ptr =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; } *cur_idx = body->lgd_saved_index; *cur_offset = body->lgd_cur_offset;memcpy (buf, ptr, len); -out: +finish_request:ptlrpc_req_finished (req); err_exit:LLOG_CLIENT_EXIT (loghandle->lgh_ctxt, imp);
@@ -233,22 +233,22 @@ static int llog_client_prev_block(const struct lu_env *env, rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; body =req_capsule_server_get (&req->rq_pill, &RMF_LLOGD_BODY );if (body =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; } ptr =req_capsule_server_get (&req->rq_pill, &RMF_EADATA );if (ptr =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; }memcpy (buf, ptr, len); -out: +finish_request:ptlrpc_req_finished (req); err_exit:LLOG_CLIENT_EXIT (loghandle->lgh_ctxt, imp);
@@ -282,12 +282,12 @@ static int llog_client_read_header(const struct lu_env *env,ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; hdr =req_capsule_server_get (&req->rq_pill, &RMF_LLOG_LOG_HDR );if (hdr =NULL ) { rc = -EFAULT ; - goto out; + goto finish_request; }memcpy (handle->lgh_hdr, hdr,sizeof (*hdr));
@@ -305,7 +305,7 @@ static int llog_client_read_header(const struct lu_env *env,CERROR ("you may need to re-run lconf --write_conf.\n" ); rc = -EIO ; } -out: +finish_request:ptlrpc_req_finished (req); err_exit:LLOG_CLIENT_EXIT (handle->lgh_ctxt, imp);
Signature · 1 line
2.6.3
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
Markus, please stop sending these things to rename out labels unless there is a bug. CodingStyle allows out labels.
regards,
dan carpenter
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
Quoted 2 lines
Markus, please stop sending these things to rename out labels unless there is a bug. CodingStyle allows out labels.
How does this feedback fit to information like the following?
"…
Chapter 7: …
…
Choose label names which say what the goto does or why the goto exists. … Avoid using GW-BASIC names …
…"
Regards,
Markus
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
Quoted 9 lines · SF Markus Elfring
Quoted 2 lines
Markus, please stop sending these things to rename out labels unless there is a bug. CodingStyle allows out labels.
How does this feedback fit to information like the following?
"…
Chapter 7: …
…
Choose label names which say what the goto does or why the goto exists.
A lot of people think "out" says what the goto does and why it exists. I personally don't agree with them but if you look at when I complain about it, it's almost always when it causes a bug.
Quoted 1 line
… Avoid using GW-BASIC names …
Those when people just use numbers for their label names instead of words like out1, out2, out4, out5. It's a different thing.
regards,
dan carpenter
Re: staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines
Markus, please stop sending these things to rename out labels unless there is a bug. CodingStyle allows out labels.
How does this feedback fit to information like the following?
"…
Chapter 7: …
…
Choose label names which say what the goto does or why the goto exists.A lot of people think "out" says what the goto does and why it exists.
I have got the impression that this short identifier is only partly appropriate.
Quoted 1 line
I personally don't agree with them
I guess that my opinion goes into a similar direction here.
Quoted 2 lines
but if you look at when I complain about it, it's almost always when it causes a bug.
I agree that the combination with bug fixing is more appealing than an attempt to improve coding style applications.
Quoted 4 lines
Quoted 1 line
… Avoid using GW-BASIC names …
Those when people just use numbers for their label names instead of words like out1, out2, out4, out5. It's a different thing.
The difference is not so clear for me as it appears to you. How many software developers can still remember habits around the selection of such identifiers from GW-BASIC times?
Regards,
Markus
PATCH 3/7 staging: lustre: Rename a jump label for a kfree(key) call
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 10:56:35 +0100
This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention.
--- drivers/staging/lustre/lustre/mdc/mdc_request.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/mdc/mdc_request.c +5 -6
@@ -1125,7 +1125,7 @@ static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)if (!fid_is_sane (&gf->gf_fid)) { rc = -EINVAL ; - goto out; + goto free_key; }/* Val is struct getinfo_fid2path result plus path */
@@ -1133,20 +1133,19 @@ static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf) rc =obd_get_info (NULL , exp, keylen, key, &vallen, gf,NULL );if (rc !=0 && rc != -EREMOTE ) - goto out; + goto free_key;if (vallen <=sizeof (*gf)) { rc = -EPROTO ; - goto out; + goto free_key; }else if (vallen >sizeof (*gf) + gf->gf_pathlen) { rc = -EOVERFLOW ; - goto out; + goto free_key; }CDEBUG (D_IOCTL ,"path get " DFID " from %llu #%d\n%s\n" ,PFID (&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path); - -out: +free_key:kfree (key);return rc; }
Signature · 1 line
2.6.3
PATCH 4/7 staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:00:32 +0100
The variable "mne_swab" will eventually be set to an appropriate value from a call of the ptlrpc_rep_need_swab() function.
Thus let us omit the explicit initialisation at the beginning.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -1293,7 +1293,7 @@ static int mgc_process_recover_log(struct obd_device *obd,struct page **pages;int nrpages;bool eof = true; -bool mne_swab = false; +bool mne_swab;int i;int ealen;int rc;
Signature · 1 line
2.6.3
PATCH 5/7 staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:21:17 +0100
A few checks would be performed by the mgc_process_recover_log() function even if it is known already that the passed variable "pages" contained a null pointer.
* Let us return directly if a call of the kcalloc() function failed.
* Move assignments for the variables "eof" and "req" behind this memory allocation.
* Delete a sanity check then.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +12 -13
@@ -1285,14 +1285,14 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,static int mgc_process_recover_log (struct obd_device *obd,struct config_llog_data *cld) { -struct ptlrpc_request *req =NULL ; +struct ptlrpc_request *req;struct config_llog_instance *cfg = &cld->cld_cfg;struct mgs_config_body *body;struct mgs_config_res *res;struct ptlrpc_bulk_desc *desc;struct page **pages;int nrpages; -bool eof = true; +bool eof;bool mne_swab;int i;int ealen;
@@ -1309,10 +1309,11 @@ static int mgc_process_recover_log(struct obd_device *obd, nrpages =CONFIG_READ_NRPAGES_INIT ; pages =kcalloc (nrpages,sizeof (*pages),GFP_KERNEL ); -if (pages =NULL ) { - rc = -ENOMEM ; - goto out; - } +if (!pages) +return -ENOMEM ; + + req =NULL ; + eof = true;for (i =0 ; i < nrpages; i++) { pages[i] =alloc_page (GFP_KERNEL );
@@ -1432,14 +1433,12 @@ out:if (rc =0 && !eof) goto again; -if (pages) { -for (i =0 ; i < nrpages; i++) { -if (pages[i] =NULL ) -break ; -__free_page (pages[i]); - } -kfree (pages); +for (i =0 ; i < nrpages; i++) { +if (pages[i] =NULL ) +break ; +__free_page (pages[i]); } +kfree (pages);return rc; }
Signature · 1 line
2.6.3
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 11 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:21:17 +0100A few checks would be performed by the
mgc_process_recover_log()function even if it is known already that the passed variable "pages" contained a null pointer.* Let us return directly if a call of the
kcalloc()function failed.* Move assignments for the variables "eof" and "req" behind this memory allocation.
Why? Then in the next patch it moves again. It's like cup shuffle to read these patches sometimes.
regards,
dan carpenter
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 10 lines
Quoted 8 lines
A few checks would be performed by the
mgc_process_recover_log()function even if it is known already that the passed variable "pages" contained a null pointer.* Let us return directly if a call of the
kcalloc()function failed.* Move assignments for the variables "eof" and "req" behind this memory allocation.
Why?
The positions of their initialisation depends on the selected exception handling implementation, doesn't it?
Can you accept the proposed changes around the affected memory allocations?
Quoted 1 line
Then in the next patch it moves again.
This detail is a matter of patch granularity.
Quoted 1 line
It's like cup shuffle to read these patches sometimes.
Do you prefer to stash any changes together for a bigger update step?
Regards,
Markus
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 9 lines · SF Markus Elfring
Quoted 9 lines
Quoted 8 lines
A few checks would be performed by the
mgc_process_recover_log()function even if it is known already that the passed variable "pages" contained a null pointer.* Let us return directly if a call of the
kcalloc()function failed.* Move assignments for the variables "eof" and "req" behind this memory allocation.
Quoted 7 lines
Quoted 1 line
Why?
The positions of their initialisation depends on the selected exception handling implementation, doesn't it?
Can you accept the proposed changes around the affected memory allocations?
Just leave it as-is if there is no reason.
Quoted 9 lines
Quoted 2 lines
Then in the next patch it moves again.
This detail is a matter of patch granularity.
Quoted 1 line
It's like cup shuffle to read these patches sometimes.
Do you prefer to stash any changes together for a bigger update step?
Yes. Patches 5 and 6 would be easier to review if they were folded into one patch.
regards,
dan carpenter
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 3 lines
Quoted 1 line
Can you accept the proposed changes around the affected memory allocations?
Just leave it as-is if there is no reason.
I suggest to make the implementation of the function "mgc_process_recover_log" a bit more efficient.
Quoted 4 lines
Quoted 1 line
Do you prefer to stash any changes together for a bigger update step?
Yes. Patches 5 and 6 would be easier to review if they were folded into one patch.
I do not like patch squashing for my update suggestions here.
Regards,
Markus
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line
Do you prefer to stash any changes together for a bigger update step?
Yes. Patches 5 and 6 would be easier to review if they were folded into one patch.
I do not like patch squashing for my update suggestions here.
I am a maintainer in drivers/staging. I am telling you what you need to do if you want us to apply your patch. What you do with that information is up to you.
regards,
dan carpenter
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 3 lines
Quoted 1 line
I do not like patch squashing for my update suggestions here.
I am a maintainer in
drivers/staging.
Thanks for this information.
Quoted 1 line
I am telling you what you need to do if you want us to apply your patch.
I am still waiting for a bit more constructive feedback for this patch series. How many days should I wait before I should send adjusted update suggestions for this approach?
Quoted 1 line
What you do with that information is up to you.
Our software development dialogue seems to trigger special challenges between us so far.
Are you generally willing to change the exception handling for the memory allocations in the function "mgc_process_recover_log" at all?
Regards,
Markus
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 2 lines · SF Markus Elfring
Our software development dialogue seems to trigger special challenges between us so far.
I try very hard to review patches mechanically and not be biased so that after a while people know if their patches will be merged or not without waiting for feedback.
In this case, I had asked you not to send patches renaming out labels and then the next day you sent me a string of patches renaming out labels. If you were a lustre dev then I would accept these renames definitely. But I believe that for anyone else, I would ask them what the point of doing these renames is. I do not think I have been unfair to you. There was no element of surprise.
Part of the reason we have CodingStyle is so that we can tell people "That's not in CodingStyle, that's just your own opinion so don't redo code just because you have a different opinion from the maintainer."
Quoted 3 lines
Are you generally willing to change the exception handling for the memory allocations in the function "
mgc_process_recover_log" at all?
I like the first patch in this series. I do not like the renames. I don't care too much about patches 5 and 6 except that they should be folded together and you should not move "req" and "eof" around.
Mostly I wish you would just focus on fixing bugs instead of these sorts of patches. It is a lot of work for me to explain how to redo patches but it is worth it for bugfixes.
regards,
dan carpenter
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 1 line
If you were a lustre dev then I would accept these renames definitely.
I find this information interesting.
Would any more contributors like to share their opinion?
Quoted 1 line
I do not think I have been unfair to you.
This view is correct in principle.
Quoted 1 line
There was no element of surprise.
I am trying to discuss further "special" update suggestions where the topic focus might evolve to new directions. I got the impression that you had some difficulties already with my previous proposals. So I am unsure about the general change acceptance from you alone.
You pointed out that you are maintainer for this software area. I was not so aware about this detail while I noticed that you are very active Linux software developer.
(You are not mentioned in the file "MAINTAINERS" for example.)
Quoted 3 lines
Part of the reason we have CodingStyle is so that we can tell people "That's not in CodingStyle, that's just your own opinion so don't redo code just because you have a different opinion from the maintainer."
I find this description reasonable.
But I see some challenges to improve the coding style specification. I would appreciate if some items can become less ambiguous and imprecise. I assume that a few recommendations from the script "checkpatch.pl" should also be mentioned there.
Quoted 5 lines
Quoted 4 lines
Are you generally willing to change the exception handling for the memory allocations in the function "
mgc_process_recover_log" at all?I like the first patch in this series.
Thanks for a bit of positive feedback.
Quoted 1 line
I do not like the renames.
I guess that this design aspect can be clarified a bit more.
Quoted 2 lines
I don't care too much about patches 5 and 6 except that they should be folded together and you should not move "req" and "eof" around.
I can understand this concern better than your first response for these update steps.
I might send an adjusted patch series a few days later.
Quoted 2 lines
Mostly I wish you would just focus on fixing bugs instead of these sorts of patches.
How often are deviations from the coding style also just ordinary bugs?
It seems that changes for this area are occasionally not so attractive in comparison to software improvements for components
which are more popular.
Regards,
Markus
PATCH 6/7 staging: lustre: A few checks less in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 13:03:58 +0100
A few checks would be performed by the mgc_process_recover_log() function even if it was determined that a call of the alloc_page() function failed.
* This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention.
* Move the assignment for the variable "eof" behind the memory allocation.
* Delete another sanity check then.
* The variable "req" will eventually be set to an appropriate pointer from a call of the ptlrpc_request_alloc() function.
Thus let us omit the explicit initialisation before.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 32 +++++++++++-------------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +14 -18
@@ -1312,17 +1312,15 @@ static int mgc_process_recover_log(struct obd_device *obd,if (!pages)return -ENOMEM ; - req =NULL ; - eof = true; -for (i =0 ; i < nrpages; i++) { pages[i] =alloc_page (GFP_KERNEL );if (pages[i] =NULL ) { rc = -ENOMEM ; - goto out; + goto free_pages; } } + eof = true; again:LASSERT (cld_is_recover (cld));LASSERT (mutex_is_locked (&cld->cld_lock));
@@ -1330,12 +1328,12 @@ again: &RQF_MGS_CONFIG_READ);if (req =NULL ) { rc = -ENOMEM ; - goto out; + goto free_pages; } rc =ptlrpc_request_pack (req,LUSTRE_MGS_VERSION ,MGS_CONFIG_READ );if (rc) - goto out; + goto finish_request;/* pack request */ body =req_capsule_client_get (&req->rq_pill, &RMF_MGS_CONFIG_BODY );
@@ -1344,7 +1342,7 @@ again:if (strlcpy (body->mcb_name, cld->cld_logname,sizeof (body->mcb_name)) >=sizeof (body->mcb_name)) { rc = -E2BIG ; - goto out; + goto finish_request; } body->mcb_offset = cfg->cfg_last_idx +1 ; body->mcb_type = cld->cld_type;
@@ -1356,7 +1354,7 @@ again: MGS_BULK_PORTAL);if (desc =NULL ) { rc = -ENOMEM ; - goto out; + goto finish_request; }for (i =0 ; i < nrpages; i++)
@@ -1365,12 +1363,12 @@ again:ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; res =req_capsule_server_get (&req->rq_pill, &RMF_MGS_CONFIG_RES );if (res->mcr_size < res->mcr_offset) { rc = -EINVAL ; - goto out; + goto finish_request; }/* always update the index even though it might have errors with
@@ -1384,18 +1382,18 @@ again: ealen =sptlrpc_cli_unwrap_bulk_read (req, req->rq_bulk,0 );if (ealen <0 ) { rc = ealen; - goto out; + goto finish_request; }if (ealen > nrpages <<PAGE_CACHE_SHIFT ) { rc = -EINVAL ; - goto out; + goto finish_request; }if (ealen =0 ) {/* no logs transferred */ if (!eof) rc = -EINVAL ; - goto out; + goto finish_request; } mne_swab = !!ptlrpc_rep_need_swab (req);
@@ -1425,14 +1423,12 @@ again: ealen -=PAGE_CACHE_SIZE ; } - -out: -if (req) -ptlrpc_req_finished (req); +finish_request: +ptlrpc_req_finished (req);if (rc =0 && !eof) goto again; - +free_pages:for (i =0 ; i < nrpages; i++) {if (pages[i] =NULL )break ;
Signature · 1 line
2.6.3
PATCH 7/7 staging: lustre: Rename a jump label for module_put() calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 14:05:57 +0100
This issue was detected by using the Coccinelle software.
Choose a jump label according to the current Linux coding style convention. I suggest to improve this implementation detail by the reuse of a script like the following for the semantic patch language.
@rename_jump_label exists@
identifier target != put_module, work;
type return_type;
@@
return_type work(...)
{
... when any
goto
-target
+put_module
;
... when any
-target
+put_module
:
module_put(...);
... when any
}
--- drivers/staging/lustre/lustre/llite/lloop.c | 8 ++-- drivers/staging/lustre/lustre/mdc/mdc_request.c | 52 ++++++++++++------------- drivers/staging/lustre/lustre/osc/osc_request.c | 24 ++++++------ 3 files changed, 42 insertions(+), 42 deletions(-)
drivers/staging/lustre/lustre/llite/lloop.c +4 -4
@@ -484,14 +484,14 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused, error = -EBUSY ;if (lo->lo_state !=LLOOP_UNBOUND ) - goto out; + goto put_module; mapping = file->f_mapping; inode = mapping->host; error = -EINVAL ;if (!S_ISREG (inode->i_mode) || inode->i_sb->s_magic !=LL_SUPER_MAGIC ) - goto out; + goto put_module;if (!(file->f_mode &FMODE_WRITE )) lo_flags |=LO_FLAGS_READ_ONLY ;
@@ -500,7 +500,7 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,if ((loff_t )(sector_t )size != size) { error = -EFBIG ; - goto out; + goto put_module; }/* remove all pages in cache so as dirty pages not to be existent. */
@@ -542,7 +542,7 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,down (&lo->lo_sem);return 0 ; -out: +put_module:/* This is safe: open() is still holding a reference. */ module_put (THIS_MODULE );return error;
drivers/staging/lustre/lustre/mdc/mdc_request.c +26 -26
144 lines not on this page · raw message
drivers/staging/lustre/lustre/osc/osc_request.c +12 -12
@@ -2611,7 +2611,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, len =0 ;if (obd_ioctl_getdata (&buf, &len, uarg)) { err = -EINVAL ; - goto out; + goto put_module; } data = (struct obd_ioctl_data *)buf;
@@ -2619,13 +2619,13 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,if (sizeof (*desc) > data->ioc_inllen1) {obd_ioctl_freedata (buf, len); err = -EINVAL ; - goto out; + goto put_module; }if (data->ioc_inllen2 <sizeof (uuid)) {obd_ioctl_freedata (buf, len); err = -EINVAL ; - goto out; + goto put_module; } desc = (struct lov_desc *)data->ioc_inlbuf1;
@@ -2643,39 +2643,39 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,if (err) err = -EFAULT ;obd_ioctl_freedata (buf, len); - goto out; + goto put_module; }case LL_IOC_LOV_SETSTRIPE : err =obd_alloc_memmd (exp, karg);if (err >0 ) err =0 ; - goto out; + goto put_module;case LL_IOC_LOV_GETSTRIPE : err =osc_getstripe (karg, uarg); - goto out; + goto put_module;case OBD_IOC_CLIENT_RECOVER : err =ptlrpc_recover_import (obd->u.cli.cl_import, data->ioc_inlbuf1,0 );if (err >0 ) err =0 ; - goto out; + goto put_module;case IOC_OSC_SET_ACTIVE : err =ptlrpc_set_import_active (obd->u.cli.cl_import, data->ioc_offset); - goto out; + goto put_module;case OBD_IOC_POLL_QUOTACHECK : err =osc_quota_poll_check (exp, karg); - goto out; + goto put_module;case OBD_IOC_PING_TARGET : err =ptlrpc_obd_ping (obd); - goto out; + goto put_module;default :CDEBUG (D_INODE ,"unrecognised ioctl %#x by %s\n" , cmd,current_comm ()); err = -ENOTTY ; - goto out; + goto put_module; } -out: +put_module:module_put (THIS_MODULE );return err; }
Signature · 1 line
2.6.3
v2 cover staging-Lustre: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 20:00:02 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (4):
Delete unnecessary goto statements in six functions
Delete an unnecessary variable initialisation in mgc_process_recover_log() Less checks in mgc_process_recover_log() after error detection Fix a jump label position in osc_get_info()
drivers/staging/lustre/lustre/llite/namei.c | 1 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ---- drivers/staging/lustre/lustre/mgc/mgc_request.c | 53 +++++++++++-------------- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 4 files changed, 25 insertions(+), 38 deletions(-)
Signature · 1 line
2.6.3
PATCH v2 1/4 staging: lustre: Delete unnecessary goto statements in six functions
From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:15:45 +0100
Six goto statements referred to a source code position directly behind them.
Thus omit such unnecessary jumps.
This issue was detected by using the Coccinelle software.
--- drivers/staging/lustre/lustre/llite/namei.c | 1 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ------- 2 files changed, 8 deletions(-)
drivers/staging/lustre/lustre/llite/namei.c +0 -1
@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, retval =NULL ; else retval = dentry; - goto out; out:if (req)ptlrpc_req_finished (req);
drivers/staging/lustre/lustre/mdc/mdc_request.c +0 -7
@@ -1181,7 +1181,6 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1216,7 +1215,6 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1282,7 +1280,6 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; out:ptlrpc_req_finished (req);return rc;
@@ -1362,8 +1359,6 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; - out:ptlrpc_req_finished (req);return rc;
@@ -1427,8 +1422,6 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,ptlrpc_request_set_replen (req); rc =mdc_queue_wait (req); - goto out; - out:ptlrpc_req_finished (req);return rc;
Signature · 1 line
2.6.3
PATCH v2 2/4 staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:24:45 +0100
The variable "mne_swab" will eventually be set to an appropriate value from a call of the ptlrpc_rep_need_swab() function.
Thus let us omit the explicit initialisation at the beginning.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -1293,7 +1293,7 @@ static int mgc_process_recover_log(struct obd_device *obd,struct page **pages;int nrpages;bool eof = true; -bool mne_swab = false; +bool mne_swab;int i;int ealen;int rc;
Signature · 1 line
2.6.3
PATCH v2 3/4 staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100
A few checks would be performed by the mgc_process_recover_log() function even though it was determined that the passed variable "pages" contained a null pointer or a call of the alloc_page() function failed.
1. Let us return directly if a call of the kcalloc() function failed.
2. Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
3. Delete sanity checks then.
4. Move an assignment for the variable "eof" behind memory allocations.
5. The variable "req" will eventually be set to an appropriate pointer from a call of the ptlrpc_request_alloc() function.
Thus let us omit the explicit initialisation before.
6. Apply a recommendation from the script "checkpatch.pl".
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 51 +++++++++++-------------- 1 file changed, 23 insertions(+), 28 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +23 -28
@@ -1285,14 +1285,14 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,static int mgc_process_recover_log (struct obd_device *obd,struct config_llog_data *cld) { -struct ptlrpc_request *req =NULL ; +struct ptlrpc_request *req;struct config_llog_instance *cfg = &cld->cld_cfg;struct mgs_config_body *body;struct mgs_config_res *res;struct ptlrpc_bulk_desc *desc;struct page **pages;int nrpages; -bool eof = true; +bool eof;bool mne_swab;int i;int ealen;
@@ -1309,19 +1309,18 @@ static int mgc_process_recover_log(struct obd_device *obd, nrpages =CONFIG_READ_NRPAGES_INIT ; pages =kcalloc (nrpages,sizeof (*pages),GFP_KERNEL ); -if (pages =NULL ) { - rc = -ENOMEM ; - goto out; - } +if (!pages) +return -ENOMEM ;for (i =0 ; i < nrpages; i++) { pages[i] =alloc_page (GFP_KERNEL );if (pages[i] =NULL ) { rc = -ENOMEM ; - goto out; + goto free_pages; } } + eof = true; again:LASSERT (cld_is_recover (cld));LASSERT (mutex_is_locked (&cld->cld_lock));
@@ -1329,12 +1328,12 @@ again: &RQF_MGS_CONFIG_READ);if (req =NULL ) { rc = -ENOMEM ; - goto out; + goto free_pages; } rc =ptlrpc_request_pack (req,LUSTRE_MGS_VERSION ,MGS_CONFIG_READ );if (rc) - goto out; + goto finish_request;/* pack request */ body =req_capsule_client_get (&req->rq_pill, &RMF_MGS_CONFIG_BODY );
@@ -1343,7 +1342,7 @@ again:if (strlcpy (body->mcb_name, cld->cld_logname,sizeof (body->mcb_name)) >=sizeof (body->mcb_name)) { rc = -E2BIG ; - goto out; + goto finish_request; } body->mcb_offset = cfg->cfg_last_idx +1 ; body->mcb_type = cld->cld_type;
@@ -1355,7 +1354,7 @@ again: MGS_BULK_PORTAL);if (desc =NULL ) { rc = -ENOMEM ; - goto out; + goto finish_request; }for (i =0 ; i < nrpages; i++)
@@ -1364,12 +1363,12 @@ again:ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; res =req_capsule_server_get (&req->rq_pill, &RMF_MGS_CONFIG_RES );if (res->mcr_size < res->mcr_offset) { rc = -EINVAL ; - goto out; + goto finish_request; }/* always update the index even though it might have errors with
@@ -1383,18 +1382,18 @@ again: ealen =sptlrpc_cli_unwrap_bulk_read (req, req->rq_bulk,0 );if (ealen <0 ) { rc = ealen; - goto out; + goto finish_request; }if (ealen > nrpages <<PAGE_CACHE_SHIFT ) { rc = -EINVAL ; - goto out; + goto finish_request; }if (ealen =0 ) {/* no logs transferred */ if (!eof) rc = -EINVAL ; - goto out; + goto finish_request; } mne_swab = !!ptlrpc_rep_need_swab (req);
@@ -1424,22 +1423,18 @@ again: ealen -=PAGE_CACHE_SIZE ; } - -out: -if (req) -ptlrpc_req_finished (req); +finish_request: +ptlrpc_req_finished (req);if (rc =0 && !eof) goto again; - -if (pages) { -for (i =0 ; i < nrpages; i++) { -if (pages[i] =NULL ) -break ; -__free_page (pages[i]); - } -kfree (pages); +free_pages: +for (i =0 ; i < nrpages; i++) { +if (!(pages[i])) +break ; +__free_page (pages[i]); } +kfree (pages);return rc; }
Signature · 1 line
2.6.3
Greg Kroah-Hartman
maintainerRe: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 14 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100A few checks would be performed by the
mgc_process_recover_log()function even though it was determined that the passed variable "pages" contained a null pointer or a call of thealloc_page()function failed.1. Let us return directly if a call of the
kcalloc()function failed.2. Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
3. Delete sanity checks then.
Quoted 7 lines
4. Move an assignment for the variable "eof" behind memory allocations.
5. The variable "req" will eventually be set to an appropriate pointer from a call of the
ptlrpc_request_alloc()function.
Thus let us omit the explicit initialisation before.6. Apply a recommendation from the script "checkpatch.pl".
That's 6 different things, shouldn't this be 6 different patches?
please redo.
thanks,
greg k-h
Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 5 lines
Quoted 1 line
6. Apply a recommendation from the script "checkpatch.pl".
That's 6 different things, shouldn't this be 6 different patches?
please redo.
Dan Carpenter requested to squash the previous update steps 5 and 6 into a single patch for better source code review.
Now I see further software development challenges to increase the patch granularity even more as you suggest.
Which route would Lustre developers like to follow?
Regards,
Markus
Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to Greg Kroah-HartmanQuoted 3 lines · Greg Kroah-Hartman
That's 6 different things, shouldn't this be 6 different patches?
Not really. The patch could be described as just "change from using one exit label to using several." Markus has sent a number of these patches and I am CC'd on them because of kernel-janitors, it's really painful to review when he breaks them up into tiny patches where he changes one label at a time. It's like trying to put coleslaw back together into a head of cabbage.
Quoted 8 lines · SF Markus Elfring
Quoted 7 lines
From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100A few checks would be performed by the
mgc_process_recover_log()function even though it was determined that the passed variable "pages" contained a null pointer or a call of thealloc_page()function failed.
Quoted 6 lines
Quoted 6 lines
1. Let us return directly if a call of the
kcalloc()function failed.2. Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
3. Delete sanity checks then.
These are not sanity checks, of course. They were required because of a common exit path.
Quoted 2 lines
Quoted 2 lines
4. Move an assignment for the variable "eof" behind memory allocations.
I had asked Markus not to do this. It is unrelated.
Quoted 4 lines
Quoted 4 lines
5. The variable "req" will eventually be set to an appropriate pointer from a call of the
ptlrpc_request_alloc()function.
Thus let us omit the explicit initialisation before.
Now that we use multiple labels it isn't necessary to initialize "req".
Quoted 2 lines
Quoted 2 lines
6. Apply a recommendation from the script "checkpatch.pl".
This is where he changed pages[i] = NULL to !(pages[i]). It's not strictly related but it's minor and he was changing those lines anyway.
regards,
dan carpenter
cover staging-Lustre: Fine-tuning for seven function implementations
In reply to Greg Kroah-HartmanFrom: Markus Elfring <[email protected]>
Further update suggestions were taken into account after a patch was applied from static source code analysis.
Markus Elfring (12):
ldlm: Delete unnecessary checks before the function call "kset_unregister" Delete unnecessary checks before the function call "kobject_put" One function call less in class_register_type() after error detection Split a condition check in class_register_type()
Optimize error handling in class_register_type()
Return directly after a failed kcalloc() in mgc_process_recover_log() Less checks after a failed alloc_page() in mgc_process_recover_log() Less checks after a failed ptlrpc_request_alloc() inmgc_process_recover_log() Delete a check for the variable "req" in mgc_process_recover_log() Rename jump labels in mgc_process_recover_log()
Move an assignment for the variable "eof" in mgc_process_recover_log() Delete an unnecessary variable initialisation in mgc_process_recover_log()
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 10 ++--- drivers/staging/lustre/lustre/lmv/lmv_obd.c | 5 +-- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 +- drivers/staging/lustre/lustre/mgc/mgc_request.c | 50 ++++++++++++------------- drivers/staging/lustre/lustre/obdclass/genops.c | 41 ++++++++++++-------- 5 files changed, 54 insertions(+), 56 deletions(-)
Signature · 1 line
2.9.2
PATCH 1/12 staging/lustre/ldlm: Delete unnecessary checks before the function call "kset_unregister"
From: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 11:33:43 +0200
The kset_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +2 -4
@@ -1067,10 +1067,8 @@ static int ldlm_cleanup(void)if (ldlm_state->ldlm_cb_service)ptlrpc_unregister_service (ldlm_state->ldlm_cb_service); -if (ldlm_ns_kset) -kset_unregister (ldlm_ns_kset); -if (ldlm_svc_kset) -kset_unregister (ldlm_svc_kset); +kset_unregister (ldlm_ns_kset); +kset_unregister (ldlm_svc_kset);if (ldlm_kobj)kobject_put (ldlm_kobj);
Signature · 1 line
2.9.2
PATCH 2/12 staging: lustre: Delete unnecessary checks before the function call "kobject_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 13:00:32 +0200
The kobject_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 4 +--- drivers/staging/lustre/lustre/lmv/lmv_obd.c | 5 ++--- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 +--- drivers/staging/lustre/lustre/obdclass/genops.c | 6 ++---- 4 files changed, 6 insertions(+), 13 deletions(-)
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +1 -3
@@ -1069,9 +1069,7 @@ static int ldlm_cleanup(void)kset_unregister (ldlm_ns_kset);kset_unregister (ldlm_svc_kset); -if (ldlm_kobj) -kobject_put (ldlm_kobj); - +kobject_put (ldlm_kobj);ldlm_debugfs_cleanup ();kfree (ldlm_state);
drivers/staging/lustre/lustre/lmv/lmv_obd.c +2 -3
@@ -238,7 +238,7 @@ static int lmv_connect(const struct lu_env *env,if (data && data->ocd_connect_flags &OBD_CONNECT_REAL ) rc =lmv_check_connect (obd); -if (rc && lmv->lmv_tgts_kobj) +if (rc)kobject_put (lmv->lmv_tgts_kobj);return rc;
@@ -648,8 +648,7 @@ static int lmv_disconnect(struct obd_export *exp)lmv_disconnect_mdc (obd, lmv->tgts[i]); } -if (lmv->lmv_tgts_kobj) -kobject_put (lmv->lmv_tgts_kobj); +kobject_put (lmv->lmv_tgts_kobj); out_local:/*
drivers/staging/lustre/lustre/lov/lov_obd.c +1 -3
@@ -106,9 +106,7 @@ static void lov_putref(struct obd_device *obd)__lov_del_obd (obd, tgt); } -if (lov->lov_tgts_kobj) -kobject_put (lov->lov_tgts_kobj); - +kobject_put (lov->lov_tgts_kobj); }else {mutex_unlock (&lov->lov_lock); }
drivers/staging/lustre/lustre/obdclass/genops.c +2 -4
@@ -203,8 +203,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,return 0 ; failed: -if (type->typ_kobj) -kobject_put (type->typ_kobj); +kobject_put (type->typ_kobj);kfree (type->typ_name);kfree (type->typ_md_ops);kfree (type->typ_dt_ops);
@@ -231,8 +230,7 @@ int class_unregister_type(const char *name)return -EBUSY ; } -if (type->typ_kobj) -kobject_put (type->typ_kobj); +kobject_put (type->typ_kobj);if (!IS_ERR_OR_NULL (type->typ_debugfs_entry))ldebugfs_remove (&type->typ_debugfs_entry);
Signature · 1 line
2.9.2
PATCH 3/12 staging: lustre: One function call less in class_register_type() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 13:40:47 +0200
The kobject_put() function was called in a few cases by the class_register_type() function during error handling even if the passed data structure element did not contain a pointer for a valid data item.
Adjust jump targets according to the Linux coding style convention.
--- drivers/staging/lustre/lustre/obdclass/genops.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/obdclass/genops.c +6 -6
@@ -164,7 +164,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,if (!type->typ_dt_ops || !type->typ_md_ops || !type->typ_name) - goto failed; + goto free_name; *(type->typ_dt_ops) = *dt_ops;/* md_ops is optional */
@@ -180,20 +180,20 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, rc = type->typ_debugfs_entry ?PTR_ERR (type->typ_debugfs_entry) : -ENOMEM ; type->typ_debugfs_entry =NULL ; - goto failed; + goto free_name; } type->typ_kobj =kobject_create_and_add (type->typ_name, lustre_kobj);if (!type->typ_kobj) { rc = -ENOMEM ; - goto failed; + goto free_name; }if (ldt) { type->typ_lu = ldt; rc =lu_device_type_init (ldt);if (rc !=0 ) - goto failed; + goto put_object; }spin_lock (&obd_types_lock);
@@ -201,9 +201,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,spin_unlock (&obd_types_lock);return 0 ; - - failed: +put_object:kobject_put (type->typ_kobj); +free_name:kfree (type->typ_name);kfree (type->typ_md_ops);kfree (type->typ_dt_ops);
Signature · 1 line
2.9.2
Re: [PATCH 03/12] staging: lustre: One function call less in class_register_type() after error detection
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 13:40:47 +0200The
kobject_put()function was called in a few cases by theclass_register_type()function during error handling even if the passed data structure element did not contain a pointer for a valid data item.
But kobject_put() already checks for NULL, right? you just submitted another batch about that in other area.
Quoted 1 line
Adjust jump targets according to the Linux coding style convention.
Not that I am totally against this patch, but when we do not need the extra checks, a single jump target is ok too in my mind (extra benefit - there's not going to be any chance of a mistake to where to jump to). And when we have a single jump target, there's no supersmart naming like free_this_and_that_and_that_other_thing_too.
Quoted 57 lines
Signed-off-by Markus Elfring <[email protected]>---
drivers/staging/lustre/lustre/obdclass/genops.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)drivers/staging/lustre/lustre/obdclass/genops.c +6
-6@@ -164,7 +164,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,if (!type->typ_dt_ops || !type->typ_md_ops || !type->typ_name) - goto failed; + goto free_name; *(type->typ_dt_ops) = *dt_ops;/* md_ops is optional */ @@ -180,20 +180,20 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, rc = type->typ_debugfs_entry ?PTR_ERR (type->typ_debugfs_entry) : -ENOMEM ; type->typ_debugfs_entry =NULL ; - goto failed; + goto free_name; } type->typ_kobj =kobject_create_and_add (type->typ_name, lustre_kobj);if (!type->typ_kobj) { rc = -ENOMEM ; - goto failed; + goto free_name; }if (ldt) { type->typ_lu = ldt; rc =lu_device_type_init (ldt);if (rc !=0 ) - goto failed; + goto put_object; }spin_lock (&obd_types_lock);@@ -201,9 +201,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,spin_unlock (&obd_types_lock);return 0 ; - - failed: +put_object:kobject_put (type->typ_kobj); +free_name:kfree (type->typ_name);kfree (type->typ_md_ops);kfree (type->typ_dt_ops);Signature · 1 line
2.9.2
Re: staging: lustre: One function call less in class_register_type() after error detection
Quoted 1 line
But
kobject_put()already checks for NULL, right?
Yes. - Such an input parameter validation is performed by the function implementation.
Quoted 1 line
you just submitted another batch about that in other area.
I sent update suggestions because of this function property for two Linux software modules in the year 2015.
Quoted 3 lines
Quoted 1 line
Adjust jump targets according to the Linux coding style convention.
Not that I am totally against this patch,
Thanks for your feedback.
Quoted 1 line
but when we do not need the extra checks, a single jump target is ok too in my mind
A single goto label will look convenient for a while. It will often work for several use cases.
Quoted 1 line
(extra benefit - there's not going to be any chance of a mistake to where to jump to).
I have got an other opinion when you would like to care for a bit more software efficiency.
Quoted 2 lines
And when we have a single jump target, there's no supersmart naming like
free_this_and_that_and_that_other_thing_too.
How often do you care for efficient exception handling in the shown function implementations?
Regards,
Markus
Re: staging: lustre: One function call less in class_register_type() after error detection
Quoted 31 lines · SF Markus Elfring
Quoted 1 line
But
kobject_put()already checks for NULL, right?Yes. - Such an input parameter validation is performed by the function implementation.
Quoted 1 line
you just submitted another batch about that in other area.
I sent update suggestions because of this function property for two Linux software modules in the year 2015.
Quoted 3 lines
Quoted 1 line
Adjust jump targets according to the Linux coding style convention.
Not that I am totally against this patch,
Thanks for your feedback.
Quoted 1 line
but when we do not need the extra checks, a single jump target is ok too in my mind
A single goto label will look convenient for a while. It will often work for several use cases.
Quoted 1 line
(extra benefit - there's not going to be any chance of a mistake to where to jump to).
I have got an other opinion when you would like to care for a bit more software efficiency.
Quoted 5 lines
Quoted 2 lines
And when we have a single jump target, there's no supersmart naming like
free_this_and_that_and_that_other_thing_too.How often do you care for efficient exception handling in the shown function implementations?
This function is called several times during lustre module insert. Namely it's called 5 times for 5 types:
osc, mdc, lov, lmv, mgc.
It's not called any more than that, so it's not exactly a super hot-path function to overoptimize it, and the failure is presumed to never happen too (or the module would be non-functional).
I guess you have already did all the work so I don't have any principal objections here, it's just like I said, in a non-super contended path, a single "fail" label is probably easier on the developer when they need to add another check there, as opposed to figuring and possibly adding a correct another label that would do something sensible.
Thank you for your contributions.
Re: staging: lustre: One function call less in class_register_type() after error detection
Quoted 3 lines
This function is called several times during lustre module insert. Namely it's called 5 times for 5 types:
osc, mdc, lov, lmv, mgc.
Will any extra memory accesses matter for the successful execution in this use case?
Quoted 3 lines
It's not called any more than that, so it's not exactly a super hot-path function to overoptimize it, and the failure is presumed to never happen too (or the module would be non-functional).
Did the assignment for the local variable "rc" with a well-known error code influence the run-time characteristics in unwanted ways?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/staging/lustre/lustre/obdclass/genops.c?idj5b99a46bedc2cfbba96dec6d255c4b90af9ff8#n140
Regards,
Markus
Re: [lustre-devel] staging: lustre: One function call less in class_register_type() after error detection
Quoted 6 lines · SF Markus Elfring
Quoted 3 lines
This function is called several times during lustre module insert. Namely it's called 5 times for 5 types:
osc, mdc, lov, lmv, mgc.Will any extra memory accesses matter for the successful execution in this use case?
I doubt it.
In typical deployments outside of testing environment, this function is called 5 times every system boot and never again.
Quoted 7 lines
Quoted 3 lines
It's not called any more than that, so it's not exactly a super hot-path function to overoptimize it, and the failure is presumed to never happen too (or the module would be non-functional).
Did the assignment for the local variable "rc" with a well-known error code influence the run-time characteristics in unwanted ways?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/staging/lustre/lustre/obdclass/genops.c?idj5b99a46bedc2cfbba96dec6d255c4b90af9ff8#n140
I am not sure what do you mean here.
Re: [lustre-devel] staging: lustre: One function call less in class_register_type() after error detection
Quoted 2 lines
In typical deployments outside of testing environment, this function is called 5 times every system boot and never again.
Does this information mean that a bit more fine-tuning is insignificant at such a source code place?
Quoted 5 lines
Quoted 3 lines
Did the assignment for the local variable "rc" with a well-known error code influence the run-time characteristics in unwanted ways?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/staging/lustre/lustre/obdclass/genops.c?idj5b99a46bedc2cfbba96dec6d255c4b90af9ff8#n140I am not sure what do you mean here.
I suggest to take another look at corresponding implementation details.
An error code is assigned to the variable "rc" before four memory allocations succeeded so far.
We hope that this function will usually return zero as a constant for the indication of a successful execution. I find that this variable should not be touched in the preferred case.
Will such an unnecessary assignment reduce the execution speed a bit for the desired file system initialisation?
Regards,
Markus
PATCH 4/12 staging: lustre: Split a condition check in class_register_type()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 14:10:55 +0200
The kfree() function was called in up to three cases by the class_register_type() function during error handling even if the passed data structure element contained a null pointer.
* Split a condition check for memory allocation failures.
* Improve this implementation detail by the introduction of a few jump labels.
--- drivers/staging/lustre/lustre/obdclass/genops.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/staging/lustre/lustre/obdclass/genops.c +17 -5
@@ -158,13 +158,22 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,return rc; type->typ_dt_ops =kzalloc (sizeof (*type->typ_dt_ops),GFP_NOFS ); +if (!type->typ_dt_ops) { + rc = -ENOMEM ; + goto free_type; + } + type->typ_md_ops =kzalloc (sizeof (*type->typ_md_ops),GFP_NOFS ); - type->typ_name =kzalloc (strlen (name) +1 ,GFP_NOFS ); +if (!type->typ_dt_ops) { + rc = -ENOMEM ; + goto free_dt_ops; + } -if (!type->typ_dt_ops || - !type->typ_md_ops || - !type->typ_name) - goto free_name; + type->typ_name =kzalloc (strlen (name) +1 ,GFP_NOFS ); +if (!type->typ_name) { + rc = -ENOMEM ; + goto free_md_ops; + } *(type->typ_dt_ops) = *dt_ops;/* md_ops is optional */
@@ -205,8 +214,11 @@ put_object:kobject_put (type->typ_kobj); free_name:kfree (type->typ_name); +free_md_ops:kfree (type->typ_md_ops); +free_dt_ops:kfree (type->typ_dt_ops); +free_type:kfree (type);return rc; }
Signature · 1 line
2.9.2
PATCH 5/12 staging: lustre: Optimize error handling in class_register_type()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 14:23:23 +0200
Return a constant error code without storing it in the local variable "rc" after a failed memory allocation at the beginning of this function.
--- drivers/staging/lustre/lustre/obdclass/genops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/lustre/lustre/obdclass/genops.c +1 -2
@@ -152,10 +152,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,return -EEXIST ; } - rc = -ENOMEM ; type =kzalloc (sizeof (*type),GFP_NOFS );if (!type) -return rc; +return -ENOMEM ; type->typ_dt_ops =kzalloc (sizeof (*type->typ_dt_ops),GFP_NOFS );if (!type->typ_dt_ops) {
Signature · 1 line
2.9.2
Oleg Drokin
NAKRe: [PATCH 05/12] staging: lustre: Optimize error handling in class_register_type()
Quoted 16 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 14:23:23 +0200Return a constant error code without storing it in the local variable "rc" after a failed memory allocation at the beginning of this function.
Signed-off-by Markus Elfring <[email protected]>---
drivers/staging/lustre/lustre/obdclass/genops.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/lustre/lustre/obdclass/genops.c +0
-0
drivers/staging/lustre/lustre/obdclass/genops.c int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, · line 155
Quoted 4 lines
drivers/staging/lustre/lustre/obdclass/genops.c +0
-1@@ -152,10 +152,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,return -EEXIST ; } - rc = -ENOMEM ;
NAK.
when you do this, the next statement below breaks:
Quoted 7 lines
drivers/staging/lustre/lustre/obdclass/genops.c +1
-1type =kzalloc (sizeof (*type),GFP_NOFS );if (!type) -return rc; +return -ENOMEM ; type->typ_dt_ops =kzalloc (sizeof (*type->typ_dt_ops),GFP_NOFS );if (!type->typ_dt_ops) {
…
goto failed;
failed:
…
return rc;
So we are now returning an unitialized rc, did you get a gcc warning about it when compiling?-- 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: [lustre-devel] [PATCH 05/12] staging: lustre: Optimize error handling in class_register_type()
Quoted 22 lines · Oleg Drokin
Quoted 19 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 14:23:23 +0200Return a constant error code without storing it in the local variable "rc" after a failed memory allocation at the beginning of this function.
Signed-off-by Markus Elfring <[email protected]>---
drivers/staging/lustre/lustre/obdclass/genops.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/lustre/lustre/obdclass/genops.c +0
-0@@ -152,10 +152,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,return -EEXIST ; }
Quoted 4 lines
drivers/staging/lustre/lustre/obdclass/genops.c int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, · line 155
Quoted 1 line
drivers/staging/lustre/lustre/obdclass/genops.c +0
-1- rc = -ENOMEM ;NAK.
when you do this, the next statement below breaks:
Ah, I see there was patch 4 before patch 5 that actually placed rc assignments everywhere.
So I guess it is fine after all.
Sorry for the noise.
Quoted 15 lines
Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/genops.c +1
-1type =kzalloc (sizeof (*type),GFP_NOFS );if (!type) -return rc; +return -ENOMEM ; type->typ_dt_ops =kzalloc (sizeof (*type->typ_dt_ops),GFP_NOFS );if (!type->typ_dt_ops) {…
goto failed;failed:
…
return rc;
Quoted 5 lines
So we are now returning an unitialized rc, did you get a gcc warning about it when compiling?
_______________________________________________
lustre-devel mailing list
[email protected]
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
--
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: staging: lustre: Optimize error handling in class_register_type()
In reply to Oleg DrokinQuoted 2 lines
NAK.
when you do this, the next statement below breaks:
I wonder about this conclusion.
Quoted 8 lines
Quoted 7 lines
type = kzalloc(sizeof(*type), GFP_NOFS); if (!type)drivers/staging/lustre/lustre/obdclass/genops.c +1
-1-return rc; +return -ENOMEM ;type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS); if (!type->typ_dt_ops) {…
Quoted 7 lines
goto failed;failed:
…
return rc;So we are now returning an unitialized rc, did you get a gcc warning about it when compiling?
I do not get such an impression if my corresponding update suggestion "[PATCH 04/12] staging: lustre: Split a condition check in class_register_type()" will be considered for this use case once more.
https://lkml.org/lkml/2016/7/26/462
https://www.mail-archive.com/[email protected]/msg1197227.html
Regards,
Markus
PATCH 6/12 staging: lustre: Return directly after a failed kcalloc() in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 16:32:31 +0200
Return directly after a memory allocation failed at the beginning.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +2 -4
@@ -1339,10 +1339,8 @@ static int mgc_process_recover_log(struct obd_device *obd, nrpages =CONFIG_READ_NRPAGES_INIT ; pages =kcalloc (nrpages,sizeof (*pages),GFP_KERNEL ); -if (!pages) { - rc = -ENOMEM ; - goto out; - } +if (!pages) +return -ENOMEM ;for (i =0 ; i < nrpages; i++) { pages[i] =alloc_page (GFP_KERNEL );
Signature · 1 line
2.9.2
PATCH 7/12 staging: lustre: Less checks after a failed alloc_page() in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 17:12:51 +0200
Release memory directly after a page allocation failed at the beginning.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +7 -8
@@ -1346,7 +1346,7 @@ static int mgc_process_recover_log(struct obd_device *obd, pages[i] =alloc_page (GFP_KERNEL );if (!pages[i]) { rc = -ENOMEM ; - goto out; + goto free_pages; } }
@@ -1461,14 +1461,13 @@ out:if (rc =0 && !eof) goto again; -if (pages) { -for (i =0 ; i < nrpages; i++) { -if (!pages[i]) -break ; -__free_page (pages[i]); - } -kfree (pages); +free_pages: +for (i =0 ; i < nrpages; i++) { +if (!pages[i]) +break ; +__free_page (pages[i]); } +kfree (pages);return rc; }
Signature · 1 line
2.9.2
PATCH 8/12 staging: lustre: Less checks after a failed ptlrpc_request_alloc() in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 17:54:24 +0200
Release memory directly after a call of the function "ptlrpc_request_alloc" failed.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -1357,7 +1357,7 @@ again: &RQF_MGS_CONFIG_READ);if (!req) { rc = -ENOMEM ; - goto out; + goto free_pages; } rc =ptlrpc_request_pack (req,LUSTRE_MGS_VERSION ,MGS_CONFIG_READ );
Signature · 1 line
2.9.2
PATCH 9/12 staging: lustre: Delete a check for the variable "req" in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 17:56:49 +0200
Delete a check for the local variable "req" which became unnecessary with the previous update step.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -2
@@ -1455,8 +1455,7 @@ again: } out: -if (req) -ptlrpc_req_finished (req); +ptlrpc_req_finished (req);if (rc =0 && !eof) goto again;
Signature · 1 line
2.9.2
PATCH 10/12 staging: lustre: Rename jump labels in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 19:29:11 +0200
Adjust jump targets according to the Linux coding style convention.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +9 -10
@@ -1362,7 +1362,7 @@ again: rc =ptlrpc_request_pack (req,LUSTRE_MGS_VERSION ,MGS_CONFIG_READ );if (rc) - goto out; + goto finish_request;/* pack request */ body =req_capsule_client_get (&req->rq_pill, &RMF_MGS_CONFIG_BODY );
@@ -1370,7 +1370,7 @@ again:if (strlcpy (body->mcb_name, cld->cld_logname,sizeof (body->mcb_name)) >=sizeof (body->mcb_name)) { rc = -E2BIG ; - goto out; + goto finish_request; } body->mcb_offset = cfg->cfg_last_idx +1 ; body->mcb_type = cld->cld_type;
@@ -1382,7 +1382,7 @@ again: MGS_BULK_PORTAL);if (!desc) { rc = -ENOMEM ; - goto out; + goto finish_request; }for (i =0 ; i < nrpages; i++)
@@ -1391,12 +1391,12 @@ again:ptlrpc_request_set_replen (req); rc =ptlrpc_queue_wait (req);if (rc) - goto out; + goto finish_request; res =req_capsule_server_get (&req->rq_pill, &RMF_MGS_CONFIG_RES );if (res->mcr_size < res->mcr_offset) { rc = -EINVAL ; - goto out; + goto finish_request; }/* always update the index even though it might have errors with
@@ -1411,18 +1411,18 @@ again: ealen =sptlrpc_cli_unwrap_bulk_read (req, req->rq_bulk,0 );if (ealen <0 ) { rc = ealen; - goto out; + goto finish_request; }if (ealen > nrpages <<PAGE_SHIFT ) { rc = -EINVAL ; - goto out; + goto finish_request; }if (ealen =0 ) {/* no logs transferred */ if (!eof) rc = -EINVAL ; - goto out; + goto finish_request; } mne_swab = !!ptlrpc_rep_need_swab (req);
@@ -1453,8 +1453,7 @@ again: ealen -=PAGE_SIZE ; } - -out: +finish_request:ptlrpc_req_finished (req);if (rc =0 && !eof)
Signature · 1 line
2.9.2
PATCH 11/12 staging: lustre: Move an assignment for the variable "eof" in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 19:40:28 +0200
Move the assignment for the local variable "eof" behind the source code for memory allocations by this function.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +2 -1
@@ -1322,7 +1322,7 @@ static int mgc_process_recover_log(struct obd_device *obd,struct ptlrpc_bulk_desc *desc;struct page **pages;int nrpages; -bool eof = true; +bool eof;bool mne_swab;int i;int ealen;
@@ -1350,6 +1350,7 @@ static int mgc_process_recover_log(struct obd_device *obd, } } + eof = true; again:LASSERT (cld_is_recover (cld));LASSERT (mutex_is_locked (&cld->cld_lock));
Signature · 1 line
2.9.2
PATCH 12/12 staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 26 Jul 2016 19:50:40 +0200
The variable "req" will eventually be set to an appropriate pointer from a call of the ptlrpc_request_alloc() function.
Thus omit the explicit initialisation which became unnecessary with a previous update step.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -1315,7 +1315,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,static int mgc_process_recover_log (struct obd_device *obd,struct config_llog_data *cld) { -struct ptlrpc_request *req =NULL ; +struct ptlrpc_request *req;struct config_llog_instance *cfg = &cld->cld_cfg;struct mgs_config_body *body;struct mgs_config_res *res;
Signature · 1 line
2.9.2
PATCH v2 4/4 staging: lustre: Fix a jump label position in osc_get_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 19:30:42 +0100
The script "checkpatch.pl" pointed out that labels should not be indented. Thus delete a horizontal tab before the jump label "out"
in the function "osc_get_info".
--- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
@@ -2727,7 +2727,7 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp, } *((u64 *)val) = *reply; - out: +out:ptlrpc_req_finished (req);return rc; }else if (KEY_IS (KEY_FIEMAP )) {
Signature · 1 line
2.6.3
[POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 14 Dec 2015 23:01:32 +0100
A status check was performed by the fsl_get_immr() function even if it was known already that a system setting did not fit to the expectations.
This implementation detail could be improved by an adjustment for a jump label according to the Linux coding style convention.
--- arch/powerpc/boot/fsl-soc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/boot/fsl-soc.c +7 -7
@@ -34,24 +34,24 @@ u32 *fsl_get_immr(void) naddr =2 ;if (naddr !=1 && naddr !=2 ) - goto err; + goto report_failure; size =getprop (soc,"ranges" , prop_buf,MAX_PROP_LEN );if (size <12 ) - goto err; + goto report_failure;if (prop_buf[0 ] !=0 ) - goto err; + goto report_failure;if (naddr =2 && prop_buf[1 ] !=0 ) - goto err; + goto report_failure;if (!dt_xlate_addr (soc, prop_buf + naddr,8 , &ret)) ret =0 ; } -err: -if (!ret) +if (!ret) { +report_failure:printf ("fsl_get_immr: Failed to find immr base\r\n" ); - + }return (u32 *)ret; }
Signature · 1 line
2.6.3
Re: [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 14 Dec 2015 23:01:32 +0100A status check was performed by the
fsl_get_immr()function even if it was known already that a system setting did not fit to the expectations.This implementation detail could be improved by an adjustment for a jump label according to the Linux coding style convention.
What is the actual problem you're trying to solve? Cluttering the code to micro-optimize an error path is not an improvement.
-Scott
PATCH 1/1 block-LDM: One function call less in ldm_validate_tocblocks() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100
This issue was detected by using the Coccinelle software.
Let us return directly if a memory allocation failed.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state, tb[1 ] =kmalloc (sizeof (*tb[1 ]) *3 ,GFP_KERNEL );if (!tb[1 ]) {ldm_crit ("Out of memory." ); - goto err; +return false; } tb[2 ] = (struct tocblock *)((u8 *)tb[1 ] +sizeof (*tb[1 ])); tb[3 ] = (struct tocblock *)((u8 *)tb[2 ] +sizeof (*tb[2 ]));
Signature · 1 line
2.6.3
Re: [PATCH] block-LDM: One function call less in ldm_validate_tocblocks() after error detection
Quoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100This issue was detected by using the Coccinelle software.
Let us return directly if a memory allocation failed.
Signed-off-by Markus Elfring <[email protected]>--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/partitions/ldm.c +0
-0
block/partitions/ldm.c static bool ldm_validate_tocblocks(struct parsed_partitions *state, · line 436
Quoted 5 lines
block/partitions/ldm.c +1
-1@@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state, tb[1 ] =kmalloc (sizeof (*tb[1 ]) *3 ,GFP_KERNEL );if (!tb[1 ]) {ldm_crit ("Out of memory." ); - goto err; +return false;
The ldm_crit, which is just a printk, is also not necessary, because kmalloc already generates backtrace information on failure. So you could clean up the whole thing at once.
julia
Quoted 7 lines
block/partitions/ldm.c +0
-1} tb[2 ] = (struct tocblock *)((u8 *)tb[1 ] +sizeof (*tb[1 ])); tb[3 ] = (struct tocblock *)((u8 *)tb[2 ] +sizeof (*tb[2 ])); --2.6.3
cover block-LDM: Improvements for exception handling
From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 17:32:12 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (5):
One function call less in ldm_validate_tocblocks() after error detection Delete extra log messages for memory allocation failures
One function call less in ldm_partition() after error detection Less function calls in ldm_validate_privheads() after error detection Fine-tuning for the source code formatting
block/partitions/ldm.c | 455 +++++++++++++++++++++++++------------------------ 1 file changed, 236 insertions(+), 219 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/5 block-LDM: One function call less in ldm_validate_tocblocks() after error detection
From: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100
This issue was detected by using the Coccinelle software.
Let us return directly if a memory allocation failed.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state, tb[1 ] =kmalloc (sizeof (*tb[1 ]) *3 ,GFP_KERNEL );if (!tb[1 ]) {ldm_crit ("Out of memory." ); - goto err; +return false; } tb[2 ] = (struct tocblock *)((u8 *)tb[1 ] +sizeof (*tb[1 ])); tb[3 ] = (struct tocblock *)((u8 *)tb[2 ] +sizeof (*tb[2 ]));
Signature · 1 line
2.6.3
PATCH 2/5 block-LDM: Delete extra log messages for memory allocation failures
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 13:21:01 +0100
A failed call of the kmalloc() function can generate appropriate information about insufficient memory already.
Thus remove unnecessary log messages for such failures.
--- block/partitions/ldm.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
block/partitions/ldm.c +5 -15
@@ -343,10 +343,8 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, ph[1 ] =kmalloc (sizeof (*ph[1 ]),GFP_KERNEL ); ph[2 ] =kmalloc (sizeof (*ph[2 ]),GFP_KERNEL ); -if (!ph[1 ] || !ph[2 ]) { -ldm_crit ("Out of memory." ); +if (!ph[1 ] || !ph[2 ]) goto out; - }/* off[1 & 2] are relative to ph[0]->config_start */ ph[0 ]->config_start =0 ;
@@ -431,10 +429,8 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state, ph = &ldb->ph; tb[0 ] = &ldb->toc; tb[1 ] =kmalloc (sizeof (*tb[1 ]) *3 ,GFP_KERNEL ); -if (!tb[1 ]) { -ldm_crit ("Out of memory." ); +if (!tb[1 ])return false; - } tb[2 ] = (struct tocblock *)((u8 *)tb[1 ] +sizeof (*tb[1 ])); tb[3 ] = (struct tocblock *)((u8 *)tb[2 ] +sizeof (*tb[2 ]));/*
@@ -1239,10 +1235,8 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)BUG_ON (!data || !ldb); vb =kmalloc (sizeof (*vb),GFP_KERNEL ); -if (!vb) { -ldm_crit ("Out of memory." ); +if (!vb)return false; - }if (!ldm_parse_vblk (data, len, vb)) {kfree (vb);
@@ -1325,10 +1319,8 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) } f =kmalloc (sizeof (*f) + size*num,GFP_KERNEL ); -if (!f) { -ldm_crit ("Out of memory." ); +if (!f)return false; - } f->group = group; f->num = num;
@@ -1519,10 +1511,8 @@ int ldm_partition(struct parsed_partitions *state)return 0 ; ldb =kmalloc (sizeof (*ldb),GFP_KERNEL ); -if (!ldb) { -ldm_crit ("Out of memory." ); +if (!ldb) goto out; - }/* Parse and check privheads. */ if (!ldm_validate_privheads (state, &ldb->ph))
Signature · 1 line
2.6.3
PATCH 3/5 block-LDM: One function call less in ldm_partition() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 13:32:51 +0100
Let us return directly if a memory allocation failed.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -1512,7 +1512,7 @@ int ldm_partition(struct parsed_partitions *state) ldb =kmalloc (sizeof (*ldb),GFP_KERNEL );if (!ldb) - goto out; +return -1 ;/* Parse and check privheads. */ if (!ldm_validate_privheads (state, &ldb->ph))
Signature · 1 line
2.6.3
PATCH 4/5 block-LDM: Less function calls in ldm_validate_privheads() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 14:31:01 +0100
The kfree() function was called by the ldm_validate_privheads() function during error handling even if the passed variable "ph" contained a null pointer.
* Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
* The variable "result" will eventually be set to an appropriate value. Thus let us omit the explicit initialisation at the beginning.
--- block/partitions/ldm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
block/partitions/ldm.c +18 -12
@@ -335,16 +335,20 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,struct privhead *ph[3 ] = { ph1 };Sector sect;u8 *data; -bool result = false; +bool result;long num_sects;int i;BUG_ON (!state || !ph1); ph[1 ] =kmalloc (sizeof (*ph[1 ]),GFP_KERNEL ); +if (!ph[1 ]) +return false; ph[2 ] =kmalloc (sizeof (*ph[2 ]),GFP_KERNEL ); -if (!ph[1 ] || !ph[2 ]) - goto out; +if (!ph[2 ]) { + result = false; + goto free_a_head; + }/* off[1 & 2] are relative to ph[0]->config_start */ ph[0 ]->config_start =0 ;
@@ -355,14 +359,15 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, §);if (!data) {ldm_crit ("Disk read failed." ); - goto out; + result = false; + goto free_another_head; } result =ldm_parse_privhead (data, ph[i]);put_dev_sector (sect);if (!result) {ldm_error ("Cannot find PRIVHEAD %d." , i+1 );/* Log again */ if (i <2 ) - goto out;/* Already logged */ + goto free_another_head;/* Already logged */ else break ;/* FIXME ignore for now, 3rd PH can fail on odd-sized disks */ }
@@ -373,30 +378,31 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,if ((ph[0 ]->config_start > num_sects) || ((ph[0 ]->config_start + ph[0 ]->config_size) > num_sects)) {ldm_crit ("Database extends beyond the end of the disk." ); - goto out; + goto free_another_head; }if ((ph[0 ]->logical_disk_start > ph[0 ]->config_start) || ((ph[0 ]->logical_disk_start + ph[0 ]->logical_disk_size) > ph[0 ]->config_start)) {ldm_crit ("Disk and database overlap." ); - goto out; + goto free_another_head; }if (!ldm_compare_privheads (ph[0 ], ph[1 ])) {ldm_crit ("Primary and backup PRIVHEADs don't match." ); - goto out; + goto free_another_head; }/* FIXME ignore this for now if (!ldm_compare_privheads (ph[0], ph[2])) { ldm_crit ("Primary and backup PRIVHEADs don't match."); -goto out; +goto free_another_head; }*/ ldm_debug ("Validated PRIVHEADs successfully." ); result = true; -out: -kfree (ph[1 ]); -kfree (ph[2 ]); +free_another_head: +kfree (ph[2 ]); +free_a_head: +kfree (ph[1 ]);return result; }
Signature · 1 line
2.6.3
PATCH 5/5 block-LDM: Fine-tuning for the source code formatting
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 17:23:25 +0100
1. Remove some space characters and add a few according to the Linux coding style convention.
2. Reformat a bit of source code also for one switch statement.
3. Apply a few more recommendations from the script "checkpatch.pl".
--- block/partitions/ldm.c | 405 ++++++++++++++++++++++++++----------------------- 1 file changed, 213 insertions(+), 192 deletions(-)
block/partitions/ldm.c +213 -192
@@ -42,12 +42,12 @@#ifndef CONFIG_LDM_DEBUG #define ldm_debug (...) do {} while (0)#else -#define ldm_debug(f, a...) _ldm_printk (KERN_DEBUG, __func__, f, ##a) +#define ldm_debug(f, a...) _ldm_printk(KERN_DEBUG, __func__, f, ##a)#endif -#define ldm_crit(f, a...) _ldm_printk (KERN_CRIT, __func__, f, ##a) -#define ldm_error(f, a...) _ldm_printk (KERN_ERR, __func__, f, ##a) -#define ldm_info(f, a...) _ldm_printk (KERN_INFO, __func__, f, ##a) +#define ldm_crit(f, a...) _ldm_printk(KERN_CRIT, __func__, f, ##a) +#define ldm_error(f, a...) _ldm_printk(KERN_ERR, __func__, f, ##a) +#define ldm_info(f, a...) _ldm_printk(KERN_INFO, __func__, f, ##a) static __printf(3, 4) void _ldm_printk(const char *level, const char *function, const char *fmt, ...)
@@ -55,7 +55,7 @@ void _ldm_printk(const char *level, const char *function, const char *fmt, ...)struct va_format vaf;va_list args; -va_start (args, fmt); +va_start (args, fmt); vaf.fmt = fmt; vaf.va = &args;
@@ -74,7 +74,7 @@ void _ldm_printk(const char *level, const char *function, const char *fmt, ...)* Return: 0-255 Success, the byte was parsed correctly * -1 Error, an invalid character was supplied */ -static int ldm_parse_hexbyte (const u8 *src) +static int ldm_parse_hexbyte (const u8 *src) {unsigned int x;/* For correct wrapping */ int h;
@@ -102,7 +102,7 @@ static int ldm_parse_hexbyte (const u8 *src)* Return: 'true' @dest contains binary GUID * 'false' @dest contents are undefined */ -static bool ldm_parse_guid (const u8 *src,u8 *dest) +static bool ldm_parse_guid (const u8 *src,u8 *dest) {static const int size[] = {4 ,2 ,2 ,2 ,6 };int i, j, v;
@@ -112,10 +112,11 @@ static bool ldm_parse_guid (const u8 *src, u8 *dest)return false;for (j =0 ; j <5 ; j++, src++) -for (i =0 ; i < size[j]; i++, src+=2 , *dest++ = v) -if ((v =ldm_parse_hexbyte (src)) <0 ) +for (i =0 ; i < size[j]; i++, src +=2 , *dest++ = v) { + v =ldm_parse_hexbyte (src); +if (v <0 )return false; - + }return true; }
@@ -189,36 +190,36 @@ static bool ldm_parse_privhead(const u8 *data, struct privhead *ph)* Return: 'true' @toc contains the TOCBLOCK data * 'false' @toc contents are undefined */ -static bool ldm_parse_tocblock (const u8 *data,struct tocblock *toc) +static bool ldm_parse_tocblock (const u8 *data,struct tocblock *toc) { -BUG_ON (!data || !toc); +BUG_ON (!data || !toc);if (MAGIC_TOCBLOCK !=get_unaligned_be64 (data)) { -ldm_crit ("Cannot find TOCBLOCK, database may be corrupt." ); +ldm_crit ("Cannot find TOCBLOCK, database may be corrupt." );return false; } -strncpy (toc->bitmap1_name, data +0x24 ,sizeof (toc->bitmap1_name)); +strncpy (toc->bitmap1_name, data +0x24 ,sizeof (toc->bitmap1_name)); toc->bitmap1_name[sizeof (toc->bitmap1_name) -1 ] =0 ; toc->bitmap1_start =get_unaligned_be64 (data +0x2E ); toc->bitmap1_size =get_unaligned_be64 (data +0x36 ); -if (strncmp (toc->bitmap1_name,TOC_BITMAP1 , -sizeof (toc->bitmap1_name)) !=0 ) { -ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'." , +if (strncmp (toc->bitmap1_name,TOC_BITMAP1 , +sizeof (toc->bitmap1_name)) !=0 ) { +ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'." ,TOC_BITMAP1 , toc->bitmap1_name);return false; } -strncpy (toc->bitmap2_name, data +0x46 ,sizeof (toc->bitmap2_name)); - toc->bitmap2_name[sizeof (toc->bitmap2_name) -1 ] =0 ; +strncpy (toc->bitmap2_name, data +0x46 ,sizeof (toc->bitmap2_name)); + toc->bitmap2_name[sizeof (toc->bitmap2_name) -1 ] =0 ; toc->bitmap2_start =get_unaligned_be64 (data +0x50 ); toc->bitmap2_size =get_unaligned_be64 (data +0x58 ); -if (strncmp (toc->bitmap2_name,TOC_BITMAP2 , -sizeof (toc->bitmap2_name)) !=0 ) { -ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'." , +if (strncmp (toc->bitmap2_name,TOC_BITMAP2 , +sizeof (toc->bitmap2_name)) !=0 ) { +ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'." ,TOC_BITMAP2 , toc->bitmap2_name);return false; } -ldm_debug ("Parsed TOCBLOCK successfully." ); +ldm_debug ("Parsed TOCBLOCK successfully." );return true; }
@@ -235,33 +236,33 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc)* Return: 'true' @vm contains VMDB info * 'false' @vm contents are undefined */ -static bool ldm_parse_vmdb (const u8 *data,struct vmdb *vm) +static bool ldm_parse_vmdb (const u8 *data,struct vmdb *vm) { -BUG_ON (!data || !vm); +BUG_ON (!data || !vm);if (MAGIC_VMDB !=get_unaligned_be32 (data)) { -ldm_crit ("Cannot find the VMDB, database may be corrupt." ); +ldm_crit ("Cannot find the VMDB, database may be corrupt." );return false; } vm->ver_major =get_unaligned_be16 (data +0x12 ); vm->ver_minor =get_unaligned_be16 (data +0x14 );if ((vm->ver_major !=4 ) || (vm->ver_minor !=10 )) { -ldm_error ("Expected VMDB version %d.%d, got %d.%d. " +ldm_error ("Expected VMDB version %d.%d, got %d.%d. " "Aborting." ,4 ,10 , vm->ver_major, vm->ver_minor);return false; } vm->vblk_size =get_unaligned_be32 (data +0x08 );if (vm->vblk_size =0 ) { -ldm_error ("Illegal VBLK size" ); +ldm_error ("Illegal VBLK size" );return false; } vm->vblk_offset =get_unaligned_be32 (data +0x0C ); vm->last_vblk_seq =get_unaligned_be32 (data +0x04 ); -ldm_debug ("Parsed VMDB successfully." ); +ldm_debug ("Parsed VMDB successfully." );return true; }
@@ -275,10 +276,10 @@ static bool ldm_parse_vmdb (const u8 *data, struct vmdb *vm)* Return: 'true' Identical * 'false' Different */ -static bool ldm_compare_privheads (const struct privhead *ph1, +static bool ldm_compare_privheads (const struct privhead *ph1,const struct privhead *ph2) { -BUG_ON (!ph1 || !ph2); +BUG_ON (!ph1 || !ph2); return ((ph1->ver_major = ph2->ver_major) && (ph1->ver_minor = ph2->ver_minor) &&
@@ -286,7 +287,7 @@ static bool ldm_compare_privheads (const struct privhead *ph1, (ph1->logical_disk_size = ph2->logical_disk_size) && (ph1->config_start = ph2->config_start) && (ph1->config_size = ph2->config_size) && - !memcmp (ph1->disk_id, ph2->disk_id, GUID_SIZE)); + !memcmp(ph1->disk_id, ph2->disk_id, GUID_SIZE)); }/**
@@ -299,19 +300,19 @@ static bool ldm_compare_privheads (const struct privhead *ph1,* Return: 'true' Identical * 'false' Different */ -static bool ldm_compare_tocblocks (const struct tocblock *toc1, +static bool ldm_compare_tocblocks (const struct tocblock *toc1,const struct tocblock *toc2) { -BUG_ON (!toc1 || !toc2); +BUG_ON (!toc1 || !toc2);return ((toc1->bitmap1_start = toc2->bitmap1_start) && (toc1->bitmap1_size = toc2->bitmap1_size) && (toc1->bitmap2_start = toc2->bitmap2_start) && (toc1->bitmap2_size = toc2->bitmap2_size) && - !strncmp (toc1->bitmap1_name, toc2->bitmap1_name, -sizeof (toc1->bitmap1_name)) && - !strncmp (toc1->bitmap2_name, toc2->bitmap2_name, -sizeof (toc1->bitmap2_name))); + !strncmp (toc1->bitmap1_name, toc2->bitmap1_name, +sizeof (toc1->bitmap1_name)) && + !strncmp (toc1->bitmap2_name, toc2->bitmap2_name, +sizeof (toc1->bitmap2_name))); }/**
@@ -339,12 +340,12 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,long num_sects;int i; -BUG_ON (!state || !ph1); +BUG_ON (!state || !ph1); - ph[1 ] =kmalloc (sizeof (*ph[1 ]),GFP_KERNEL ); + ph[1 ] =kmalloc (sizeof (*ph[1 ]),GFP_KERNEL );if (!ph[1 ])return false; - ph[2 ] =kmalloc (sizeof (*ph[2 ]),GFP_KERNEL ); + ph[2 ] =kmalloc (sizeof (*ph[2 ]),GFP_KERNEL );if (!ph[2 ]) { result = false; goto free_a_head;
@@ -358,18 +359,23 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, data =read_part_sector (state, ph[0 ]->config_start + off[i], §);if (!data) { -ldm_crit ("Disk read failed." ); +ldm_crit ("Disk read failed." ); result = false; goto free_another_head; } - result =ldm_parse_privhead (data, ph[i]); + result =ldm_parse_privhead (data, ph[i]);put_dev_sector (sect);if (!result) { -ldm_error ("Cannot find PRIVHEAD %d." , i+1 );/* Log again */ +/* Log again */ +ldm_error ("Cannot find PRIVHEAD %d." , i +1 );if (i <2 ) goto free_another_head;/* Already logged */ else -break ;/* FIXME ignore for now, 3rd PH can fail on odd-sized disks */ +/* +* FIXME: ignore for now, +* 3rd PH can fail on odd-sized disks +*/ +break ; } }
@@ -377,19 +383,19 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,if ((ph[0 ]->config_start > num_sects) || ((ph[0 ]->config_start + ph[0 ]->config_size) > num_sects)) { -ldm_crit ("Database extends beyond the end of the disk." ); +ldm_crit ("Database extends beyond the end of the disk." ); goto free_another_head; }if ((ph[0 ]->logical_disk_start > ph[0 ]->config_start) || ((ph[0 ]->logical_disk_start + ph[0 ]->logical_disk_size) > ph[0 ]->config_start)) { -ldm_crit ("Disk and database overlap." ); +ldm_crit ("Disk and database overlap." ); goto free_another_head; } -if (!ldm_compare_privheads (ph[0 ], ph[1 ])) { -ldm_crit ("Primary and backup PRIVHEADs don't match." ); +if (!ldm_compare_privheads (ph[0 ], ph[1 ])) { +ldm_crit ("Primary and backup PRIVHEADs don't match." ); goto free_another_head; }/* FIXME ignore this for now
@@ -397,7 +403,7 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,ldm_crit ("Primary and backup PRIVHEADs don't match."); goto free_another_head; }*/ -ldm_debug ("Validated PRIVHEADs successfully." ); +ldm_debug ("Validated PRIVHEADs successfully." ); result = true; free_another_head:kfree (ph[2 ]);
@@ -501,42 +507,42 @@ static bool ldm_validate_vmdb(struct parsed_partitions *state,struct vmdb *vm;struct tocblock *toc; -BUG_ON (!state || !ldb); +BUG_ON (!state || !ldb); vm = &ldb->vm; toc = &ldb->toc; data =read_part_sector (state, base +OFF_VMDB , §);if (!data) { -ldm_crit ("Disk read failed." ); +ldm_crit ("Disk read failed." );return false; } -if (!ldm_parse_vmdb (data, vm)) +if (!ldm_parse_vmdb (data, vm)) goto out;/* Already logged */ /* Are there uncommitted transactions? */ if (get_unaligned_be16 (data +0x10 ) !=0x01 ) { -ldm_crit ("Database is not in a consistent state. Aborting." ); +ldm_crit ("Database is not in a consistent state. Aborting." ); goto out; }if (vm->vblk_offset !=512 ) -ldm_info ("VBLKs start at offset 0x%04x." , vm->vblk_offset); +ldm_info ("VBLKs start at offset 0x%04x." , vm->vblk_offset);/* * The last_vblkd_seq can be before the end of the vmdb, just make sure * it is not out of bounds. */ if ((vm->vblk_size * vm->last_vblk_seq) > (toc->bitmap1_size <<9 )) { -ldm_crit ("VMDB exceeds allowed size specified by TOCBLOCK. " +ldm_crit ("VMDB exceeds allowed size specified by TOCBLOCK. " "Database is corrupt. Aborting." ); goto out; } result = true; out: -put_dev_sector (sect); +put_dev_sector (sect);return result; }
@@ -569,11 +575,11 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state) data =read_part_sector (state,0 , §);if (!data) { -ldm_info ("Disk read failed." ); +ldm_info ("Disk read failed." );return false; } -if (*(__le16 *) (data +0x01FE ) !=cpu_to_le16 (MSDOS_LABEL_MAGIC )) +if (*(__le16 *) (data +0x01FE ) !=cpu_to_le16 (MSDOS_LABEL_MAGIC )) goto out; p = (struct partition *)(data +0x01BE );
@@ -584,10 +590,10 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state) }if (result) -ldm_debug ("Found W2K dynamic disk partition type." ); +ldm_debug ("Found W2K dynamic disk partition type." ); out: -put_dev_sector (sect); +put_dev_sector (sect);return result; }
@@ -603,15 +609,16 @@ out:* Return: Pointer, A matching vblk was found * NULL, No match, or an error */ -static struct vblk *ldm_get_disk_objid (const struct ldmdb *ldb) +static struct vblk *ldm_get_disk_objid (const struct ldmdb *ldb) {struct list_head *item; -BUG_ON (!ldb); +BUG_ON (!ldb); - list_for_each (item, &ldb->v_disk) { - struct vblk *v = list_entry (item, struct vblk, list); -if (!memcmp (v->vblk.disk.disk_id, ldb->ph.disk_id,GUID_SIZE )) +list_for_each (item, &ldb->v_disk) { + struct vblk *v = list_entry(item, struct vblk, list); + +if (!memcmp (v->vblk.disk.disk_id, ldb->ph.disk_id,GUID_SIZE ))return v; }
@@ -635,7 +642,7 @@ static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb)* Return: 'true' Partition created * 'false' Error, probably a range checking problem */ -static bool ldm_create_data_partitions (struct parsed_partitions *pp, +static bool ldm_create_data_partitions (struct parsed_partitions *pp,const struct ldmdb *ldb) {struct list_head *item;
@@ -644,25 +651,25 @@ static bool ldm_create_data_partitions (struct parsed_partitions *pp,struct vblk_part *part;int part_num =1 ; -BUG_ON (!pp || !ldb); +BUG_ON (!pp || !ldb); - disk =ldm_get_disk_objid (ldb); + disk =ldm_get_disk_objid (ldb);if (!disk) { -ldm_crit ("Can't find the ID of this disk in the database." ); +ldm_crit ("Can't find the ID of this disk in the database." );return false; }strlcat (pp->pp_buf," [LDM]" ,PAGE_SIZE );/* Create the data partitions */ - list_for_each (item, &ldb->v_part) { - vb = list_entry (item, struct vblk, list); +list_for_each (item, &ldb->v_part) { + vb = list_entry(item, struct vblk, list); part = &vb->vblk.part;if (part->disk_id != disk->obj_id)continue ; -put_partition (pp, part_num, ldb->ph.logical_disk_start + +put_partition (pp, part_num, ldb->ph.logical_disk_start + part->start, part->size); part_num++; }
@@ -722,12 +729,12 @@ static int ldm_relative(const u8 *buffer, int buflen, int base, int offset)* Return: n A number * 0 Zero, or an error occurred */ -static u64 ldm_get_vnum (const u8 *block) +static u64 ldm_get_vnum (const u8 *block) {u64 tmp =0 ;u8 length; -BUG_ON (!block); +BUG_ON (!block); length = *block++;
@@ -735,7 +742,7 @@ static u64 ldm_get_vnum (const u8 *block)while (length--) tmp = (tmp <<8 ) | *block++; else - ldm_error ("Illegal length %d.", length); + ldm_error("Illegal length %d.", length);return tmp; }
@@ -757,18 +764,18 @@ static u64 ldm_get_vnum (const u8 *block)* n, String length in characters (excluding NULL) * buflen-1, String was truncated. */ -static int ldm_get_vstr (const u8 *block,u8 *buffer,int buflen) +static int ldm_get_vstr (const u8 *block,u8 *buffer,int buflen) {int length; -BUG_ON (!block || !buffer); +BUG_ON (!block || !buffer); length = block[0 ];if (length >= buflen) { -ldm_error ("Truncating string %d -> %d." , length, buflen); +ldm_error ("Truncating string %d -> %d." , length, buflen); length = buflen -1 ; } -memcpy (buffer, block +1 , length); +memcpy (buffer, block +1 , length); buffer[length] =0 ;return length; }
@@ -785,22 +792,22 @@ static int ldm_get_vstr (const u8 *block, u8 *buffer, int buflen)* Return: 'true' @vb contains a Component VBLK * 'false' @vb contents are not defined */ -static bool ldm_parse_cmp3 (const u8 *buffer,int buflen,struct vblk *vb) +static bool ldm_parse_cmp3 (const u8 *buffer,int buflen,struct vblk *vb) {int r_objid, r_name, r_vstate, r_child, r_parent, r_stripe, r_cols, len;struct vblk_comp *comp; -BUG_ON (!buffer || !vb); +BUG_ON (!buffer || !vb); - r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); - r_name =ldm_relative (buffer, buflen,0x18 , r_objid); - r_vstate =ldm_relative (buffer, buflen,0x18 , r_name); - r_child =ldm_relative (buffer, buflen,0x1D , r_vstate); - r_parent =ldm_relative (buffer, buflen,0x2D , r_child); + r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); + r_name =ldm_relative (buffer, buflen,0x18 , r_objid); + r_vstate =ldm_relative (buffer, buflen,0x18 , r_name); + r_child =ldm_relative (buffer, buflen,0x1D , r_vstate); + r_parent =ldm_relative (buffer, buflen,0x2D , r_child);if (buffer[0x12 ] &VBLK_FLAG_COMP_STRIPE ) { - r_stripe =ldm_relative (buffer, buflen,0x2E , r_parent); - r_cols =ldm_relative (buffer, buflen,0x2E , r_stripe); + r_stripe =ldm_relative (buffer, buflen,0x2E , r_parent); + r_cols =ldm_relative (buffer, buflen,0x2E , r_stripe); len = r_cols; }else { r_stripe =0 ;
@@ -815,12 +822,12 @@ static bool ldm_parse_cmp3 (const u8 *buffer, int buflen, struct vblk *vb)return false; comp = &vb->vblk.comp; -ldm_get_vstr (buffer +0x18 + r_name, comp->state, -sizeof (comp->state)); +ldm_get_vstr (buffer +0x18 + r_name, comp->state, +sizeof (comp->state)); comp->type = buffer[0x18 + r_vstate]; - comp->children =ldm_get_vnum (buffer +0x1D + r_vstate); - comp->parent_id =ldm_get_vnum (buffer +0x2D + r_child); - comp->chunksize = r_stripe ?ldm_get_vnum (buffer+r_parent+0x2E ) :0 ; + comp->children =ldm_get_vnum (buffer +0x1D + r_vstate); + comp->parent_id =ldm_get_vnum (buffer +0x2D + r_child); + comp->chunksize = r_stripe ?ldm_get_vnum (buffer + r_parent +0x2E ) :0 ;return true; }
@@ -836,20 +843,20 @@ static bool ldm_parse_cmp3 (const u8 *buffer, int buflen, struct vblk *vb)* Return: 'true' @vb contains a Disk Group VBLK * 'false' @vb contents are not defined */ -static int ldm_parse_dgr3 (const u8 *buffer,int buflen,struct vblk *vb) +static int ldm_parse_dgr3 (const u8 *buffer,int buflen,struct vblk *vb) {int r_objid, r_name, r_diskid, r_id1, r_id2, len;struct vblk_dgrp *dgrp; -BUG_ON (!buffer || !vb); +BUG_ON (!buffer || !vb); - r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); - r_name =ldm_relative (buffer, buflen,0x18 , r_objid); - r_diskid =ldm_relative (buffer, buflen,0x18 , r_name); + r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); + r_name =ldm_relative (buffer, buflen,0x18 , r_objid); + r_diskid =ldm_relative (buffer, buflen,0x18 , r_name);if (buffer[0x12 ] &VBLK_FLAG_DGR3_IDS ) { - r_id1 =ldm_relative (buffer, buflen,0x24 , r_diskid); - r_id2 =ldm_relative (buffer, buflen,0x24 , r_id1); + r_id1 =ldm_relative (buffer, buflen,0x24 , r_diskid); + r_id2 =ldm_relative (buffer, buflen,0x24 , r_id1); len = r_id2; }else { r_id1 =0 ;
@@ -864,8 +871,8 @@ static int ldm_parse_dgr3 (const u8 *buffer, int buflen, struct vblk *vb)return false; dgrp = &vb->vblk.dgrp; -ldm_get_vstr (buffer +0x18 + r_name, dgrp->disk_id, -sizeof (dgrp->disk_id)); +ldm_get_vstr (buffer +0x18 + r_name, dgrp->disk_id, +sizeof (dgrp->disk_id));return true; }
@@ -886,14 +893,14 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb)int r_objid, r_name, r_id1, r_id2, len;struct vblk_dgrp *dgrp; -BUG_ON (!buffer || !vb); +BUG_ON (!buffer || !vb); - r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); - r_name =ldm_relative (buffer, buflen,0x18 , r_objid); + r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); + r_name =ldm_relative (buffer, buflen,0x18 , r_objid);if (buffer[0x12 ] &VBLK_FLAG_DGR4_IDS ) { - r_id1 =ldm_relative (buffer, buflen,0x44 , r_name); - r_id2 =ldm_relative (buffer, buflen,0x44 , r_id1); + r_id1 =ldm_relative (buffer, buflen,0x44 , r_name); + r_id2 =ldm_relative (buffer, buflen,0x44 , r_id1); len = r_id2; }else { r_id1 =0 ;
@@ -909,7 +916,7 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb) dgrp = &vb->vblk.dgrp; -ldm_get_vstr (buffer +0x18 + r_objid, buf,sizeof (buf)); +ldm_get_vstr (buffer +0x18 + r_objid, buf,sizeof (buf));return true; }
@@ -924,17 +931,17 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb)* Return: 'true' @vb contains a Disk VBLK * 'false' @vb contents are not defined */ -static bool ldm_parse_dsk3 (const u8 *buffer,int buflen,struct vblk *vb) +static bool ldm_parse_dsk3 (const u8 *buffer,int buflen,struct vblk *vb) {int r_objid, r_name, r_diskid, r_altname, len;struct vblk_disk *disk; -BUG_ON (!buffer || !vb); +BUG_ON (!buffer || !vb); - r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); - r_name =ldm_relative (buffer, buflen,0x18 , r_objid); - r_diskid =ldm_relative (buffer, buflen,0x18 , r_name); - r_altname =ldm_relative (buffer, buflen,0x18 , r_diskid); + r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); + r_name =ldm_relative (buffer, buflen,0x18 , r_objid); + r_diskid =ldm_relative (buffer, buflen,0x18 , r_name); + r_altname =ldm_relative (buffer, buflen,0x18 , r_diskid); len = r_altname;if (len <0 )return false;
@@ -944,9 +951,9 @@ static bool ldm_parse_dsk3 (const u8 *buffer, int buflen, struct vblk *vb)return false; disk = &vb->vblk.disk; -ldm_get_vstr (buffer +0x18 + r_diskid, disk->alt_name, -sizeof (disk->alt_name)); -if (!ldm_parse_guid (buffer +0x19 + r_name, disk->disk_id)) +ldm_get_vstr (buffer +0x18 + r_diskid, disk->alt_name, +sizeof (disk->alt_name)); +if (!ldm_parse_guid (buffer +0x19 + r_name, disk->disk_id))return false;return true;
@@ -963,15 +970,15 @@ static bool ldm_parse_dsk3 (const u8 *buffer, int buflen, struct vblk *vb)* Return: 'true' @vb contains a Disk VBLK * 'false' @vb contents are not defined */ -static bool ldm_parse_dsk4 (const u8 *buffer,int buflen,struct vblk *vb) +static bool ldm_parse_dsk4 (const u8 *buffer,int buflen,struct vblk *vb) {int r_objid, r_name, len;struct vblk_disk *disk; -BUG_ON (!buffer || !vb); +BUG_ON (!buffer || !vb); - r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); - r_name =ldm_relative (buffer, buflen,0x18 , r_objid); + r_objid =ldm_relative (buffer, buflen,0x18 ,0 ); + r_name =ldm_relative (buffer, buflen,0x18 , r_objid); len = r_name;if (len <0 )return false;
@@ -981,7 +988,7 @@ static bool ldm_parse_dsk4 (const u8 *buffer, int buflen, struct vblk *vb)return false; disk = &vb->vblk.disk; -memcpy (disk->disk_id, buffer +0x18 + r_name,GUID_SIZE ); +memcpy (disk->disk_id, buffer +0x18 + r_name,GUID_SIZE );return true; }
@@ -1181,39 +1188,53 @@ static bool ldm_parse_vol5(const u8 *buffer, int buflen, struct vblk *vb)* Return: 'true' @vb contains a VBLK * 'false' @vb contents are not defined */ -static bool ldm_parse_vblk (const u8 *buf,int len,struct vblk *vb) +static bool ldm_parse_vblk (const u8 *buf,int len,struct vblk *vb) {bool result = false;int r_objid; -BUG_ON (!buf || !vb); +BUG_ON (!buf || !vb); - r_objid =ldm_relative (buf, len,0x18 ,0 ); + r_objid =ldm_relative (buf, len,0x18 ,0 );if (r_objid <0 ) { -ldm_error ("VBLK header is corrupt." ); +ldm_error ("VBLK header is corrupt." );return false; } vb->flags = buf[0x12 ]; vb->type = buf[0x13 ]; - vb->obj_id =ldm_get_vnum (buf +0x18 ); -ldm_get_vstr (buf+0x18 +r_objid, vb->name,sizeof (vb->name)); + vb->obj_id =ldm_get_vnum (buf +0x18 ); +ldm_get_vstr (buf +0x18 + r_objid, vb->name,sizeof (vb->name));switch (vb->type) { -case VBLK_CMP3 : result =ldm_parse_cmp3 (buf, len, vb);break ; -case VBLK_DSK3 : result =ldm_parse_dsk3 (buf, len, vb);break ; -case VBLK_DSK4 : result =ldm_parse_dsk4 (buf, len, vb);break ; -case VBLK_DGR3 : result =ldm_parse_dgr3 (buf, len, vb);break ; -case VBLK_DGR4 : result =ldm_parse_dgr4 (buf, len, vb);break ; -case VBLK_PRT3 : result =ldm_parse_prt3 (buf, len, vb);break ; -case VBLK_VOL5 : result =ldm_parse_vol5 (buf, len, vb);break ; +case VBLK_CMP3 : + result =ldm_parse_cmp3 (buf, len, vb); +break ; +case VBLK_DSK3 : + result =ldm_parse_dsk3 (buf, len, vb); +break ; +case VBLK_DSK4 : + result =ldm_parse_dsk4 (buf, len, vb); +break ; +case VBLK_DGR3 : + result =ldm_parse_dgr3 (buf, len, vb); +break ; +case VBLK_DGR4 : + result =ldm_parse_dgr4 (buf, len, vb); +break ; +case VBLK_PRT3 : + result =ldm_parse_prt3 (buf, len, vb); +break ; +case VBLK_VOL5 : + result =ldm_parse_vol5 (buf, len, vb); +break ; }if (result) -ldm_debug ("Parsed VBLK 0x%llx (type: 0x%02x) ok." , +ldm_debug ("Parsed VBLK 0x%llx (type: 0x%02x) ok." , (unsigned long long ) vb->obj_id, vb->type);else -ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x)." , +ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x)." , (unsigned long long ) vb->obj_id, vb->type);return result;
@@ -1238,13 +1259,13 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)struct vblk *vb;struct list_head *item; -BUG_ON (!data || !ldb); +BUG_ON (!data || !ldb); - vb =kmalloc (sizeof (*vb),GFP_KERNEL ); + vb =kmalloc (sizeof (*vb),GFP_KERNEL );if (!vb)return false; -if (!ldm_parse_vblk (data, len, vb)) { +if (!ldm_parse_vblk (data, len, vb)) {kfree (vb);return false;/* Already logged */ }
@@ -1253,29 +1274,29 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)switch (vb->type) {case VBLK_DGR3 :case VBLK_DGR4 : -list_add (&vb->list, &ldb->v_dgrp); +list_add (&vb->list, &ldb->v_dgrp);break ;case VBLK_DSK3 :case VBLK_DSK4 : -list_add (&vb->list, &ldb->v_disk); +list_add (&vb->list, &ldb->v_disk);break ;case VBLK_VOL5 : -list_add (&vb->list, &ldb->v_volu); +list_add (&vb->list, &ldb->v_volu);break ;case VBLK_CMP3 : -list_add (&vb->list, &ldb->v_comp); +list_add (&vb->list, &ldb->v_comp);break ;case VBLK_PRT3 :/* Sort by the partition's start sector. */ - list_for_each (item, &ldb->v_part) { - struct vblk *v = list_entry (item, struct vblk, list); +list_for_each (item, &ldb->v_part) { + struct vblk *v = list_entry(item, struct vblk, list);if ((v->vblk.part.disk_id = vb->vblk.part.disk_id) && (v->vblk.part.start > vb->vblk.part.start)) { -list_add_tail (&vb->list, &v->list); +list_add_tail (&vb->list, &v->list);return true; } } -list_add_tail (&vb->list, &ldb->v_part); +list_add_tail (&vb->list, &ldb->v_part);break ; }return true;
@@ -1293,13 +1314,13 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)* Return: 'true' Success, the VBLK was added to the list * 'false' Error, a problem occurred */ -static bool ldm_frag_add (const u8 *data,int size,struct list_head *frags) +static bool ldm_frag_add (const u8 *data,int size,struct list_head *frags) {struct frag *f;struct list_head *item;int rec, num, group; -BUG_ON (!data || !frags); +BUG_ON (!data || !frags);if (size <2 *VBLK_SIZE_HEAD ) {ldm_error ("Value of size is to small." );
@@ -1310,7 +1331,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) rec =get_unaligned_be16 (data +0x0C ); num =get_unaligned_be16 (data +0x0E );if ((num <1 ) || (num >4 )) { -ldm_error ("A VBLK claims to have %d parts." , num); +ldm_error ("A VBLK claims to have %d parts." , num);return false; }if (rec >= num) {
@@ -1318,13 +1339,13 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)return false; } - list_for_each (item, frags) { - f = list_entry (item, struct frag, list); +list_for_each (item, frags) { + f = list_entry(item, struct frag, list);if (f->group = group) goto found; } - f =kmalloc (sizeof (*f) + size*num,GFP_KERNEL ); + f =kmalloc (sizeof (*f) + size*num,GFP_KERNEL );if (!f)return false;
@@ -1340,7 +1361,7 @@ found:return false; }if (f->map & (1 << rec)) { -ldm_error ("Duplicate VBLK, part %d." , rec); +ldm_error ("Duplicate VBLK, part %d." , rec); f->map &=0x7F ;/* Mark the group as broken */ return false; }
@@ -1361,14 +1382,14 @@ found:* * Return: none */ -static void ldm_frag_free (struct list_head *list) +static void ldm_frag_free (struct list_head *list) {struct list_head *item, *tmp; -BUG_ON (!list); +BUG_ON (!list); - list_for_each_safe (item, tmp, list) -kfree (list_entry (item ,struct frag ,list )); +list_for_each_safe (item, tmp, list) + kfree(list_entry(item, struct frag, list)); }/**
@@ -1382,23 +1403,23 @@ static void ldm_frag_free (struct list_head *list)* Return: 'true' All the fragments we added successfully * 'false' One or more of the fragments we invalid */ -static bool ldm_frag_commit (struct list_head *frags,struct ldmdb *ldb) +static bool ldm_frag_commit (struct list_head *frags,struct ldmdb *ldb) {struct frag *f;struct list_head *item; -BUG_ON (!frags || !ldb); +BUG_ON (!frags || !ldb); - list_for_each (item, frags) { - f = list_entry (item, struct frag, list); +list_for_each (item, frags) { + f = list_entry(item, struct frag, list);if (f->map !=0xFF ) { -ldm_error ("VBLK group %d is incomplete (0x%02x)." , +ldm_error ("VBLK group %d is incomplete (0x%02x)." , f->group, f->map);return false; } -if (!ldm_ldmdb_add (f->data, f->num*ldb->vm.vblk_size, ldb)) +if (!ldm_ldmdb_add (f->data, f->num*ldb->vm.vblk_size, ldb))return false;/* Already logged */ }return true;
@@ -1435,35 +1456,35 @@ static bool ldm_get_vblks(struct parsed_partitions *state, unsigned long base,for (s = skip; s < finish; s++) {/* For each sector */ data =read_part_sector (state, base +OFF_VMDB + s, §);if (!data) { -ldm_crit ("Disk read failed." ); +ldm_crit ("Disk read failed." ); goto out; }for (v =0 ; v < perbuf; v++, data+=size) {/* For each vblk */ if (MAGIC_VBLK !=get_unaligned_be32 (data)) { -ldm_error ("Expected to find a VBLK." ); +ldm_error ("Expected to find a VBLK." ); goto out; } recs =get_unaligned_be16 (data +0x0E );/* Number of records */ if (recs =1 ) { -if (!ldm_ldmdb_add (data, size, ldb)) +if (!ldm_ldmdb_add (data, size, ldb)) goto out;/* Already logged */ }else if (recs >1 ) { -if (!ldm_frag_add (data, size, &frags)) +if (!ldm_frag_add (data, size, &frags)) goto out;/* Already logged */ }/* else Record is not in use, ignore it. */ } -put_dev_sector (sect); +put_dev_sector (sect); data =NULL ; } - result =ldm_frag_commit (&frags, ldb);/* Failures, already logged */ + result =ldm_frag_commit (&frags, ldb);/* Failures, already logged */ out:if (data) -put_dev_sector (sect); -ldm_frag_free (&frags); +put_dev_sector (sect); +ldm_frag_free (&frags);return result; }
@@ -1476,14 +1497,14 @@ out:* * Return: none */ -static void ldm_free_vblks (struct list_head *lh) +static void ldm_free_vblks (struct list_head *lh) {struct list_head *item, *tmp; -BUG_ON (!lh); +BUG_ON (!lh); - list_for_each_safe (item, tmp, lh) -kfree (list_entry (item ,struct vblk ,list )); +list_for_each_safe (item, tmp, lh) + kfree(list_entry(item, struct vblk, list)); }
@@ -1516,7 +1537,7 @@ int ldm_partition(struct parsed_partitions *state)if (!ldm_validate_partition_table (state))return 0 ; - ldb =kmalloc (sizeof (*ldb),GFP_KERNEL ); + ldb =kmalloc (sizeof (*ldb),GFP_KERNEL );if (!ldb)return -1 ;
@@ -1533,31 +1554,31 @@ int ldm_partition(struct parsed_partitions *state) goto out;/* Already logged */ /* Initialize vblk lists in ldmdb struct */ -INIT_LIST_HEAD (&ldb->v_dgrp); -INIT_LIST_HEAD (&ldb->v_disk); -INIT_LIST_HEAD (&ldb->v_volu); -INIT_LIST_HEAD (&ldb->v_comp); -INIT_LIST_HEAD (&ldb->v_part); +INIT_LIST_HEAD (&ldb->v_dgrp); +INIT_LIST_HEAD (&ldb->v_disk); +INIT_LIST_HEAD (&ldb->v_volu); +INIT_LIST_HEAD (&ldb->v_comp); +INIT_LIST_HEAD (&ldb->v_part);if (!ldm_get_vblks (state, base, ldb)) { -ldm_crit ("Failed to read the VBLKs from the database." ); +ldm_crit ("Failed to read the VBLKs from the database." ); goto cleanup; }/* Finally, create the data partition devices. */ if (ldm_create_data_partitions (state, ldb)) { -ldm_debug ("Parsed LDM database successfully." ); +ldm_debug ("Parsed LDM database successfully." ); result =1 ; }/* else Already logged */ cleanup: -ldm_free_vblks (&ldb->v_dgrp); -ldm_free_vblks (&ldb->v_disk); -ldm_free_vblks (&ldb->v_volu); -ldm_free_vblks (&ldb->v_comp); -ldm_free_vblks (&ldb->v_part); +ldm_free_vblks (&ldb->v_dgrp); +ldm_free_vblks (&ldb->v_disk); +ldm_free_vblks (&ldb->v_volu); +ldm_free_vblks (&ldb->v_comp); +ldm_free_vblks (&ldb->v_part); out: -kfree (ldb); +kfree (ldb);return result; }
Signature · 1 line
2.6.3
cover Documentation-getdelays: Fine-tuning for two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 13:23:34 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Fix a check for container file usage in main() Apply a recommendation from "checkpatch.pl" in main() Less function calls in usage()
Documentation/accounting/getdelays.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 Documentation-getdelays: Fix a check for container file usage in main()
From: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 11:00:54 +0100
The close() function could be called by the main() function even if the passed variable "cfd" was assigned a negative value.
* Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
* Fix the affected condition check.
--- Documentation/accounting/getdelays.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Documentation/accounting/getdelays.c +12 -9
@@ -383,7 +383,7 @@ int main(int argc, char *argv[]) id =get_family_id (nl_sd);if (!id) {fprintf (stderr,"Error getting family id, errno %d\n" , errno); - goto err; + goto close_socket; }PRINTF ("family id %d\n" , id);
@@ -394,13 +394,13 @@ int main(int argc, char *argv[])PRINTF ("Sent register cpumask, retval %d\n" , rc);if (rc <0 ) {fprintf (stderr,"error sending register cpumask\n" ); - goto err; + goto close_socket; } }if (tid && containerset) {fprintf (stderr,"Select either -t or -C, not both\n" ); - goto err; + goto close_socket; }/*
@@ -426,18 +426,18 @@ int main(int argc, char *argv[]) cfd =open (containerpath,O_RDONLY );if (cfd <0 ) {perror ("error opening container file" ); - goto err; + goto close_socket; } rc =send_cmd (nl_sd, id, mypid,CGROUPSTATS_CMD_GET ,CGROUPSTATS_CMD_ATTR_FD , &cfd,sizeof (__u32));if (rc <0 ) {perror ("error sending cgroupstats command" ); - goto err; + goto close_container; } }if (!maskset && !tid && !containerset) {usage (); - goto err; + goto check_container; } do {
@@ -536,11 +536,14 @@ done:if (rc <0 )err (rc,"error sending deregister cpumask\n" ); } -err: +check_container: +if (cfd >=0 ) { +close_container: +close (cfd); + } +close_socket:close (nl_sd);if (fd)close (fd); -if (cfd) -close (cfd);return 0 ; }
Signature · 1 line
2.6.3
Jonathan Corbet
maintainerRe: [PATCH 1/3] Documentation-getdelays: Fix a check for container file usage in main()
Quoted 7 lines · On Thu, 24 Dec 2015 13:34:20 +0100 SF Markus Elfring…
The
close()function could be called by themain()function even if the passed variable "cfd" was assigned a negative value.* Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention.
* Fix the affected condition check.
This seems more easily fixed by simply making the condition > 0. Meanwhile, I'd really not add labels-inside-if-statements as an example in the documentation tree.
Thanks,
jon
Re: Documentation-getdelays: Fix a check for container file usage in main()
Quoted 2 lines
Quoted 2 lines
The
close()function could be called by themain()function even if the passed variable "cfd" was assigned a negative value.
…
Quoted 1 line
This seems more easily fixed by simply making the condition > 0.
How do you think about the reuse of the error predicate "cfd != -1" for the return value from a call of the function "open"?
http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/Documentation/accounting/getdelays.c?id€c75a0f1d81922bf322c0634d1e1a15825a89e6#n425
Quoted 2 lines
Meanwhile, I'd really not add labels-inside-if-statements as an example in the documentation tree.
How are the chances to improve the affected error detection and corresponding exception handling?
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
PATCH 2/3 Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 11:05:32 +0100
The script "checkpatch.pl" pointed out that assignments should usually not be performed within condition checks.
Thus move the assignment for the variable "nl_sd" to a separate statement.
--- Documentation/accounting/getdelays.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/accounting/getdelays.c +2 -1
@@ -375,7 +375,8 @@ int main(int argc, char *argv[]) } } -if ((nl_sd =create_nl_socket (NETLINK_GENERIC )) <0 ) + nl_sd =create_nl_socket (NETLINK_GENERIC ); +if (nl_sd <0 )err (1 ,"error creating Netlink socket\n" );
Signature · 1 line
2.6.3
Jonathan Corbet
maintainerRe: [PATCH 2/3] Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()
Quoted 3 lines · On Thu, 24 Dec 2015 13:36:48 +0100 SF Markus Elfring…
The script "checkpatch.pl" pointed out that assignments should usually not be performed within condition checks.
Thus move the assignment for the variable "nl_sd" to a separate statement.
Fine, applied to the docs tree.
jon
PATCH 3/3 Documentation-getdelays: Less function calls in usage()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 13:10:19 +0100
A single call of the fprintf() function is sufficient for the desired display of the usage information.
--- Documentation/accounting/getdelays.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Documentation/accounting/getdelays.c +6 -6
@@ -74,12 +74,12 @@ char cpumask[100+6*MAX_CPUS];static void usage (void ) {fprintf (stderr,"getdelays [-dilv] [-w logfile] [-r bufsize] " -"[-m cpumask] [-t tgid] [-p pid]\n" ); -fprintf (stderr," -d: print delayacct stats\n" ); -fprintf (stderr," -i: print IO accounting (works only with -p)\n" ); -fprintf (stderr," -l: listen forever\n" ); -fprintf (stderr," -v: debug on\n" ); -fprintf (stderr," -C: container path\n" ); +"[-m cpumask] [-t tgid] [-p pid]\n" +" -d: print delayacct stats\n" +" -i: print IO accounting (works only with -p)\n" +" -l: listen forever\n" +" -v: debug on\n" +" -C: container path\n" ); }/*
Signature · 1 line
2.6.3
Jonathan Corbet
maintainerRe: [PATCH 3/3] Documentation-getdelays: Less function calls in usage()
Quoted 2 lines · On Thu, 24 Dec 2015 13:38:01 +0100 SF Markus Elfring…
A single call of the
fprintf()function is sufficient for the desired display of the usage information.
This seems like churn that doesn't actually fix anything.
jon
Re: Documentation-getdelays: Less function calls in usage()
Quoted 4 lines
Quoted 2 lines
A single call of the
fprintf()function is sufficient for the desired display of the usage information.This seems like churn that doesn't actually fix anything.
Will it matter occasionally to reduce the number of function calls by combining several text fragments into the passing of one longer string parameter?
Does a warning like "quoted string split across lines" need also any further considerations for the Linux coding style specification?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/scripts/checkpatch.pl?id€c75a0f1d81922bf322c0634d1e1a15825a89e6#n4837
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
ACPI-fan: Another source code review around null pointer handling?
In reply to SF Markus ElfringHello,
I have looked at the source file for the ACPI fan driver once more. I would appreciate if a specific implementation detail can be clarified there.
Static source code analysis can point out that functions like the following share an approach for error detection and corresponding exception handling.
* acpi_fan_get_fif
* acpi_fan_get_fps
* fan_get_state_acpi4
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/acpi/fan.c?id€c75a0f1d81922bf322c0634d1e1a15825a89e6#n107
Can it matter eventually to handle a detected null pointer differently from further checks for an attribute like "obj->type" or "obj->package"?
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
sata_mv: Another source code review around exception handling?
In reply to SF Markus ElfringHello,
I have looked at the source file for the Marvell SATA support driver once more. I would appreciate if a specific implementation detail can be clarified there.
Static source code analysis can point out that functions like the following are called by the mv_platform_probe() function.
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/ata/sata_mv.c?id€c75a0f1d81922bf322c0634d1e1a15825a89e6#n4055
* ata_host_alloc_pinfo
http://lxr.free-electrons.com/source/drivers/ata/libata-core.c?v=4.3#L5768
* devm_kzalloc
http://lxr.free-electrons.com/source/include/linux/device.h?v=4.3#L645
The value "-ENOMEM" will be returned if one of these function calls failed. Can it be that any system resources (like memory) are not appropriately released if any calls of this sequence succeeded before the failure?
Is the use of the single jump label "err" also suspicious here?
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: sata_mv: Another source code review around exception handling?
Hello,
Quoted 3 lines · SF Markus Elfring
The value "
-ENOMEM" will be returned if one of these function calls failed. Can it be that any system resources (like memory) are not appropriately released if any calls of this sequence succeeded before the failure?
Most of those are managed resources (devm_, pcim_ and so on) and are released automatically when the driver detaches from the device.
Quoted 1 line
Is the use of the single jump label "err" also suspicious here?
And that exit label deal with resources which aren't managed - some just haven't grown managed variant yet while others don't fit the model too well.
Thanks.
Signature · 1 line
tejun
PATCH 1/1 gpio-ucb1400: Delete an unnecessary variable initialisation in ucb1400_gpio_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 25 Dec 2015 19:36:20 +0100
The variable "err" will eventually be set to an appropriate value from a call of the gpiochip_add() function.
Thus let us omit the explicit initialisation at the beginning.
--- drivers/gpio/gpio-ucb1400.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-ucb1400.c +1 -1
@@ -46,7 +46,7 @@ static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)static int ucb1400_gpio_probe (struct platform_device *dev) {struct ucb1400_gpio *ucb =dev_get_platdata (&dev->dev); -int err =0 ; +int err;if (!(ucb && ucb->gpio_offset)) { err = -EINVAL ;
Signature · 1 line
2.6.3
PATCH 1/1 i2c-core: One function call less in acpi_i2c_space_handler() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 07:30:35 +0100
The kfree() function was called in one case by the acpi_i2c_space_handler() function during error handling even if the passed variable "client" contained a null pointer.
Implementation details could be improved by the adjustment of jump targets.
This issue was detected by using the Coccinelle software.
--- drivers/i2c/i2c-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/i2c-core.c +5 -5
@@ -313,18 +313,18 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command, client =kzalloc (sizeof (*client),GFP_KERNEL );if (!client) { ret =AE_NO_MEMORY ; - goto err; + goto free_ares; }if (!value64 || ares->type !=ACPI_RESOURCE_TYPE_SERIAL_BUS ) { ret =AE_BAD_PARAMETER ; - goto err; + goto free_client; } sb = &ares->data.i2c_serial_bus;if (sb->type !=ACPI_RESOURCE_SERIAL_TYPE_I2C ) { ret =AE_BAD_PARAMETER ; - goto err; + goto free_client; } client->adapter = adapter;
@@ -405,9 +405,9 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command, } gsb->status = status; - - err: +free_client:kfree (client); +free_ares:ACPI_FREE (ares);return ret; }
Signature · 1 line
2.6.3
kbuild test robot
build botRe: [PATCH] i2c-core: One function call less in acpi_i2c_space_handler() after error detection
reproduce:
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system] Hi Markus,
[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on v4.4-rc6 next-20151223]
url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/i2c-core-One-function-call-less-in-acpi_i2c_space_handler-after-error-detection/20151226-143820 base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux i2c/for-next config: x86_64-randconfig-x010-12251849 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/i2c/i2c-core.c: In function 'acpi_i2c_space_handler':
>> drivers/i2c/i2c-core.c:404:3: error: label 'err' used but not defined
goto err;
^vim +/err +404 drivers/i2c/i2c-core.c
17f4a5c4 Wolfram Sang 2014-09-22 398 }
17f4a5c4 Wolfram Sang 2014-09-22 399 break;
17f4a5c4 Wolfram Sang 2014-09-22 400
17f4a5c4 Wolfram Sang 2014-09-22 401 default:
17f4a5c4 Wolfram Sang 2014-09-22 402 pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
17f4a5c4 Wolfram Sang 2014-09-22 403 ret = AE_BAD_PARAMETER;
17f4a5c4 Wolfram Sang 2014-09-22 @404 goto err;
17f4a5c4 Wolfram Sang 2014-09-22 405 }
17f4a5c4 Wolfram Sang 2014-09-22 406
17f4a5c4 Wolfram Sang 2014-09-22 407 gsb->status = status;:::::: The code at line 404 was first introduced by commit
:::::: 17f4a5c47f28de9ea59182f48d07f8c44ee5dcc9 i2c: move acpi code back into the core
:::::: TO: Wolfram Sang <[email protected]>
:::::: CC: Wolfram Sang <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/1 i2c-core: One function call less in acpi_i2c_space_handler() after error detection
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 08:00:52 +0100
The kfree() function was called in one case by the acpi_i2c_space_handler() function during error handling even if the passed variable "client" contained a null pointer.
Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- drivers/i2c/i2c-core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/i2c/i2c-core.c +6 -6
@@ -313,18 +313,18 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command, client =kzalloc (sizeof (*client),GFP_KERNEL );if (!client) { ret =AE_NO_MEMORY ; - goto err; + goto free_ares; }if (!value64 || ares->type !=ACPI_RESOURCE_TYPE_SERIAL_BUS ) { ret =AE_BAD_PARAMETER ; - goto err; + goto free_client; } sb = &ares->data.i2c_serial_bus;if (sb->type !=ACPI_RESOURCE_SERIAL_TYPE_I2C ) { ret =AE_BAD_PARAMETER ; - goto err; + goto free_client; } client->adapter = adapter;
@@ -401,13 +401,13 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,default :pr_info ("protocol(0x%02x) is not supported.\n" , accessor_type); ret =AE_BAD_PARAMETER ; - goto err; + goto free_client; } gsb->status = status; - - err: +free_client:kfree (client); +free_ares:ACPI_FREE (ares);return ret; }
Signature · 1 line
2.6.3
Re: [PATCH v2] i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 3 lines
The
kfree()function was called in one case by theacpi_i2c_space_handler()function during error handling even if the passed variable "client" contained a null pointer.
This is OK. kfree() is known to be NULL-tolerant and we rely on it in various places to keep the code simpler.
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 6 lines
Quoted 3 lines
The
kfree()function was called in one case by theacpi_i2c_space_handler()function during error handling even if the passed variable "client" contained a null pointer.This is OK.
kfree()is known to be NULL-tolerant and we rely on it in various places to keep the code simpler.
I would appreciate if an unnecessary function call can be avoided here so that the affected exception handling can become also a bit more efficient.
Regards,
Markus
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 9 lines · SF Markus Elfring
Quoted 6 lines
Quoted 3 lines
The
kfree()function was called in one case by theacpi_i2c_space_handler()function during error handling even if the passed variable "client" contained a null pointer.This is OK.
kfree()is known to be NULL-tolerant and we rely on it in various places to keep the code simpler.I would appreciate if an unnecessary function call can be avoided here so that the affected exception handling can become also a bit more efficient.
Simpler code is easier to maintain. See your patch, you didn't get it correctly at your first try. Also, this is not a hot path, so I see it as a micro-optimization also adding complexity. I don't favor that.
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 4 lines
Quoted 2 lines
I would appreciate if an unnecessary function call can be avoided here so that the affected exception handling can become also a bit more efficient.
Simpler code is easier to maintain.
There are different opinions available around the desired simplicity.
Quoted 1 line
See your patch, you didn't get it correctly at your first try.
I wonder myself about the circumstances on how my incomplete update suggestion did happen.
Quoted 1 line
Also, this is not a hot path,
I'm curious if approaches around better exception handling can eventually become a "hot topic".
Quoted 1 line
so I see it as a micro-optimization
I can agree to this view for this function implementation.
Quoted 1 line
also adding complexity.
There are the usual software development trade-offs.
Quoted 1 line
I don't favor that.
Thanks for your constructive feedback.
Is an identifier like "free_client" a bit nicer (according to the Linux coding style recommendations) than the short jump label "err" in the discussed use case?
Regards,
Markus
cover IDE-ACPI: Fine-tuning for a function
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 11:04:56 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
One function call less in ide_get_dev_handle() after error detection Delete unnecessary null pointer checks in ide_get_dev_handle() Move an assignment for one variable in ide_get_dev_handle()
drivers/ide/ide-acpi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 IDE-ACPI: One function call less in ide_get_dev_handle() after error detection
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:01:36 +0100
The kfree() function was called in two cases by the ide_get_dev_handle() function during error handling even if the passed variable "dinfo" contained a null pointer.
* Let us return directly if a call of the function "ACPI_HANDLE" or "acpi_get_object_info" failed.
* Delete the explicit initialisation for the variables "dinfo" and "ret" at the beginning then.
This issue was detected by using the Coccinelle software.
--- drivers/ide/ide-acpi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/ide/ide-acpi.c +7 -6
@@ -126,8 +126,8 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,u64 addr;acpi_handle dev_handle;acpi_status status; -struct acpi_device_info *dinfo =NULL ; -int ret = -ENODEV ; +struct acpi_device_info *dinfo; +int ret; bus = pdev->bus->number; devnum =PCI_SLOT (pdev->devfn);
@@ -140,13 +140,13 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, dev_handle =ACPI_HANDLE (dev);if (!dev_handle) {DEBPRINT ("no acpi handle for device\n" ); - goto err; +return -ENODEV ; } status =acpi_get_object_info (dev_handle, &dinfo);if (ACPI_FAILURE (status)) {DEBPRINT ("get_object_info for device failed\n" ); - goto err; +return -ENODEV ; }if (dinfo && (dinfo->valid &ACPI_VALID_ADR ) && dinfo->address = addr) {
@@ -157,13 +157,14 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle," address: %llu, should be %u\n" , dinfo ? (unsigned long long )dinfo->address :-1ULL , (unsigned int)addr); - goto err; + ret = -ENODEV ; + goto free_info; }DEBPRINT ("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n" , devnum, func, (unsigned long long )addr, *handle); ret =0 ; -err: +free_info:kfree (dinfo);return ret; }
Signature · 1 line
2.6.3
PATCH 2/3 IDE-ACPI: Delete unnecessary null pointer checks in ide_get_dev_handle()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:33:48 +0100
The variable "dinfo" will contain an appropropriate pointer after a call of the acpi_get_object_info() function succeeded.
Thus remove two safety checks.
--- drivers/ide/ide-acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ide/ide-acpi.c +2 -2
@@ -148,14 +148,14 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,DEBPRINT ("get_object_info for device failed\n" );return -ENODEV ; } -if (dinfo && (dinfo->valid &ACPI_VALID_ADR ) && +if ((dinfo->valid &ACPI_VALID_ADR ) && dinfo->address = addr) { *pcidevfn = addr; *handle = dev_handle; }else {DEBPRINT ("get_object_info for device has wrong " " address: %llu, should be %u\n" , - dinfo ? (unsigned long long )dinfo->address :-1ULL , + (unsigned long long )dinfo->address, (unsigned int )addr); ret = -ENODEV ; goto free_info;
Signature · 1 line
2.6.3
PATCH 3/3 IDE-ACPI: Move an assignment for one variable in ide_get_dev_handle()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:50:33 +0100
Move the assignment for the variable "addr" to the statement where its value is used after previous function calls succeeded.
--- drivers/ide/ide-acpi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/ide/ide-acpi.c +2 -3
@@ -132,9 +132,6 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle, bus = pdev->bus->number; devnum =PCI_SLOT (pdev->devfn); func =PCI_FUNC (pdev->devfn); -/* ACPI _ADR encoding for PCI bus: */ - addr = (u64)(devnum <<16 | func); -DEBPRINT ("ENTER: pci %02x:%02x.%01x\n" , bus, devnum, func); dev_handle =ACPI_HANDLE (dev);
@@ -148,6 +145,8 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,DEBPRINT ("get_object_info for device failed\n" );return -ENODEV ; } +/* ACPI _ADR encoding for PCI bus: */ + addr = (u64)(devnum <<16 | func);if ((dinfo->valid &ACPI_VALID_ADR ) && dinfo->address = addr) { *pcidevfn = addr;
Signature · 1 line
2.6.3
David Miller
maintainerRe: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
In reply to SF Markus ElfringIDE is in deep freeze maintainence mode.
Therefore patches that perform simplications and cleanups will not be accepted.
Thanks.
Joe Perches
maintainerRe: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
Quoted 4 lines · David Miller
IDE is in deep freeze maintainence mode.
Therefore patches that perform simplications and cleanups will not be accepted.
Maybe there should be something like a README
in drivers/ide that says that.
Maybe the MAINTAINERS entry for "IDE SUBSYSTEM"
should be something like:
S: Frozen - critical fixes only
Re: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
Quoted 6 lines · Joe Perches
Quoted 4 lines · David Miller
IDE is in deep freeze maintainence mode.
Therefore patches that perform simplications and cleanups will not be accepted.
Quoted 7 lines
Maybe there should be something like a README
indrivers/idethat says that.Maybe the
MAINTAINERSentry for "IDE SUBSYSTEM"
should be something like:S: Frozen - critical fixes only
This could be a good idea. Sometimes I hold off on sending patches for things becuse I have the impression that the subsystem doesn't want minor fixes, but I could be wrong, and if one could have a deterministic way to know, it could be better for everyone.
julia
PATCH 1/1 iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 13:53:15 +0100
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" does not need to be checked once more after it was determined that a function call failed.
--- drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/adc/qcom-spmi-vadc.c +9 -8
@@ -424,7 +424,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) prop =vadc_get_channel (vadc,VADC_REF_1250MV ); ret =vadc_do_conversion (vadc, prop, &read_1);if (ret) - goto err; + goto report_failure;/* Try with buffered 625mV channel first */ prop =vadc_get_channel (vadc,VADC_SPARE1 );
@@ -433,11 +433,11 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) ret =vadc_do_conversion (vadc, prop, &read_2);if (ret) - goto err; + goto report_failure;if (read_1 = read_2) { ret = -EINVAL ; - goto err; + goto report_failure; } vadc->graph[VADC_CALIB_ABSOLUTE ].dy = read_1 - read_2;
@@ -447,23 +447,24 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) prop =vadc_get_channel (vadc,VADC_VDD_VADC ); ret =vadc_do_conversion (vadc, prop, &read_1);if (ret) - goto err; + goto report_failure; prop =vadc_get_channel (vadc,VADC_GND_REF ); ret =vadc_do_conversion (vadc, prop, &read_2);if (ret) - goto err; + goto report_failure;if (read_1 = read_2) { ret = -EINVAL ; - goto err; + goto report_failure; } vadc->graph[VADC_CALIB_RATIOMETRIC ].dy = read_1 - read_2; vadc->graph[VADC_CALIB_RATIOMETRIC ].gnd = read_2; -err: -if (ret) +if (ret) { +report_failure:dev_err (vadc->dev,"measure reference points failed\n" ); + }return ret; }
Signature · 1 line
2.6.3
Jonathan Cameron
maintainerRe: [PATCH] iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 13:53:15 +0100This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" does not need to be checked once more after it was determined that a function call failed.
Signed-off-by Markus Elfring <[email protected]>
If we are going to change this, I would prefer to see more useful local error messages and direct returns rather than jumping to a very generic message at the end.
I'm also less than keen on jumping into conditionals as I find it slightly less readable.
We might technically be 'simplifying' the code, but in this case the gain is very minor for a fair bit of code churn...
Thanks,
Jonathan
Quoted 9 lines
--- drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)drivers/iio/adc/qcom-spmi-vadc.c +0
-0
drivers/iio/adc/qcom-spmi-vadc.c static int vadc_measure_ref_points(struct vadc_priv *vadc) · line 427
Quoted 5 lines
drivers/iio/adc/qcom-spmi-vadc.c +1
-1@@ -424,7 +424,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) prop =vadc_get_channel (vadc,VADC_REF_1250MV ); ret =vadc_do_conversion (vadc, prop, &read_1);if (ret) - goto err; + goto report_failure;
In this first case we have already had a report that a conversion failed. I suppose adding that it was during reference point measurement 'might' be useful additional information. I'm not really convinced of it does however... Hence I'd drop reporting it entirely in this function.
drivers/iio/adc/qcom-spmi-vadc.c static int vadc_measure_ref_points(struct vadc_priv *vadc) · line 439
Quoted 12 lines
drivers/iio/adc/qcom-spmi-vadc.c +1
-1/* Try with buffered 625mV channel first */ prop =vadc_get_channel (vadc,VADC_SPARE1 );@@ -433,11 +433,11 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) ret =vadc_do_conversion (vadc, prop, &read_2);if (ret) - goto err; + goto report_failure;if (read_1 = read_2) { ret = -EINVAL ;
I think this one indicates we can't actually read anything at all for some reason... It's the only form of error we won't have effectively already reported so is worthy of some sort of debug message...
Quoted 36 lines
drivers/iio/adc/qcom-spmi-vadc.c +7
-6- goto err; + goto report_failure; } vadc->graph[VADC_CALIB_ABSOLUTE ].dy = read_1 - read_2;@@ -447,23 +447,24 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) prop =vadc_get_channel (vadc,VADC_VDD_VADC ); ret =vadc_do_conversion (vadc, prop, &read_1);if (ret) - goto err; + goto report_failure; prop =vadc_get_channel (vadc,VADC_GND_REF ); ret =vadc_do_conversion (vadc, prop, &read_2);if (ret) - goto err; + goto report_failure;if (read_1 = read_2) { ret = -EINVAL ; - goto err; + goto report_failure; } vadc->graph[VADC_CALIB_RATIOMETRIC ].dy = read_1 - read_2; vadc->graph[VADC_CALIB_RATIOMETRIC ].gnd = read_2; -err: -if (ret) +if (ret) { +report_failure:dev_err (vadc->dev,"measure reference points failed\n" ); + }return ret; }
cover InfiniBand-ocrdma: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 19:30:54 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (6):
One variable and jump label less in ocrdma_alloc_ucontext_pd() Delete unnecessary variable initialisations in 11 functions Returning only value constants in ocrdma_qp_state_change() Return a value from a function call in _ocrdma_modify_qp() directly Returning only value constants in ocrdma_resize_cq() Delete an unnecessary variable in ocrdma_dealloc_pd()
drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 7 +++--- drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 +-- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 39 +++++++++++------------------ 4 files changed, 20 insertions(+), 32 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/6 InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 17:16:00 +0100
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the _ocrdma_alloc_pd() function failed.
* Delete the jump label "err" and the local variable "status" then.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -6
@@ -483,19 +483,15 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,struct ocrdma_ucontext *uctx, struct ib_udata *udata) { - int status = 0; - uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);if (IS_ERR (uctx->cntxt_pd)) { - status =PTR_ERR (uctx->cntxt_pd); uctx->cntxt_pd =NULL ; - goto err; +return PTR_ERR (uctx->cntxt_pd); } uctx->cntxt_pd->uctx = uctx; uctx->cntxt_pd->ibpd.device = &dev->ibdev; -err: -return status; +return 0 ; }static int ocrdma_dealloc_ucontext_pd (struct ocrdma_ucontext *uctx)
Signature · 1 line
2.6.3
kbuild test robot
build botRe: [PATCH 1/6] InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()
url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/InfiniBand-ocrdma-Fine-tuning-for-some-function-implementations/20151227-025304
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system] Hi Markus,
[auto build test WARNING on v4.4-rc6]
[also build test WARNING on next-20151223]
coccinelle warnings: (new ones prefixed by >>)
>> drivers/infiniband/hw/ocrdma/ocrdma_verbs.c:489:9-16: ERROR: PTR_ERR applied after initialization to constant on line 488
vim +489 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
482 static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,
483 struct ocrdma_ucontext *uctx,
484 struct ib_udata *udata)
485 {
486 uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);
487 if (IS_ERR(uctx->cntxt_pd)) {
> 488 uctx->cntxt_pd = NULL; > 489 return PTR_ERR(uctx->cntxt_pd);
490 }
491
492 uctx->cntxt_pd->uctx = uctx;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/6 InfiniBand-ocrdma: One jump label less in ocrdma_alloc_ucontext_pd()
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 22:18:38 +0100
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the _ocrdma_alloc_pd() function failed.
* Reduce the scope for the local variable "status" to one case of an if statement.
* Delete the jump label "err" then.
* Return zero as a constant at the end.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -483,19 +483,16 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,struct ocrdma_ucontext *uctx, struct ib_udata *udata) { - int status = 0; - uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);if (IS_ERR (uctx->cntxt_pd)) { - status =PTR_ERR (uctx->cntxt_pd); +int status =PTR_ERR (uctx->cntxt_pd); uctx->cntxt_pd =NULL ; - goto err; +return status; } uctx->cntxt_pd->uctx = uctx; uctx->cntxt_pd->ibpd.device = &dev->ibdev; -err: -return status; +return 0 ; }static int ocrdma_dealloc_ucontext_pd (struct ocrdma_ucontext *uctx)
Signature · 1 line
2.6.3
Re: [PATCH v2 1/6] InfiniBand-ocrdma: One jump label less in ocrdma_alloc_ucontext_pd()
This patch series looks good to me
Thanks,
Quoted 50 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 22:18:38 +0100This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the
_ocrdma_alloc_pd()function failed.* Reduce the scope for the local variable "status" to one case of an if statement.
* Delete the jump label "err" then.
* Return zero as a constant at the end.
Signed-off-by Markus Elfring <[email protected]>--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3
-7@@ -483,19 +483,16 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,struct ocrdma_ucontext *uctx, struct ib_udata *udata) { - int status = 0; - uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);if (IS_ERR (uctx->cntxt_pd)) { - status =PTR_ERR (uctx->cntxt_pd); +int status =PTR_ERR (uctx->cntxt_pd); uctx->cntxt_pd =NULL ; - goto err; +return status; } uctx->cntxt_pd->uctx = uctx; uctx->cntxt_pd->ibpd.device = &dev->ibdev; -err: -return status; +return 0 ; }static int ocrdma_dealloc_ucontext_pd (struct ocrdma_ucontext *uctx) --2.6.3
PATCH 2/6 InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:18:18 +0100
The variable "status" will be set to an appropriate value a bit later. Thus let us omit the explicit initialisation at the beginning.
--- drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_ah.c +1 -1
@@ -59,7 +59,7 @@ static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah, struct ib_ah_attr *attr, union ib_gid *sgid, int pdid, bool *isvlan, u16 vlan_tag) { - int status = 0; + int status;struct ocrdma_eth_vlan eth;struct ocrdma_grh grh;int eth_sz;
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +2 -2
@@ -1089,7 +1089,7 @@ mbx_err:static int ocrdma_nonemb_mbx_cmd (struct ocrdma_dev *dev,struct ocrdma_mqe *mqe,void *payload_va) { -int status =0 ; +int status;struct ocrdma_mbx_rsp *rsp = payload_va; if ((mqe->hdr.spcl_sge_cnt_emb & OCRDMA_MQE_HDR_EMB_MASK) >>
@@ -2842,7 +2842,7 @@ int ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq)static int ocrdma_mbx_get_dcbx_config (struct ocrdma_dev *dev,u32 ptype,struct ocrdma_dcbx_cfg *dcbxcfg) { -int status =0 ; +int status;dma_addr_t pa;struct ocrdma_mqe cmd;
drivers/infiniband/hw/ocrdma/ocrdma_stats.c +2 -2
@@ -608,7 +608,7 @@ static char *ocrdma_driver_dbg_stats(struct ocrdma_dev *dev)static void ocrdma_update_stats (struct ocrdma_dev *dev) {ulong now = jiffies, secs; -int status =0 ; +int status; struct ocrdma_rdma_stats_resp *rdma_stats (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
@@ -639,7 +639,7 @@ static ssize_t ocrdma_dbgfs_ops_write(struct file *filp, {char tmp_str[32 ];long reset; -int status =0 ; +int status;struct ocrdma_stats *pstats = filp->private_data;struct ocrdma_dev *dev = pstats->dev;
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -6
@@ -419,7 +419,7 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev, struct ib_udata *udata) {struct ocrdma_pd *pd =NULL ; -int status =0 ; +int status; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)
@@ -468,7 +468,7 @@ static inline int is_ucontext_pd(struct ocrdma_ucontext *uctx,static int _ocrdma_dealloc_pd (struct ocrdma_dev *dev,struct ocrdma_pd *pd) { -int status =0 ; +int status;if (dev->pd_mgr->pd_prealloc_valid) status =ocrdma_put_pd_num (dev, pd->id, pd->dpp_enabled);
@@ -592,7 +592,7 @@ map_err:int ocrdma_dealloc_ucontext (struct ib_ucontext *ibctx) { -int status =0 ; +int status;struct ocrdma_mm *mm, *tmp;struct ocrdma_ucontext *uctx =get_ocrdma_ucontext (ibctx);struct ocrdma_dev *dev =get_ocrdma_dev (ibctx->device);
@@ -619,7 +619,7 @@ int ocrdma_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)unsigned long vm_page = vma->vm_pgoff <<PAGE_SHIFT ;u64 unmapped_db = (u64 ) dev->nic_info.unmapped_db;unsigned long len = (vma->vm_end - vma->vm_start); -int status =0 ; +int status;bool found;if (vma->vm_start & (PAGE_SIZE -1 ))
@@ -1282,7 +1282,7 @@ static int ocrdma_copy_qp_uresp(struct ocrdma_qp *qp, struct ib_udata *udata, int dpp_offset, int dpp_credit_lmt, int srq) { - int status = 0; + int status;u64 usr_db;struct ocrdma_create_qp_uresp uresp;struct ocrdma_pd *pd = qp->pd;
@@ -1946,7 +1946,7 @@ int ocrdma_modify_srq(struct ib_srq *ibsrq,enum ib_srq_attr_mask srq_attr_mask, struct ib_udata *udata) { - int status = 0; + int status;struct ocrdma_srq *srq; srq =get_ocrdma_srq (ibsrq);
Signature · 1 line
2.6.3
PATCH 3/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:28:35 +0100
Return zero at the end without using the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +1 -2
@@ -2110,7 +2110,6 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state, enum ib_qp_state *old_ib_state) {unsigned long flags; -int status =0 ;enum ocrdma_qp_state new_state; new_state =get_ocrdma_qp_state (new_ib_state);
@@ -2135,7 +2134,7 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state, qp->state = new_state;spin_unlock_irqrestore (&qp->q_lock, flags); -return status; +return 0 ; }static u32 ocrdma_set_create_qp_mbx_access_flags (struct ocrdma_qp *qp)
Signature · 1 line
2.6.3
PATCH 4/6 InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:40:43 +0100
Return the value from a call of the ocrdma_mbx_modify_qp() function without using an extra assignment for the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1 -3
@@ -1491,9 +1491,7 @@ int _ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,*/ if (status <0 )return status; - status =ocrdma_mbx_modify_qp (dev, qp, attr, attr_mask); - -return status; +return ocrdma_mbx_modify_qp (dev, qp, attr, attr_mask); } int ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
Signature · 1 line
2.6.3
PATCH 5/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:54:47 +0100
Return constant integer values without storing them in the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -1120,15 +1120,12 @@ ctx_err:int ocrdma_resize_cq (struct ib_cq *ibcq,int new_cnt,struct ib_udata *udata) { -int status =0 ;struct ocrdma_cq *cq =get_ocrdma_cq (ibcq); -if (new_cnt <1 || new_cnt > cq->max_hw_cqe) { - status = -EINVAL ; -return status; - } +if (new_cnt <1 || new_cnt > cq->max_hw_cqe) +return -EINVAL ; ibcq->cqe = new_cnt; -return status; +return 0 ; }static void ocrdma_flush_cq (struct ocrdma_cq *cq)
Signature · 1 line
2.6.3
PATCH 6/6 InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 19:09:23 +0100
1. Return zero in one case directly.
2. Return the value from a call of the _ocrdma_dealloc_pd() function without using an extra assignment for the local variable.
3. Remove the variable "status" in this function then.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -4
@@ -750,7 +750,6 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)struct ocrdma_pd *pd =get_ocrdma_pd (ibpd);struct ocrdma_dev *dev =get_ocrdma_dev (ibpd->device);struct ocrdma_ucontext *uctx =NULL ; -int status =0 ;u64 usr_db; uctx = pd->uctx;
@@ -764,11 +763,10 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)if (is_ucontext_pd (uctx, pd)) {ocrdma_release_ucontext_pd (uctx); -return status; +return 0 ; } } - status =_ocrdma_dealloc_pd (dev, pd); -return status; +return _ocrdma_dealloc_pd (dev, pd); } static int ocrdma_alloc_lkey(struct ocrdma_dev *dev, struct ocrdma_mr *mr,
Signature · 1 line
2.6.3
v3 cover InfiniBand-ocrdma: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 18:15:54 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (6):
One variable and jump label less in ocrdma_alloc_ucontext_pd() Delete unnecessary variable initialisations in 11 functions Returning only value constants in ocrdma_qp_state_change() Return a value from a function call in _ocrdma_modify_qp() directly Returning only value constants in ocrdma_resize_cq() Delete an unnecessary variable in ocrdma_dealloc_pd()
---
v3: Rebase proposed changes on the source files for the software
"Linux next-20160114".
v2: Unfortunately, the first update step from this series contained
an inappropriate suggestion.
Thus fix that.
drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 7 +++--- drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 +-- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 39 +++++++++++------------------ 4 files changed, 20 insertions(+), 32 deletions(-)
Signature · 1 line
2.6.3
PATCH v3 1/6 InfiniBand-ocrdma: One jump label less in ocrdma_alloc_ucontext_pd()
From: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 17:17:44 +0100
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the _ocrdma_alloc_pd() function failed.
* Reduce the scope for the local variable "status" to one case of an if statement.
* Delete the jump label "err" then.
* Return zero as a constant at the end.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -483,19 +483,16 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,struct ocrdma_ucontext *uctx, struct ib_udata *udata) { - int status = 0; - uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);if (IS_ERR (uctx->cntxt_pd)) { - status =PTR_ERR (uctx->cntxt_pd); +int status =PTR_ERR (uctx->cntxt_pd); uctx->cntxt_pd =NULL ; - goto err; +return status; } uctx->cntxt_pd->uctx = uctx; uctx->cntxt_pd->ibpd.device = &dev->ibdev; -err: -return status; +return 0 ; }static int ocrdma_dealloc_ucontext_pd (struct ocrdma_ucontext *uctx)
Signature · 1 line
2.6.3
PATCH v3 2/6 InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 17:47:59 +0100
The variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_ah.c +1 -1
@@ -59,7 +59,7 @@ static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah, struct ib_ah_attr *attr, union ib_gid *sgid, int pdid, bool *isvlan, u16 vlan_tag) { - int status = 0; + int status;struct ocrdma_eth_vlan eth;struct ocrdma_grh grh;int eth_sz;
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +2 -2
@@ -1113,7 +1113,7 @@ mbx_err:static int ocrdma_nonemb_mbx_cmd (struct ocrdma_dev *dev,struct ocrdma_mqe *mqe,void *payload_va) { -int status =0 ; +int status;struct ocrdma_mbx_rsp *rsp = payload_va; if ((mqe->hdr.spcl_sge_cnt_emb & OCRDMA_MQE_HDR_EMB_MASK) >>
@@ -2871,7 +2871,7 @@ int ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq)static int ocrdma_mbx_get_dcbx_config (struct ocrdma_dev *dev,u32 ptype,struct ocrdma_dcbx_cfg *dcbxcfg) { -int status =0 ; +int status;dma_addr_t pa;struct ocrdma_mqe cmd;
drivers/infiniband/hw/ocrdma/ocrdma_stats.c +2 -2
@@ -608,7 +608,7 @@ static char *ocrdma_driver_dbg_stats(struct ocrdma_dev *dev)static void ocrdma_update_stats (struct ocrdma_dev *dev) {ulong now = jiffies, secs; -int status =0 ; +int status; struct ocrdma_rdma_stats_resp *rdma_stats (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
@@ -639,7 +639,7 @@ static ssize_t ocrdma_dbgfs_ops_write(struct file *filp, {char tmp_str[32 ];long reset; -int status =0 ; +int status;struct ocrdma_stats *pstats = filp->private_data;struct ocrdma_dev *dev = pstats->dev;
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -6
@@ -419,7 +419,7 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev, struct ib_udata *udata) {struct ocrdma_pd *pd =NULL ; -int status =0 ; +int status; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)
@@ -468,7 +468,7 @@ static inline int is_ucontext_pd(struct ocrdma_ucontext *uctx,static int _ocrdma_dealloc_pd (struct ocrdma_dev *dev,struct ocrdma_pd *pd) { -int status =0 ; +int status;if (dev->pd_mgr->pd_prealloc_valid) status =ocrdma_put_pd_num (dev, pd->id, pd->dpp_enabled);
@@ -593,7 +593,7 @@ map_err:int ocrdma_dealloc_ucontext (struct ib_ucontext *ibctx) { -int status =0 ; +int status;struct ocrdma_mm *mm, *tmp;struct ocrdma_ucontext *uctx =get_ocrdma_ucontext (ibctx);struct ocrdma_dev *dev =get_ocrdma_dev (ibctx->device);
@@ -620,7 +620,7 @@ int ocrdma_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)unsigned long vm_page = vma->vm_pgoff <<PAGE_SHIFT ;u64 unmapped_db = (u64 ) dev->nic_info.unmapped_db;unsigned long len = (vma->vm_end - vma->vm_start); -int status =0 ; +int status;bool found;if (vma->vm_start & (PAGE_SIZE -1 ))
@@ -1283,7 +1283,7 @@ static int ocrdma_copy_qp_uresp(struct ocrdma_qp *qp, struct ib_udata *udata, int dpp_offset, int dpp_credit_lmt, int srq) { - int status = 0; + int status;u64 usr_db;struct ocrdma_create_qp_uresp uresp;struct ocrdma_pd *pd = qp->pd;
@@ -1947,7 +1947,7 @@ int ocrdma_modify_srq(struct ib_srq *ibsrq,enum ib_srq_attr_mask srq_attr_mask, struct ib_udata *udata) { - int status = 0; + int status;struct ocrdma_srq *srq; srq =get_ocrdma_srq (ibsrq);
Signature · 1 line
2.6.3
Re: [PATCH v3 2/6] InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 17:47:59 +0100The variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
What did you try to achieve by this patch?
Quoted 130 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 ++-- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-)drivers/infiniband/hw/ocrdma/ocrdma_ah.c +1
-1@@ -59,7 +59,7 @@ static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah, struct ib_ah_attr *attr, union ib_gid *sgid, int pdid, bool *isvlan, u16 vlan_tag) { - int status = 0; + int status;struct ocrdma_eth_vlan eth;struct ocrdma_grh grh;int eth_sz;drivers/infiniband/hw/ocrdma/ocrdma_hw.c +2
-2@@ -1113,7 +1113,7 @@ mbx_err:static int ocrdma_nonemb_mbx_cmd (struct ocrdma_dev *dev,struct ocrdma_mqe *mqe,void *payload_va) { -int status =0 ; +int status;struct ocrdma_mbx_rsp *rsp = payload_va; if ((mqe->hdr.spcl_sge_cnt_emb & OCRDMA_MQE_HDR_EMB_MASK) >>@@ -2871,7 +2871,7 @@ int ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq)static int ocrdma_mbx_get_dcbx_config (struct ocrdma_dev *dev,u32 ptype,struct ocrdma_dcbx_cfg *dcbxcfg) { -int status =0 ; +int status;dma_addr_t pa;struct ocrdma_mqe cmd;drivers/infiniband/hw/ocrdma/ocrdma_stats.c +2
-2@@ -608,7 +608,7 @@ static char *ocrdma_driver_dbg_stats(struct ocrdma_dev *dev)static void ocrdma_update_stats (struct ocrdma_dev *dev) {ulong now = jiffies, secs; -int status =0 ; +int status; struct ocrdma_rdma_stats_resp *rdma_stats > (struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;@@ -639,7 +639,7 @@ static ssize_t ocrdma_dbgfs_ops_write(struct file *filp, {char tmp_str[32 ];long reset; -int status =0 ; +int status;struct ocrdma_stats *pstats = filp->private_data;struct ocrdma_dev *dev = pstats->dev;drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6
-6@@ -419,7 +419,7 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev, struct ib_udata *udata) {struct ocrdma_pd *pd =NULL ; -int status =0 ; +int status; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)@@ -468,7 +468,7 @@ static inline int is_ucontext_pd(struct ocrdma_ucontext *uctx,static int _ocrdma_dealloc_pd (struct ocrdma_dev *dev,struct ocrdma_pd *pd) { -int status =0 ; +int status;if (dev->pd_mgr->pd_prealloc_valid) status =ocrdma_put_pd_num (dev, pd->id, pd->dpp_enabled);@@ -593,7 +593,7 @@ map_err:int ocrdma_dealloc_ucontext (struct ib_ucontext *ibctx) { -int status =0 ; +int status;struct ocrdma_mm *mm, *tmp;struct ocrdma_ucontext *uctx =get_ocrdma_ucontext (ibctx);struct ocrdma_dev *dev =get_ocrdma_dev (ibctx->device);@@ -620,7 +620,7 @@ int ocrdma_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)unsigned long vm_page = vma->vm_pgoff <<PAGE_SHIFT ;u64 unmapped_db = (u64 ) dev->nic_info.unmapped_db;unsigned long len = (vma->vm_end - vma->vm_start); -int status =0 ; +int status;bool found;if (vma->vm_start & (PAGE_SIZE -1 ))@@ -1283,7 +1283,7 @@ static int ocrdma_copy_qp_uresp(struct ocrdma_qp *qp, struct ib_udata *udata, int dpp_offset, int dpp_credit_lmt, int srq) { - int status = 0; + int status;u64 usr_db;struct ocrdma_create_qp_uresp uresp;struct ocrdma_pd *pd = qp->pd;@@ -1947,7 +1947,7 @@ int ocrdma_modify_srq(struct ib_srq *ibsrq,enum ib_srq_attr_mask srq_attr_mask, struct ib_udata *udata) { - int status = 0; + int status;struct ocrdma_srq *srq; srq =get_ocrdma_srq (ibsrq);Signature · 6 lines
2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 4 lines
Quoted 2 lines
The variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
What did you try to achieve by this patch?
I would like to optimise the affected source files a bit. Would you like to clarify any measurable effects around the implementation detail when various variables will only be initialised immediately before they will be read again?
Regards,
Markus
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 9 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
The variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
What did you try to achieve by this patch?
I would like to optimise the affected source files a bit. Would you like to clarify any measurable effects around the implementation detail when various variables will only be initialised immediately before they will be read again?
Compiler will drop this variable initialization by itself because there are no reads between this variable initialization and write.
I recommend you to take a look on the assembly code and ensure it by yourself.
The proposed change won't affect performance at all.
Quoted 3 lines
Regards,
Markus
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 6 lines
Quoted 3 lines
Would you like to clarify any measurable effects around the implementation detail when various variables will only be initialised immediately before they will be read again?
Compiler will drop this variable initialization by itself because there are no reads between this variable initialization and write.
Which compiler variants would you to take into account for such an use case?
Quoted 2 lines
I recommend you to take a look on the assembly code and ensure it by yourself.
Will any configuration parameters and command arguments become relevant to improve also a corresponding software comparison?
Quoted 1 line
The proposed change won't affect performance at all.
Will unneeded variable assignments be really optimised away by default?
By the way:
Will a small source code reduction matter also a bit here?
Regards,
Markus
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 8 lines · SF Markus Elfring
Quoted 6 lines
Quoted 3 lines
Would you like to clarify any measurable effects around the implementation detail when various variables will only be initialised immediately before they will be read again?
Compiler will drop this variable initialization by itself because there are no reads between this variable initialization and write.
Which compiler variants would you to take into account for such an use case?
GCC supported it before 1999 when I saw it first time. My assumption that in 2016 all compilers are doing such optimization now. I would be glad to hear an example of modern compiler which doesn't support this simple optimization.
Quoted 7 lines
Quoted 4 lines
I recommend you to take a look on the assembly code and ensure it by yourself.
Will any configuration parameters and command arguments become relevant to improve also a corresponding software comparison?
Please suggest us, you are proposing this change, and not me.
Quoted 5 lines
Quoted 3 lines
The proposed change won't affect performance at all.
Will unneeded variable assignments be really optimised away by default?
Yes
Quoted 4 lines
By the way:
Will a small source code reduction matter also a bit here?
If you are interested in saving space of one latter, you need to take into account git database increase, do you?
Quoted 3 lines
Regards,
Markus
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Doing bogus initializations turns off GCC's checking for uninitialized variables so it's a bad habbit.
On the other hand, GCC's checking is not perfect and it sometimes misses bugs so these patches have to be reviewed manually which is maybe too much work to be worthwhile.
regards,
dan carpenter
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
In reply to Leon RomanovskyQuoted 2 lines
GCC supported it before 1999 when I saw it first time. My assumption that in 2016 all compilers are doing such optimization now.
Interesting …
Quoted 2 lines
I would be glad to hear an example of modern compiler which doesn't support this simple optimization.
Would you like to take into account any other source code analysis approaches?
Quoted 4 lines
Quoted 2 lines
Will any configuration parameters and command arguments become relevant to improve also a corresponding software comparison?
Please suggest us, you are proposing this change, and not me.
Which combination of hardware and software versions would you find representative for a corresponding system check?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
The proposed change won't affect performance at all.
Will unneeded variable assignments be really optimised away by default?
Yes
Can it be that this result will depend on special parameters so that data flow analysis and optimisation will be performed in the way you seem to expect?
Quoted 2 lines
If you are interested in saving space of one latter, you need to take into account git database increase, do you?
There are also other aspects to consider:
* Do you insist to initialise a return code at the beginning of every function with a non-void return type?
* Does each bit of extra information can result also in unwanted consequences?
* Is this a specific source code review concern?
* Can this software be improved a bit more only if we dare to talk about potential update candidates?
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: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
On Fri, Jan 15, 2016 at 05:24:50PM +0100, SF Markus Elfring wrote:
Since, you didn't answer to my original question, I will repeat it again. [Q.] What did you try to achieve by this patch?
P.S. This is mailing list for developers and not for patch bots. We are glad to see patches that clean the code, but they need to be meaningful. Your automated patches add noise without any real benefit.
You was suggested to be ignored in MTD mailing list exactly for this type of patches, did you learn anything from that experience?
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 4 lines · Leon Romanovsky
On Fri, Jan 15, 2016 at 05:24:50PM +0100, SF Markus Elfring wrote:
Since, you didn't answer to my original question, I will repeat it again. [Q.] What did you try to achieve by this patch?
Hello Leon,
Have you noticed Dan's reply: "Doing bogus initializations turns off GCC's checking for uninitialized variables so it's a bad habit."
Thanks,
Bart.
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 10 lines · Bart Van Assche
Quoted 4 lines · Leon Romanovsky
On Fri, Jan 15, 2016 at 05:24:50PM +0100, SF Markus Elfring wrote:
Since, you didn't answer to my original question, I will repeat it again. [Q.] What did you try to achieve by this patch?
Hello Leon,
Have you noticed Dan's reply: "Doing bogus initializations turns off GCC's checking for uninitialized variables so it's a bad habit."
Yes and his second part of that message too, that uninitialized checks in GCC work as not as expected [1, 2].
Stackoverflow site has a lot examples of these types of bugs [3]. These examples together with Dan's suggestion requires from all reviewers to be extra cautions when removing variable initialization.
[1] https://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
[2] https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=may%20be%20uninitialized
[3] http://stackoverflow.com/questions/27063678/compiler-not-detecting-obviously-uninitialized-variable
Quoted 8 lines
Thanks,
Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
In reply to Leon RomanovskyQuoted 1 line
[Q.] What did you try to achieve by this patch?
I would appreciate a bit more fine-tuning in the affected source files.
Quoted 1 line
P.S. This is mailing list for developers
Do you try to express any further restrictions?
Quoted 1 line
and not for patch bots.
Would you like to explain such an information a bit more?
Quoted 2 lines
We are glad to see patches that clean the code, but they need to be meaningful.
This is usual.
Quoted 1 line
Your automated patches add noise without any real benefit.
Are you expecting a kind of special proof?
Quoted 2 lines
You was suggested to be ignored in MTD mailing list exactly for this type of patches,
Will the acceptance increase a bit for similar issues over time?
Quoted 1 line
did you learn anything from that experience?
Will another acknowledgement by Selvin Xavier influence any corresponding software improvements?
How do you think about to add any further constructive comments also for the other proposed update steps?
Regards,
Markus
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 3 lines · SF Markus Elfring
Quoted 1 line
[Q.] What did you try to achieve by this patch?
I would appreciate a bit more fine-tuning in the affected source files.
Please provide the numbers BEFORE and AFTER your change which can support that your so called "fine-tuning" worked.
We are waiting to see it together with Tested-By tag to emphasize that your code was tested on real HW and passed minimal sanity checks.
NAK on this patch.
Re: InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
Quoted 2 lines
Please provide the numbers BEFORE and AFTER your change which can support that your so called "fine-tuning" worked.
For which combinations of hardware and software versions would you like to see corresponding results from detailed system checks and special benchmarks?
Quoted 2 lines
We are waiting to see it together with Tested-By tag to emphasize that your code was tested on real HW and passed minimal sanity checks.
Are any other contributors interested to collaborate for such a task?
Quoted 1 line
NAK on this patch.
Thanks for your feedback.
Does it mean that you reject (only) the proposed source code adjustments around the variable "status" in the shown function selection at the moment?
Would you like to clarify the other update steps from this patch series a bit more?
Regards,
Markus
PATCH v3 3/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 17:54:45 +0100
Return zero at the end without using the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +1 -2
@@ -2138,7 +2138,6 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state, enum ib_qp_state *old_ib_state) {unsigned long flags; -int status =0 ;enum ocrdma_qp_state new_state; new_state =get_ocrdma_qp_state (new_ib_state);
@@ -2163,7 +2162,7 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state, qp->state = new_state;spin_unlock_irqrestore (&qp->q_lock, flags); -return status; +return 0 ; }static u32 ocrdma_set_create_qp_mbx_access_flags (struct ocrdma_qp *qp)
Signature · 1 line
2.6.3
PATCH v3 4/6 InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 18:00:23 +0100
Return the value from a call of the ocrdma_mbx_modify_qp() function without using an extra assignment for the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1 -3
@@ -1492,9 +1492,7 @@ int _ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,*/ if (status <0 )return status; - status =ocrdma_mbx_modify_qp (dev, qp, attr, attr_mask); - -return status; +return ocrdma_mbx_modify_qp (dev, qp, attr, attr_mask); } int ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
Signature · 1 line
2.6.3
PATCH v3 5/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 18:04:17 +0100
Return constant integer values without storing them in the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -1121,15 +1121,12 @@ ctx_err:int ocrdma_resize_cq (struct ib_cq *ibcq,int new_cnt,struct ib_udata *udata) { -int status =0 ;struct ocrdma_cq *cq =get_ocrdma_cq (ibcq); -if (new_cnt <1 || new_cnt > cq->max_hw_cqe) { - status = -EINVAL ; -return status; - } +if (new_cnt <1 || new_cnt > cq->max_hw_cqe) +return -EINVAL ; ibcq->cqe = new_cnt; -return status; +return 0 ; }static void ocrdma_flush_cq (struct ocrdma_cq *cq)
Signature · 1 line
2.6.3
PATCH v3 6/6 InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Jan 2016 18:08:08 +0100
1. Return zero in one case directly.
2. Return the value from a call of the _ocrdma_dealloc_pd() function without using an extra assignment for the local variable.
3. Remove the variable "status" in this function then.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -4
@@ -751,7 +751,6 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)struct ocrdma_pd *pd =get_ocrdma_pd (ibpd);struct ocrdma_dev *dev =get_ocrdma_dev (ibpd->device);struct ocrdma_ucontext *uctx =NULL ; -int status =0 ;u64 usr_db; uctx = pd->uctx;
@@ -765,11 +764,10 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)if (is_ucontext_pd (uctx, pd)) {ocrdma_release_ucontext_pd (uctx); -return status; +return 0 ; } } - status =_ocrdma_dealloc_pd (dev, pd); -return status; +return _ocrdma_dealloc_pd (dev, pd); } static int ocrdma_alloc_lkey(struct ocrdma_dev *dev, struct ocrdma_mr *mr,
Signature · 1 line
2.6.3
cover InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
I suggest to return directly instead of using the jump label "err" in two functions (which are working without clean-up there).
Markus Elfring (2):
One jump label less in iser_reg_sig_mr()
One jump label less in isert_reg_sig_mr()
drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 InfiniBand-iSER: One jump label less in iser_reg_sig_mr()
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 11:41:42 +0100
This issue was detected by using the Coccinelle software.
1. Let us return directly if a call of the iser_set_sig_attrs() function failed.
2. Delete the jump label "err" then.
3. Return zero as a constant at the end.
--- drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/iser/iser_memory.c +2 -3
@@ -443,7 +443,7 @@ iser_reg_sig_mr(struct iscsi_iser_task *iser_task,memset (sig_attrs,0 ,sizeof (*sig_attrs)); ret =iser_set_sig_attrs (iser_task->sc, sig_attrs);if (ret) - goto err; +return ret;iser_set_prot_checks (iser_task->sc, &sig_attrs->check_mask);
@@ -475,8 +475,7 @@ iser_reg_sig_mr(struct iscsi_iser_task *iser_task,iser_dbg ("lkey=0x%x rkey=0x%x addr=0x%llx length=%u\n" , sig_reg->sge.lkey, sig_reg->rkey, sig_reg->sge.addr, sig_reg->sge.length); -err: -return ret; +return 0 ; } static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task,
Signature · 1 line
2.6.3
PATCH 2/2 InfiniBand-iSER-target: One jump label less in isert_reg_sig_mr()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 12:54:52 +0100
This issue was detected by using the Coccinelle software.
1. Let us return directly if a call of the function "isert_set_sig_attrs" or "ib_post_send" failed.
2. Delete the jump label "err" then.
3. Return zero as a constant at the end.
--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +3 -4
@@ -2660,7 +2660,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn,memset (&sig_attrs,0 ,sizeof (sig_attrs)); ret =isert_set_sig_attrs (se_cmd, &sig_attrs);if (ret) - goto err; +return ret; sig_attrs.check_mask =isert_set_prot_checks (se_cmd->prot_checks);
@@ -2688,7 +2688,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn, ret =ib_post_send (isert_conn->qp, wr, &bad_wr);if (ret) {isert_err ("fast registration failed, ret:%d\n" , ret); - goto err; +return ret; } fr_desc->ind &= ~ISERT_SIG_KEY_VALID ;
@@ -2706,8 +2706,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn,isert_dbg ("sig_sge: addr: 0x%llx length: %u lkey: %x\n" , rdma_wr->ib_sg[SIG ].addr, rdma_wr->ib_sg[SIG ].length, rdma_wr->ib_sg[SIG ].lkey); -err: -return ret; +return 0 ; } static int
Signature · 1 line
2.6.3
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
Just a note for the future submissions (no need to respin), we are using different subject line: InfiniBand-iSER: --> IB/iser:
Quoted 19 lines
I suggest to return directly instead of using the jump label "err" in two functions (which are working without clean-up there).
Markus Elfring (2):
One jump label less iniser_reg_sig_mr()
One jump label less inisert_reg_sig_mr()drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)Signature · 6 lines
2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementationsI suggest to return directly instead of using the jump label "err" in two functions (which are working without clean-up there).
Markus Elfring (2):
One jump label less iniser_reg_sig_mr()
One jump label less inisert_reg_sig_mr()
Looks good,
Quoted 12 lines
drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)Signature · 6 lines
2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringAlong with Leon's prefix comment:
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementationsI suggest to return directly instead of using the jump label "err" in two functions (which are working without clean-up there).
Quoted 8 lines
Markus Elfring (2):
One jump label less iniser_reg_sig_mr()
One jump label less inisert_reg_sig_mr()drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)
Doug, are you going to pick these two minor patches up, or shall I..?
PATCH 1/1 si2165: Refactoring for si2165_writereg_mask8()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 18:23:57 +0100
This issue was detected by using the Coccinelle software.
1. Let us return directly if a call of the si2165_readreg8() function failed.
2. Reduce the scope for the local variables "ret" and "tmp" to one branch of an if statement.
3. Delete the jump label "err" then.
4. Return the value from a call of the si2165_writereg8() function without using an extra assignment for the variable "ret" at the end.
--- drivers/media/dvb-frontends/si2165.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/media/dvb-frontends/si2165.c +5 -9
@@ -225,22 +225,18 @@ static int si2165_writereg32(struct si2165_state *state, const u16 reg, u32 val)static int si2165_writereg_mask8 (struct si2165_state *state,const u16 reg,u8 val,u8 mask) { -int ret; -u8 tmp; -if (mask !=0xff ) { - ret =si2165_readreg8 (state, reg, &tmp); +u8 tmp; +int ret =si2165_readreg8 (state, reg, &tmp); +if (ret <0 ) - goto err; +return ret; val &= mask; tmp &= ~mask; val |= tmp; } - - ret =si2165_writereg8 (state, reg, val); -err: -return ret; +return si2165_writereg8 (state, reg, val); }#define REG16 (reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
Signature · 1 line
2.6.3
Matthias Schwarzott
maintainerRe: [PATCH] [media] si2165: Refactoring for si2165_writereg_mask8()
Am 27.12.2015 um 18:33 schrieb SF Markus Elfring:
Quoted 11 lines
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 18:23:57 +0100This issue was detected by using the Coccinelle software.
1. Let us return directly if a call of the
si2165_readreg8()function failed.2. Reduce the scope for the local variables "ret" and "tmp" to one branch of an if statement.
Quoted 6 lines
3. Delete the jump label "err" then.
4. Return the value from a call of the
si2165_writereg8()function without using an extra assignment for the variable "ret" at the end.Signed-off-by Markus Elfring <[email protected]>
The patch looks fine.
Regards
Matthias
PS: I am going to switch to regmap, but this change is not yet polished and until now does not touch this function.
PATCH 1/1 bttv: Returning only value constants in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 22:02:21 +0100
Return constant integer values without storing them in the local variable "err" or "rc".
--- drivers/media/pci/bt8xx/bttv-driver.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/media/pci/bt8xx/bttv-driver.c +6 -19
@@ -1726,22 +1726,15 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id id)struct bttv_fh *fh = priv;struct bttv *btv = fh->btv;unsigned int i; -int err =0 ;for (i =0 ; i <BTTV_TVNORMS ; i++)if (id & bttv_tvnorms[i].v4l2_id)break ; -if (i =BTTV_TVNORMS ) { - err = -EINVAL ; - goto err; - } - +if (i =BTTV_TVNORMS ) +return -EINVAL ; btv->std = id;set_tvnorm (btv, i); - -err: - -return err; +return 0 ; }static int bttv_g_std (struct file *file,void *priv,v4l2_std_id *id)
@@ -1770,12 +1763,9 @@ static int bttv_enum_input(struct file *file, void *priv, {struct bttv_fh *fh = priv;struct bttv *btv = fh->btv; -int rc =0 ; -if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { - rc = -EINVAL ; - goto err; - } +if (i->index >= bttv_tvcards[btv->c.type].video_inputs) +return -EINVAL ; i->type =V4L2_INPUT_TYPE_CAMERA ; i->audioset =0 ;
@@ -1799,10 +1789,7 @@ static int bttv_enum_input(struct file *file, void *priv, } i->std =BTTV_NORMS ; - -err: - -return rc; +return 0 ; }static int bttv_g_input (struct file *file,void *priv,unsigned int *i)
Signature · 1 line
2.6.3
PATCH 1/1 tuners: One check less in m88rs6000t_get_rf_strength() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 10:10:34 +0100
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after it was determined that a function call failed.
--- drivers/media/tuners/m88rs6000t.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/media/tuners/m88rs6000t.c +9 -7
@@ -510,27 +510,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength) ret =regmap_read (dev->regmap,0x5A , &val);if (ret) - goto err; + goto report_failure;RF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x5F , &val);if (ret) - goto err; + goto report_failure;IF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x3F , &val);if (ret) - goto err; + goto report_failure;TIA_GC = (val >>4 ) &0x07 ; ret =regmap_read (dev->regmap,0x77 , &val);if (ret) - goto err; + goto report_failure;BB_GC = (val >>4 ) &0x0f ; ret =regmap_read (dev->regmap,0x76 , &val);if (ret) - goto err; + goto report_failure;PGA2_GC = val &0x3f ; PGA2_cri =PGA2_GC >>2 ; PGA2_crf =PGA2_GC &0x03 ;
@@ -562,9 +562,11 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)/* scale value to 0x0000-0xffff */ gain =clamp_val (gain,1000U ,10500U ); *strength = (10500 - gain) *0xffff / (10500 -1000 ); -err: -if (ret) + +if (ret) { +report_failure:dev_dbg (&dev->client->dev,"failed=%d\n" , ret); + }return ret; }
Signature · 1 line
2.6.3
Re: [PATCH] [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 10:10:34 +0100This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after it was determined that a function call failed.
Why not avoid both unnecessary ifs and the enormous ugliness of a label inside an if by making two returns: a return 0 for success and a dev_dbg and return ret for failure?
julia
Quoted 64 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/m88rs6000t.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)drivers/media/tuners/m88rs6000t.c +9
-8@@ -510,27 +510,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength) ret =regmap_read (dev->regmap,0x5A , &val);if (ret) - goto err; + goto report_failure;RF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x5F , &val);if (ret) - goto err; + goto report_failure;IF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x3F , &val);if (ret) - goto err; + goto report_failure;TIA_GC = (val >>4 ) &0x07 ; ret =regmap_read (dev->regmap,0x77 , &val);if (ret) - goto err; + goto report_failure;BB_GC = (val >>4 ) &0x0f ; ret =regmap_read (dev->regmap,0x76 , &val);if (ret) - goto err; + goto report_failure;PGA2_GC = val &0x3f ; PGA2_cri =PGA2_GC >>2 ; PGA2_crf =PGA2_GC &0x03 ;@@ -562,9 +562,11 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)/* scale value to 0x0000-0xffff */ gain =clamp_val (gain,1000U ,10500U ); *strength = (10500 - gain) *0xffff / (10500 -1000 ); -err: -if (ret) + +if (ret) { +report_failure:dev_dbg (&dev->client->dev,"failed=%d\n" , ret); + }return ret; } --2.6.3
--
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: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 5 lines
Quoted 3 lines
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after it was determined that a function call failed.
Why not avoid both unnecessary ifs
I would find such a fine-tuning also nice in principle at more source code places.
Quoted 2 lines
and the enormous ugliness of a label inside an if by making two returns:
a return 0 for success and adev_dbgand return ret for failure?
How should your suggestion finally work when the desired execution success can be determined for such functions only after several other calls succeeded?
Is consistent checking of failure predicates usually required?
Regards,
Markus
Re: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after it was determined that a function call failed.
Why not avoid both unnecessary ifs
Quoted 8 lines
I would find such a fine-tuning also nice in principle at more source code places.
Quoted 2 lines
and the enormous ugliness of a label inside an if by making two returns:
a return 0 for success and adev_dbgand return ret for failure?How should your suggestion finally work when the desired execution success can be determined for such functions only after several other calls succeeded?
Not idea what this means, but immediate return 0 followed by various code for reacting to an error is very common, so it looks like it should be possible here.
julia
cover m88rs6000t: Fine-tuning for some function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:32:20 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Better exception handling in five functions
Refactoring for m88rs6000t_sleep()
drivers/media/tuners/m88rs6000t.c | 165 +++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 82 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 m88rs6000t: Better exception handling in five functions
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:10:30 +0100
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".
--- drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 76 deletions(-)
drivers/media/tuners/m88rs6000t.c +78 -76
@@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* select demod main mclk */ ret =regmap_read (dev->regmap,0x15 , &utmp);if (ret) - goto err; + goto report_failure; reg15 = utmp;if (c->symbol_rate >45010000 ) { reg11 =0x0E ;
@@ -106,7 +106,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe) ret =regmap_read (dev->regmap,0x1D , &utmp);if (ret) - goto err; + goto report_failure; reg1D = utmp; reg1D &= ~0x03 ; reg1D |=N -1 ;
@@ -116,42 +116,42 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* program and recalibrate demod PLL */ ret =regmap_write (dev->regmap,0x05 ,0x40 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x11 ,0x08 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x15 , reg15);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x16 , reg16);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1D , reg1D);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1E , reg1E);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1F , reg1F);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x17 ,0xc1 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x17 ,0x81 );if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); ret =regmap_write (dev->regmap,0x05 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x11 , reg11);if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }
@@ -169,13 +169,13 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, ret =regmap_write (dev->regmap,0x36 , (refDiv -8 ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x31 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2c ,0x02 );if (ret) - goto err; + goto report_failure;if (tuner_freq_MHz >=1550 ) { ucLoDiv1 =2 ;
@@ -227,105 +227,105 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, reg27 = (((ulNDiv1 >>8 ) &0x0F ) + ucLomod1) &0x7F ; ret =regmap_write (dev->regmap,0x27 , reg27);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x28 , (u8)(ulNDiv1 &0xFF ));if (ret) - goto err; + goto report_failure; reg29 = (((ulNDiv2 >>8 ) &0x0F ) + ucLomod2) &0x7f ; ret =regmap_write (dev->regmap,0x29 , reg29);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2a , (u8)(ulNDiv2 &0xFF ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2F ,0xf5 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x30 ,0x05 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x1f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x20 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x3e ,0x11 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x2f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure;usleep_range (2000 ,50000 ); ret =regmap_read (dev->regmap,0x42 , &utmp);if (ret) - goto err; + goto report_failure; reg42 = utmp; ret =regmap_write (dev->regmap,0x3e ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x2f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure;usleep_range (2000 ,50000 ); ret =regmap_read (dev->regmap,0x42 , &utmp);if (ret) - goto err; + goto report_failure; reg42buf = utmp;if (reg42buf < reg42) { ret =regmap_write (dev->regmap,0x3e ,0x11 );if (ret) - goto err; + goto report_failure; }usleep_range (5000 ,50000 ); ret =regmap_read (dev->regmap,0x2d , &utmp);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2d , utmp);if (ret) - goto err; + goto report_failure; ret =regmap_read (dev->regmap,0x2e , &utmp);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2e , utmp);if (ret) - goto err; + goto report_failure; ret =regmap_read (dev->regmap,0x27 , &utmp);if (ret) - goto err; + goto report_failure; reg27 = utmp &0x70 ; ret =regmap_read (dev->regmap,0x83 , &utmp);if (ret) - goto err; + goto report_failure;if (reg27 = (utmp &0x70 )) { ucLoDiv = ucLoDiv1; ulNDiv = ulNDiv1;
@@ -340,7 +340,7 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, refDiv =18 ; ret =regmap_write (dev->regmap,0x36 , (refDiv -8 ));if (ret) - goto err; + goto report_failure; ulNDiv = ((tuner_freq_MHz * ucLoDiv *1000 ) * refDiv / fcry_KHz -1024 ) /2 ; }
@@ -349,16 +349,16 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, + ((ulNDiv >> 8) & 0x0F)) & 0xFF; ret =regmap_write (dev->regmap,0x27 , reg27);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x28 , (u8)(ulNDiv &0xFF ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x29 ,0x80 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x31 ,0x03 );if (ret) - goto err; + goto report_failure;if (ucLoDiv =3 ) utmp =0xCE ;
@@ -366,15 +366,15 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, utmp =0x8A ; ret =regmap_write (dev->regmap,0x3b , utmp);if (ret) - goto err; + goto report_failure; dev->frequency_khz = fcry_KHz * (ulNDiv *2 +1024 ) / refDiv / ucLoDiv;dev_dbg (&dev->client->dev,"actual tune frequency=%d\n" , dev->frequency_khz); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }
@@ -413,21 +413,23 @@ static int m88rs6000t_set_params(struct dvb_frontend *fe) freq_MHz = (realFreq +500 ) /1000 ; ret =m88rs6000t_set_pll_freq (dev, freq_MHz);if (ret) - goto err; + goto report_failure; ret =m88rs6000t_set_bb (dev, c->symbol_rate /1000 , lpf_offset_KHz);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x00 ,0x01 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x00 ,0x00 );if (ret) - goto err; + goto report_failure;/* set demod mlck */ ret =m88rs6000t_set_demod_mclk (fe); -err:if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); + goto report_failure; +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }
@@ -440,16 +442,16 @@ static int m88rs6000t_init(struct dvb_frontend *fe) ret =regmap_update_bits (dev->regmap,0x11 ,0x08 ,0x08 );if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); ret =regmap_update_bits (dev->regmap,0x10 ,0x01 ,0x01 );if (ret) - goto err; + goto report_failure;usleep_range (10000 ,50000 ); ret =regmap_write (dev->regmap,0x07 ,0x7d ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }
@@ -510,27 +512,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength) ret =regmap_read (dev->regmap,0x5A , &val);if (ret) - goto err; + goto report_failure;RF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x5F , &val);if (ret) - goto err; + goto report_failure;IF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x3F , &val);if (ret) - goto err; + goto report_failure;TIA_GC = (val >>4 ) &0x07 ; ret =regmap_read (dev->regmap,0x77 , &val);if (ret) - goto err; + goto report_failure;BB_GC = (val >>4 ) &0x0f ; ret =regmap_read (dev->regmap,0x76 , &val);if (ret) - goto err; + goto report_failure;PGA2_GC = val &0x3f ; PGA2_cri =PGA2_GC >>2 ; PGA2_crf =PGA2_GC &0x03 ;
@@ -562,9 +564,9 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)/* scale value to 0x0000-0xffff */ gain =clamp_val (gain,1000U ,10500U ); *strength = (10500 - gain) *0xffff / (10500 -1000 ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }
Signature · 1 line
2.6.3
Re: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:10:30 +0100This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
This commit message fits with the previous change.
It could be nice to put a blank line before the error handling code. See what is done elsewhere in the file.
julia
Quoted 390 lines
Suggested-by Julia Lawall <[email protected]>Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 76 deletions(-)drivers/media/tuners/m88rs6000t.c +78
-77@@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* select demod main mclk */ ret =regmap_read (dev->regmap,0x15 , &utmp);if (ret) - goto err; + goto report_failure; reg15 = utmp;if (c->symbol_rate >45010000 ) { reg11 =0x0E ;@@ -106,7 +106,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe) ret =regmap_read (dev->regmap,0x1D , &utmp);if (ret) - goto err; + goto report_failure; reg1D = utmp; reg1D &= ~0x03 ; reg1D |=N -1 ;@@ -116,42 +116,42 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* program and recalibrate demod PLL */ ret =regmap_write (dev->regmap,0x05 ,0x40 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x11 ,0x08 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x15 , reg15);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x16 , reg16);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1D , reg1D);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1E , reg1E);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x1F , reg1F);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x17 ,0xc1 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x17 ,0x81 );if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); ret =regmap_write (dev->regmap,0x05 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x11 , reg11);if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }@@ -169,13 +169,13 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, ret =regmap_write (dev->regmap,0x36 , (refDiv -8 ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x31 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2c ,0x02 );if (ret) - goto err; + goto report_failure;if (tuner_freq_MHz >=1550 ) { ucLoDiv1 =2 ;@@ -227,105 +227,105 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, reg27 = (((ulNDiv1 >>8 ) &0x0F ) + ucLomod1) &0x7F ; ret =regmap_write (dev->regmap,0x27 , reg27);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x28 , (u8)(ulNDiv1 &0xFF ));if (ret) - goto err; + goto report_failure; reg29 = (((ulNDiv2 >>8 ) &0x0F ) + ucLomod2) &0x7f ; ret =regmap_write (dev->regmap,0x29 , reg29);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2a , (u8)(ulNDiv2 &0xFF ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2F ,0xf5 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x30 ,0x05 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x1f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x20 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x3e ,0x11 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x2f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure;usleep_range (2000 ,50000 ); ret =regmap_read (dev->regmap,0x42 , &utmp);if (ret) - goto err; + goto report_failure; reg42 = utmp; ret =regmap_write (dev->regmap,0x3e ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x2f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x08 ,0x3f );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x10 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x09 ,0x00 );if (ret) - goto err; + goto report_failure;usleep_range (2000 ,50000 ); ret =regmap_read (dev->regmap,0x42 , &utmp);if (ret) - goto err; + goto report_failure; reg42buf = utmp;if (reg42buf < reg42) { ret =regmap_write (dev->regmap,0x3e ,0x11 );if (ret) - goto err; + goto report_failure; }usleep_range (5000 ,50000 ); ret =regmap_read (dev->regmap,0x2d , &utmp);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2d , utmp);if (ret) - goto err; + goto report_failure; ret =regmap_read (dev->regmap,0x2e , &utmp);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x2e , utmp);if (ret) - goto err; + goto report_failure; ret =regmap_read (dev->regmap,0x27 , &utmp);if (ret) - goto err; + goto report_failure; reg27 = utmp &0x70 ; ret =regmap_read (dev->regmap,0x83 , &utmp);if (ret) - goto err; + goto report_failure;if (reg27 = (utmp &0x70 )) { ucLoDiv = ucLoDiv1; ulNDiv = ulNDiv1;@@ -340,7 +340,7 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, refDiv =18 ; ret =regmap_write (dev->regmap,0x36 , (refDiv -8 ));if (ret) - goto err; + goto report_failure; ulNDiv = ((tuner_freq_MHz * ucLoDiv *1000 ) * refDiv / fcry_KHz -1024 ) /2 ; }@@ -349,16 +349,16 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, + ((ulNDiv >> 8) & 0x0F)) & 0xFF; ret =regmap_write (dev->regmap,0x27 , reg27);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x28 , (u8)(ulNDiv &0xFF ));if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x29 ,0x80 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x31 ,0x03 );if (ret) - goto err; + goto report_failure;if (ucLoDiv =3 ) utmp =0xCE ;@@ -366,15 +366,15 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev, utmp =0x8A ; ret =regmap_write (dev->regmap,0x3b , utmp);if (ret) - goto err; + goto report_failure; dev->frequency_khz = fcry_KHz * (ulNDiv *2 +1024 ) / refDiv / ucLoDiv;dev_dbg (&dev->client->dev,"actual tune frequency=%d\n" , dev->frequency_khz); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }@@ -413,21 +413,23 @@ static int m88rs6000t_set_params(struct dvb_frontend *fe) freq_MHz = (realFreq +500 ) /1000 ; ret =m88rs6000t_set_pll_freq (dev, freq_MHz);if (ret) - goto err; + goto report_failure; ret =m88rs6000t_set_bb (dev, c->symbol_rate /1000 , lpf_offset_KHz);if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x00 ,0x01 );if (ret) - goto err; + goto report_failure; ret =regmap_write (dev->regmap,0x00 ,0x00 );if (ret) - goto err; + goto report_failure;/* set demod mlck */ ret =m88rs6000t_set_demod_mclk (fe); -err:if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); + goto report_failure; +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }@@ -440,16 +442,16 @@ static int m88rs6000t_init(struct dvb_frontend *fe) ret =regmap_update_bits (dev->regmap,0x11 ,0x08 ,0x08 );if (ret) - goto err; + goto report_failure;usleep_range (5000 ,50000 ); ret =regmap_update_bits (dev->regmap,0x10 ,0x01 ,0x01 );if (ret) - goto err; + goto report_failure;usleep_range (10000 ,50000 ); ret =regmap_write (dev->regmap,0x07 ,0x7d ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; }@@ -510,27 +512,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength) ret =regmap_read (dev->regmap,0x5A , &val);if (ret) - goto err; + goto report_failure;RF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x5F , &val);if (ret) - goto err; + goto report_failure;IF_GC = val &0x0f ; ret =regmap_read (dev->regmap,0x3F , &val);if (ret) - goto err; + goto report_failure;TIA_GC = (val >>4 ) &0x07 ; ret =regmap_read (dev->regmap,0x77 , &val);if (ret) - goto err; + goto report_failure;BB_GC = (val >>4 ) &0x0f ; ret =regmap_read (dev->regmap,0x76 , &val);if (ret) - goto err; + goto report_failure;PGA2_GC = val &0x3f ; PGA2_cri =PGA2_GC >>2 ; PGA2_crf =PGA2_GC &0x03 ;@@ -562,9 +564,9 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)/* scale value to 0x0000-0xffff */ gain =clamp_val (gain,1000U ,10500U ); *strength = (10500 - gain) *0xffff / (10500 -1000 ); -err: -if (ret) -dev_dbg (&dev->client->dev,"failed=%d\n" , ret); +return 0 ; +report_failure: +dev_dbg (&dev->client->dev,"failed=%d\n" , ret);return ret; } --2.6.3
Re: [media] m88rs6000t: Better exception handling in five functions
Quoted 5 lines
Quoted 3 lines
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
This commit message fits with the previous change.
Do you prefer an other wording?
Quoted 1 line
It could be nice to put a blank line before the error handling code.
Is it really a coding style requirement to insert another blank line between the suggested placement of the statement "return 0;" and the jump label?
Regards,
Markus
Re: [media] m88rs6000t: Better exception handling in five functions
Quoted 7 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
This commit message fits with the previous change.
Do you prefer an other wording?
Something like "Split the return into success and error cases, to avoid the need for testing before logging."
The concept of the return being duplicated didn't come across in your message.
Quoted 4 lines
Quoted 1 line
It could be nice to put a blank line before the error handling code.
Is it really a coding style requirement to insert another blank line between the suggested placement of the statement "return 0;" and the jump label?
I don't think it is a requirement. But some files do it, and if other functions in this file do it, then it would be nice to do the same.
julia
Re: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions
In reply to SF Markus ElfringEm Mon, 28 Dec 2015 15:38:54 +0100
SF Markus Elfring <[email protected]> escreveu:
Quoted 21 lines
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:10:30 +0100This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".Suggested-by Julia Lawall <[email protected]>Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 76 deletions(-)drivers/media/tuners/m88rs6000t.c +0
-0
drivers/media/tuners/m88rs6000t.c static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe) · line 47
Quoted 5 lines
drivers/media/tuners/m88rs6000t.c +1
-1@@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* select demod main mclk */ ret =regmap_read (dev->regmap,0x15 , &utmp);if (ret) - goto err; + goto report_failure;
Why to be so verbose? Calling it as "err" is enough, and it means less code to type if we need to add another goto.
Regards,
Mauro
Re: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions
Quoted 13 lines
Quoted 13 lines
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".Suggested-by Julia Lawall <[email protected]>Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 76 deletions(-)
Quoted 12 lines
drivers/media/tuners/m88rs6000t.c static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe) · line 47
Quoted 10 lines
drivers/media/tuners/m88rs6000t.c +1
-1@@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)/* select demod main mclk */ ret =regmap_read (dev->regmap,0x15 , &utmp);if (ret) - goto err; + goto report_failure;Why to be so verbose?
Does the document "CodingStyle" give an indication in the section "Chapter 7:
Centralized exiting of functions"?
Quoted 1 line
Calling it as "err" is enough,
It seems that some short identifiers are popular during software development.
Quoted 1 line
and it means less code to type if we need to add another goto.
Would you like to increase the usage of jump labels which will contain only a single character?
Regards,
Markus
PATCH 2/2 tuners: Refactoring for m88rs6000t_sleep()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:20:45 +0100
This issue was detected by using the Coccinelle software.
1. Let us return directly if a call of the regmap_write() function failed.
2. Delete the jump label "err" then.
3. Return zero as a constant at the end.
--- drivers/media/tuners/m88rs6000t.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/tuners/m88rs6000t.c +5 -6
@@ -463,13 +463,12 @@ static int m88rs6000t_sleep(struct dvb_frontend *fe)dev_dbg (&dev->client->dev,"%s:\n" , __func__); ret =regmap_write (dev->regmap,0x07 ,0x6d ); -if (ret) - goto err; -usleep_range (5000 ,10000 ); -err: -if (ret) +if (ret) {dev_dbg (&dev->client->dev,"failed=%d\n" , ret); -return ret; +return ret; + } +usleep_range (5000 ,10000 ); +return 0 ; }static int m88rs6000t_get_frequency (struct dvb_frontend *fe,u32 *frequency)
Signature · 1 line
2.6.3
cover r820t: Fine-tuning for generic_set_freq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 17:18:34 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an unnecessary variable initialisation
Better exception handling
drivers/media/tuners/r820t.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 r820t: Delete an unnecessary variable initialisation in generic_set_freq()
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 16:36:44 +0100
The variable "rc" will be set to an appropriate value from a call of the r820t_set_tv_standard() function.
Thus let us omit the explicit initialisation at the beginning.
--- drivers/media/tuners/r820t.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/r820t.c +1 -1
@@ -1295,7 +1295,7 @@ static int generic_set_freq(struct dvb_frontend *fe, v4l2_std_id std, u32 delsys) {struct r820t_priv *priv = fe->tuner_priv; -int rc = -EINVAL ; +int rc;u32 lo_freq; tuner_dbg("should set frequency to %d kHz, bw %d MHz\n",
Signature · 1 line
2.6.3
PATCH 2/2 r820t: Better exception handling in generic_set_freq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 17:13:02 +0100
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "rc" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".
The error logging is performed in a separate section at the end now.
--- drivers/media/tuners/r820t.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/tuners/r820t.c +7 -9
@@ -1303,7 +1303,7 @@ static int generic_set_freq(struct dvb_frontend *fe, rc =r820t_set_tv_standard (priv, bw, type, std, delsys);if (rc <0 ) - goto err; + goto report_failure;if ((type =V4L2_TUNER_ANALOG_TV ) && (std =V4L2_STD_SECAM_LC )) lo_freq = freq - priv->int_freq;
@@ -1312,23 +1312,21 @@ static int generic_set_freq(struct dvb_frontend *fe, rc =r820t_set_mux (priv, lo_freq);if (rc <0 ) - goto err; + goto report_failure; rc =r820t_set_pll (priv, type, lo_freq);if (rc <0 || !priv->has_lock) - goto err; + goto report_failure; rc =r820t_sysfreq_sel (priv, freq, type, std, delsys);if (rc <0 ) - goto err; + goto report_failure;tuner_dbg ("%s: PLL locked on frequency %d Hz, gain=%d\n" , __func__, freq,r820t_read_gain (priv)); - -err: - -if (rc <0 ) -tuner_dbg ("%s: failed=%d\n" , __func__, rc); +return 0 ; +report_failure: +tuner_dbg ("%s: failed=%d\n" , __func__, rc);return rc; }
Signature · 1 line
2.6.3
Re: [PATCH 2/2] [media] r820t: Better exception handling in generic_set_freq()
Em Mon, 28 Dec 2015 17:32:22 +0100
SF Markus Elfring <[email protected]> escreveu:
Quoted 22 lines
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 17:13:02 +0100This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "rc" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".The error logging is performed in a separate section at the end now.
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/r820t.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)drivers/media/tuners/r820t.c +0
-0
drivers/media/tuners/r820t.c static int generic_set_freq(struct dvb_frontend *fe, · line 1306
Quoted 5 lines
drivers/media/tuners/r820t.c +1
-1@@ -1303,7 +1303,7 @@ static int generic_set_freq(struct dvb_frontend *fe, rc =r820t_set_tv_standard (priv, bw, type, std, delsys);if (rc <0 ) - goto err; + goto report_failure;
Same thing as my previous comment: just "err" please.
Same applies to other patches you sent with similar hunks.
Quoted 33 lines
drivers/media/tuners/r820t.c +6
-8if ((type =V4L2_TUNER_ANALOG_TV ) && (std =V4L2_STD_SECAM_LC )) lo_freq = freq - priv->int_freq;@@ -1312,23 +1312,21 @@ static int generic_set_freq(struct dvb_frontend *fe, rc =r820t_set_mux (priv, lo_freq);if (rc <0 ) - goto err; + goto report_failure; rc =r820t_set_pll (priv, type, lo_freq);if (rc <0 || !priv->has_lock) - goto err; + goto report_failure; rc =r820t_sysfreq_sel (priv, freq, type, std, delsys);if (rc <0 ) - goto err; + goto report_failure;tuner_dbg ("%s: PLL locked on frequency %d Hz, gain=%d\n" , __func__, freq,r820t_read_gain (priv)); - -err: - -if (rc <0 ) -tuner_dbg ("%s: failed=%d\n" , __func__, rc); +return 0 ; +report_failure: +tuner_dbg ("%s: failed=%d\n" , __func__, rc);return rc; }
PATCH 1/1 xc5000: Faster result reporting in xc_load_fw_and_init_tuner()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 20:10:30 +0100
This issue was detected by using the Coccinelle software.
Split the previous if statement at the end so that each final log statement will eventually be performed by a direct jump to these labels.
* report_failure
* report_success
A check repetition can be excluded for the variable "ret" at the end then.
Apply also two recommendations from the script "checkpatch.pl".
--- drivers/media/tuners/xc5000.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/tuners/xc5000.c +7 -9
@@ -1166,7 +1166,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) ret =xc5000_fwupload (fe, desired_fw, fw);if (ret !=0 ) - goto err; + goto report_failure;msleep (20 );
@@ -1229,18 +1229,16 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)/* Default to "CABLE" mode */ ret =xc_write_reg (priv,XREG_SIGNALSOURCE ,XC_RF_MODE_CABLE );if (!ret) -break ; + goto report_success;printk (KERN_ERR "xc5000: can't set to cable mode." ); } -err: -if (!ret) -printk (KERN_INFO "xc5000: Firmware %s loaded and running.\n" , - desired_fw->name); -else -printk (KERN_CONT " - too many retries. Giving up\n" ); - +report_failure: +pr_cont (" - too many retries. Giving up\n" );return ret; +report_success: +pr_info ("xc5000: Firmware %s loaded and running.\n" , desired_fw->name); +return 0 ; }static void xc5000_do_timer_sleep (struct work_struct *timer_sleep)
Signature · 1 line
2.6.3
Re: [PATCH] [media] xc5000: Faster result reporting in xc_load_fw_and_init_tuner()
Em Mon, 28 Dec 2015 20:20:27 +0100
SF Markus Elfring <[email protected]> escreveu:
Quoted 34 lines
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 20:10:30 +0100This issue was detected by using the Coccinelle software.
Split the previous if statement at the end so that each final log statement will eventually be performed by a direct jump to these labels.
*report_failure
*report_successA check repetition can be excluded for the variable "ret" at the end then.
Apply also two recommendations from the script "checkpatch.pl".
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/xc5000.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)drivers/media/tuners/xc5000.c +1
-1@@ -1166,7 +1166,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) ret =xc5000_fwupload (fe, desired_fw, fw);if (ret !=0 ) - goto err; + goto report_failure;msleep (20 );
drivers/media/tuners/xc5000.c static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) · line 1233
Quoted 6 lines
drivers/media/tuners/xc5000.c +1
-1@@ -1229,18 +1229,16 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)/* Default to "CABLE" mode */ ret =xc_write_reg (priv,XREG_SIGNALSOURCE ,XC_RF_MODE_CABLE );if (!ret) -break ; + goto report_success;printk (KERN_ERR "xc5000: can't set to cable mode." );
It sounds worth to avoid adding a goto here.
Quoted 18 lines
drivers/media/tuners/xc5000.c +5
-7} -err: -if (!ret) -printk (KERN_INFO "xc5000: Firmware %s loaded and running.\n" , - desired_fw->name); -else -printk (KERN_CONT " - too many retries. Giving up\n" ); - +report_failure: +pr_cont (" - too many retries. Giving up\n" );return ret; +report_success: +pr_info ("xc5000: Firmware %s loaded and running.\n" , desired_fw->name); +return 0 ; }static void xc5000_do_timer_sleep (struct work_struct *timer_sleep)
Re: [PATCH] [media] xc5000: Faster result reporting in xc_load_fw_and_init_tuner()
Quoted 30 lines
Quoted 30 lines
This issue was detected by using the Coccinelle software.
Split the previous if statement at the end so that each final log statement will eventually be performed by a direct jump to these labels.
*report_failure
*report_successA check repetition can be excluded for the variable "ret" at the end then.
Apply also two recommendations from the script "checkpatch.pl".
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/xc5000.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)drivers/media/tuners/xc5000.c +1
-1@@ -1166,7 +1166,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) ret =xc5000_fwupload (fe, desired_fw, fw);if (ret !=0 ) - goto err; + goto report_failure;msleep (20 );
Quoted 9 lines
drivers/media/tuners/xc5000.c static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) · line 1233
Quoted 7 lines
drivers/media/tuners/xc5000.c +1
-1@@ -1229,18 +1229,16 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)/* Default to "CABLE" mode */ ret =xc_write_reg (priv,XREG_SIGNALSOURCE ,XC_RF_MODE_CABLE );if (!ret) -break ; + goto report_success;printk (KERN_ERR "xc5000: can't set to cable mode." );It sounds worth to avoid adding a goto here.
Are you interested in a bit of software optimisation for the implementation of the function "xc_load_fw_and_init_tuner"?
Quoted 17 lines
Quoted 17 lines
drivers/media/tuners/xc5000.c +5
-7} -err: -if (!ret) -printk (KERN_INFO "xc5000: Firmware %s loaded and running.\n" , - desired_fw->name); -else -printk (KERN_CONT " - too many retries. Giving up\n" ); - +report_failure: +pr_cont (" - too many retries. Giving up\n" );return ret; +report_success: +pr_info ("xc5000: Firmware %s loaded and running.\n" , desired_fw->name); +return 0 ; }
Quoted 1 line
drivers/media/tuners/xc5000.c static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) · line 1244
Quoted 1 line
drivers/media/tuners/xc5000.c +0
-0static void xc5000_do_timer_sleep (struct work_struct *timer_sleep)
Is the proposed source code restructuring interesting?
Regards,
Markus
Re: [PATCH] [media] xc5000: Faster result reporting in xc_load_fw_and_init_tuner()
Quoted 2 lines
Are you interested in a bit of software optimisation for the implementation of the function "
xc_load_fw_and_init_tuner"?
To be clear, absolutely none of the code in question is performance sensitive (i.e. saving a couple of extra CPU cycles has no value in this case). Hence given that I'm assuming you have no intention to actually test any of these patches with a real device I would recommend you do the bare minimum to prevent Coccinelle from complaining and not restructure any of the core business logic unless you plan to also do actual testing.
Thanks,
Devin
Signature · 2 lines
Devin J. Heitmueller - Kernel Labs http://www.kernellabs.com
PATCH 1/1 airspy: Better exception handling in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 22:10:28 +0100
This issue was detected by using the Coccinelle software.
Move the jump label directly before the desired log statement so that the variable "ret" will not be checked once more after a function call.
Use the identifier "report_failure" instead of "err".
The error logging is performed in a separate section at the end now.
--- drivers/media/usb/airspy/airspy.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/media/usb/airspy/airspy.c +10 -12
@@ -889,18 +889,17 @@ static int airspy_set_lna_gain(struct airspy *s) ret =airspy_ctrl_msg (s,CMD_SET_LNA_AGC ,0 , s->lna_gain_auto->val, &u8tmp,1 );if (ret) - goto err; + goto report_failure;if (s->lna_gain_auto->val = false) { ret =airspy_ctrl_msg (s,CMD_SET_LNA_GAIN ,0 , s->lna_gain->val, &u8tmp,1 );if (ret) - goto err; + goto report_failure; } -err: -if (ret) -dev_dbg (s->dev,"failed=%d\n" , ret); - +return 0 ; +report_failure: +dev_dbg (s->dev,"failed=%d\n" , ret);return ret; }
@@ -916,18 +915,17 @@ static int airspy_set_mixer_gain(struct airspy *s) ret =airspy_ctrl_msg (s,CMD_SET_MIXER_AGC ,0 , s->mixer_gain_auto->val, &u8tmp,1 );if (ret) - goto err; + goto report_failure;if (s->mixer_gain_auto->val = false) { ret =airspy_ctrl_msg (s,CMD_SET_MIXER_GAIN ,0 , s->mixer_gain->val, &u8tmp,1 );if (ret) - goto err; + goto report_failure; } -err: -if (ret) -dev_dbg (s->dev,"failed=%d\n" , ret); - +return 0 ; +report_failure: +dev_dbg (s->dev,"failed=%d\n" , ret);return ret; }
Signature · 1 line
2.6.3
PATCH 1/1 au0828: Refactoring for start_urb_transfer()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 22:52:48 +0100
This issue was detected by using the Coccinelle software.
1. Let us return directly if a buffer allocation failed.
2. Delete the jump label "err" then.
3. Drop the explicit initialisation for the variable "ret" at the beginning.
4. Return zero as a constant at the end.
--- drivers/media/usb/au0828/au0828-dvb.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/media/usb/au0828/au0828-dvb.c +5 -7
@@ -181,7 +181,7 @@ static int stop_urb_transfer(struct au0828_dev *dev)static int start_urb_transfer (struct au0828_dev *dev) {struct urb *purb; -int i, ret = -ENOMEM ; +int i, ret;dprintk (2 ,"%s()\n" , __func__);
@@ -194,7 +194,7 @@ static int start_urb_transfer(struct au0828_dev *dev) dev->urbs[i] =usb_alloc_urb (0 ,GFP_KERNEL );if (!dev->urbs[i]) - goto err; +return -ENOMEM ; purb = dev->urbs[i];
@@ -207,9 +207,10 @@ static int start_urb_transfer(struct au0828_dev *dev)if (!purb->transfer_buffer) {usb_free_urb (purb); dev->urbs[i] =NULL ; + ret = -ENOMEM ;pr_err ("%s: failed big buffer allocation, err = %d\n" , __func__, ret); - goto err; +return ret; } purb->status = -EINPROGRESS ;
@@ -235,10 +236,7 @@ static int start_urb_transfer(struct au0828_dev *dev) } dev->urb_streaming = true; - ret =0 ; - -err: -return ret; +return 0 ; }static void au0828_start_transport (struct au0828_dev *dev)
Signature · 1 line
2.6.3
PATCH 1/1 hdpvr: Refactoring for hdpvr_read()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 11:02:43 +0100
Let us return directly if the element "status" of the variable "buf" indicates "BUFSTAT_READY".
A check repetition can be excluded for the variable "ret" at the end then.
--- drivers/media/usb/hdpvr/hdpvr-video.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/usb/hdpvr/hdpvr-video.c +2 -4
@@ -462,10 +462,8 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count, }if (wait_event_interruptible (dev->wait_data, - buf->status =BUFSTAT_READY )) { - ret = -ERESTARTSYS ; - goto err; - } + buf->status =BUFSTAT_READY )) +return -ERESTARTSYS ; }if (buf->status !=BUFSTAT_READY )
Signature · 1 line
2.6.3
PATCH 1/1 msi2500: Delete an unnecessary check in msi2500_set_usb_adc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 12:32:41 +0100
This issue was detected by using the Coccinelle software.
Return the value from a call of the msi2500_ctrl_msg() function without using an extra check for the variable "ret" at the end.
--- drivers/media/usb/msi2500/msi2500.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/usb/msi2500/msi2500.c +0 -2
@@ -839,8 +839,6 @@ static int msi2500_set_usb_adc(struct msi2500_dev *dev) goto err; ret =msi2500_ctrl_msg (dev,CMD_WREG , reg3); -if (ret) - goto err; err:return ret; }
Signature · 1 line
2.6.3
PATCH 1/1 mfd-dm355evm_msp: One function call less in add_child() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 13:56:42 +0100
The platform_device_put() function was called in one case by the add_child() function during error handling even if the passed variable "pdev" contained a null pointer.
Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mfd/dm355evm_msp.c +10 -11
@@ -202,7 +202,7 @@ static struct device *add_child(struct i2c_client *client, const char *name,if (!pdev) {dev_dbg (&client->dev,"can't alloc dev\n" ); status = -ENOMEM ; - goto err; + goto report_failure; }device_init_wakeup (&pdev->dev, can_wakeup);
@@ -212,7 +212,7 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_data (pdev, pdata, pdata_len);if (status <0 ) {dev_dbg (&pdev->dev,"can't add platform_data\n" ); - goto err; + goto put_device; } }
@@ -225,19 +225,18 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_resources (pdev, &r,1 );if (status <0 ) {dev_dbg (&pdev->dev,"can't add irq\n" ); - goto err; + goto put_device; } } status =platform_device_add (pdev); - -err: -if (status <0 ) { -platform_device_put (pdev); -dev_err (&client->dev,"can't add %s dev\n" , name); -return ERR_PTR (status); - } -return &pdev->dev; +if (!status) +return &pdev->dev; +put_device: +platform_device_put (pdev); +report_failure: +dev_err (&client->dev,"can't add %s dev\n" , name); +return ERR_PTR (status); }static int add_children (struct i2c_client *client)
Signature · 1 line
2.6.3
Re: [PATCH] mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 13:56:42 +0100The
platform_device_put()function was called in one case by theadd_child()function during error handling even if the passed variable "pdev" contained a null pointer.Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
Same comments as before.
Quoted 50 lines
drivers/mfd/dm355evm_msp.c +10
-11@@ -202,7 +202,7 @@ static struct device *add_child(struct i2c_client *client, const char *name,if (!pdev) {dev_dbg (&client->dev,"can't alloc dev\n" ); status = -ENOMEM ; - goto err; + goto report_failure; }device_init_wakeup (&pdev->dev, can_wakeup);@@ -212,7 +212,7 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_data (pdev, pdata, pdata_len);if (status <0 ) {dev_dbg (&pdev->dev,"can't add platform_data\n" ); - goto err; + goto put_device; } }@@ -225,19 +225,18 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_resources (pdev, &r,1 );if (status <0 ) {dev_dbg (&pdev->dev,"can't add irq\n" ); - goto err; + goto put_device; } } status =platform_device_add (pdev); - -err: -if (status <0 ) { -platform_device_put (pdev); -dev_err (&client->dev,"can't add %s dev\n" , name); -return ERR_PTR (status); - } -return &pdev->dev; +if (!status) +return &pdev->dev; +put_device: +platform_device_put (pdev); +report_failure: +dev_err (&client->dev,"can't add %s dev\n" , name); +return ERR_PTR (status); }static int add_children (struct i2c_client *client)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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: mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 7 lines
Quoted 7 lines
The
platform_device_put()function was called in one case by theadd_child()function during error handling even if the passed variable "pdev" contained a null pointer.Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
Quoted 8 lines
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)Same comments as before.
To which comments do you refer here?
Are you interested in any further clarification of open issues?
Regards,
Markus
Re: mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 14 lines · SF Markus Elfring
Quoted 14 lines
Quoted 13 lines
The
platform_device_put()function was called in one case by theadd_child()function during error handling even if the passed variable "pdev" contained a null pointer.Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
Quoted 5 lines
Quoted 1 line
Same comments as before.
To which comments do you refer here?
Are you interested in any further clarification of open issues?
I'm sure you'll work it out. ;)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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: mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 1 line
I'm sure you'll work it out. ;)
Do you want any changes for this suggestion around the software component "dm355evm_msp"?
Regards,
Markus
Re: mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 4 lines · SF Markus Elfring
Quoted 1 line
I'm sure you'll work it out. ;)
Do you want any changes for this suggestion around the software component "
dm355evm_msp"?
There we go.
I have been more explicit as there was obviously some confusion.
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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] mfd-dm355evm_msp: One function call less in add_child() after error detection
In reply to SF Markus ElfringThe subject format is wrong and the summary itself isn't very informative.
Quoted 2 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 13:56:42 +0100
This patch format is wrong, please consider using git format-patch and git send-email.
Quoted 19 lines
The
platform_device_put()function was called in one case by theadd_child()function during error handling even if the passed variable "pdev" contained a null pointer.Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/mfd/dm355evm_msp.c +0
-0
drivers/mfd/dm355evm_msp.c static struct device *add_child(struct i2c_client *client, const char *name, · line 203
Quoted 2 lines
drivers/mfd/dm355evm_msp.c +0
-0@@ -202,7 +202,7 @@ static struct device *add_child(struct i2c_client *client, const char *name,if (!pdev) {dev_dbg (&client->dev,"can't alloc dev\n" );
Make this dev_err().
drivers/mfd/dm355evm_msp.c static struct device *add_child(struct i2c_client *client, const char *name, · line 205
Quoted 3 lines
drivers/mfd/dm355evm_msp.c +1
-1status = -ENOMEM ; - goto err; + goto report_failure;
Return here.
Quoted 21 lines
drivers/mfd/dm355evm_msp.c +2
-2}device_init_wakeup (&pdev->dev, can_wakeup);@@ -212,7 +212,7 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_data (pdev, pdata, pdata_len);if (status <0 ) {dev_dbg (&pdev->dev,"can't add platform_data\n" ); - goto err; + goto put_device; } }@@ -225,19 +225,18 @@ static struct device *add_child(struct i2c_client *client, const char *name, status =platform_device_add_resources (pdev, &r,1 );if (status <0 ) {dev_dbg (&pdev->dev,"can't add irq\n" ); - goto err; + goto put_device; } }
drivers/mfd/dm355evm_msp.c static struct device *add_child(struct i2c_client *client, const char *name, · line 233
Quoted 10 lines
drivers/mfd/dm355evm_msp.c +1
-8status =platform_device_add (pdev); - -err: -if (status <0 ) { -platform_device_put (pdev); -dev_err (&client->dev,"can't add %s dev\n" , name); -return ERR_PTR (status); - } -return &pdev->dev; +if (!status)
Be more consistent here.
Reverse the condition and return an instead, as you do above.
drivers/mfd/dm355evm_msp.c static struct device *add_child(struct i2c_client *client, const char *name, · line 238
Quoted 5 lines
drivers/mfd/dm355evm_msp.c +5
-0+return &pdev->dev; +put_device: +platform_device_put (pdev); +report_failure: +dev_err (&client->dev,"can't add %s dev\n" , name);
This isn't a very friendly error message. Better to convert the dev_dbg() calls to dev_err() and tell the user what the problem was.
Quoted 4 lines
drivers/mfd/dm355evm_msp.c +1
-0+return ERR_PTR (status); }static int add_children (struct i2c_client *client)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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: mfd-dm355evm_msp: One function call less in add_child() after error detection
Quoted 1 line
The subject format is wrong
Which format do you expect?
Quoted 1 line
and the summary itself isn't very informative.
Which wording do you find more useful?
Quoted 4 lines
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 13:56:42 +0100This patch format is wrong,
You might find the use of additional fields in the message body unusual. I have got an other impression from the canonical patch format.
Quoted 1 line
please consider using
git format-patchandgit send-email.
Thanks for your suggestion.
Quoted 6 lines
Quoted 6 lines
The
platform_device_put()function was called in one case by theadd_child()function during error handling even if the passed variable "pdev" contained a null pointer.Implementation details could be improved by the adjustment of jump targets according to the Linux coding style convention.
I am going to integrate the source code changes that you requested a bit later.
Quoted 5 lines
drivers/mfd/dm355evm_msp.c static struct device *add_child(struct i2c_client *client, const char *name, · line 238
Quoted 2 lines
drivers/mfd/dm355evm_msp.c +2
-0+report_failure: +dev_err (&client->dev,"can't add %s dev\n" , name);This isn't a very friendly error message. Better to convert the
dev_dbg()calls todev_err()and tell the user what the problem was.
Which information display would be more appropriate here?
Regards,
Markus
cover mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:10:48 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an unnecessary variable initialisation
Refactoring
drivers/mfd/smsc-ece1099.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 mfd: smsc-ece1099: Delete an unnecessary variable initialisation in smsc_i2c_probe()
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 14:47:40 +0100
The variable "ret" will be set to an appropriate value a bit later. Thus let us omit the explicit initialisation at the beginning.
--- drivers/mfd/smsc-ece1099.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/smsc-ece1099.c +1 -1
@@ -36,7 +36,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c, {struct smsc *smsc;int devid, rev, venid_l, venid_h; -int ret =0 ; +int ret; smsc =devm_kzalloc (&i2c->dev,sizeof (struct smsc ),GFP_KERNEL );
Signature · 1 line
2.6.3
Re: [PATCH 1/2] mfd: smsc-ece1099: Delete an unnecessary variable initialisation in smsc_i2c_probe()
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 14:47:40 +0100The variable "ret" will be set to an appropriate value a bit later. Thus let us omit the explicit initialisation at the beginning.
Not sure this change is worth your or my time to be frank. I could understand if you were a first time submitter who was dipping their toe in the water, but for someone with 200+ patches, I really think you should be focusing on less trivial matters.
Quoted 18 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/smsc-ece1099.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mfd/smsc-ece1099.c +1
-1@@ -36,7 +36,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c, {struct smsc *smsc;int devid, rev, venid_l, venid_h; -int ret =0 ; +int ret; smsc =devm_kzalloc (&i2c->dev,sizeof (struct smsc ),GFP_KERNEL );
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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 2/2 mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:03:31 +0100
This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "devm_regmap_init_i2c" or "regmap_write" failed.
* Delete the jump label "err" then.
--- drivers/mfd/smsc-ece1099.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mfd/smsc-ece1099.c +3 -6
@@ -46,10 +46,8 @@ static int smsc_i2c_probe(struct i2c_client *i2c, } smsc->regmap =devm_regmap_init_i2c (i2c, &smsc_regmap_config); -if (IS_ERR (smsc->regmap)) { - ret =PTR_ERR (smsc->regmap); - goto err; - } +if (IS_ERR (smsc->regmap)) +return PTR_ERR (smsc->regmap);i2c_set_clientdata (i2c, smsc); smsc->dev = &i2c->dev;
@@ -68,7 +66,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c, ret =regmap_write (smsc->regmap,SMSC_CLK_CTRL , smsc->clk);if (ret) - goto err; +return ret;#ifdef CONFIG_OF if (i2c->dev.of_node)
@@ -76,7 +74,6 @@ static int smsc_i2c_probe(struct i2c_client *i2c, NULL, NULL, &i2c->dev);#endif -err:return ret; }
Signature · 1 line
2.6.3
Re: [PATCH 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:03:31 +0100This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "
devm_regmap_init_i2c" or "regmap_write" failed.* Delete the jump label "err" then.
Why are you bullet pointing here?
Just use proper sentences to tell us what's going on.
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/smsc-ece1099.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
Code looks fine however.
Please re-submit the set with the aforementioned changes along with my:
Quoted 34 lines
drivers/mfd/smsc-ece1099.c +3
-6@@ -46,10 +46,8 @@ static int smsc_i2c_probe(struct i2c_client *i2c, } smsc->regmap =devm_regmap_init_i2c (i2c, &smsc_regmap_config); -if (IS_ERR (smsc->regmap)) { - ret =PTR_ERR (smsc->regmap); - goto err; - } +if (IS_ERR (smsc->regmap)) +return PTR_ERR (smsc->regmap);i2c_set_clientdata (i2c, smsc); smsc->dev = &i2c->dev;@@ -68,7 +66,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c, ret =regmap_write (smsc->regmap,SMSC_CLK_CTRL , smsc->clk);if (ret) - goto err; +return ret;#ifdef CONFIG_OF if (i2c->dev.of_node)@@ -76,7 +74,6 @@ static int smsc_i2c_probe(struct i2c_client *i2c, NULL, NULL, &i2c->dev);#endif -err:return ret; }
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
Oh, the subject line is also duff. Please describe the changes properly.
"refactoring X", "making changes to Y" are not good subject lines.
Quoted 62 lines · Lee Jones
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:03:31 +0100This issue was detected by using the Coccinelle software.
* Let us return directly if a call of the function "
devm_regmap_init_i2c" or "regmap_write" failed.* Delete the jump label "err" then.
Why are you bullet pointing here?
Just use proper sentences to tell us what's going on.
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/smsc-ece1099.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)Code looks fine however.
Please re-submit the set with the aforementioned changes along with my:
Acked-by Lee Jones <[email protected]>Quoted 34 lines
drivers/mfd/smsc-ece1099.c +3
-6@@ -46,10 +46,8 @@ static int smsc_i2c_probe(struct i2c_client *i2c, } smsc->regmap =devm_regmap_init_i2c (i2c, &smsc_regmap_config); -if (IS_ERR (smsc->regmap)) { - ret =PTR_ERR (smsc->regmap); - goto err; - } +if (IS_ERR (smsc->regmap)) +return PTR_ERR (smsc->regmap);i2c_set_clientdata (i2c, smsc); smsc->dev = &i2c->dev;@@ -68,7 +66,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c, ret =regmap_write (smsc->regmap,SMSC_CLK_CTRL , smsc->clk);if (ret) - goto err; +return ret;#ifdef CONFIG_OF if (i2c->dev.of_node)@@ -76,7 +74,6 @@ static int smsc_i2c_probe(struct i2c_client *i2c, NULL, NULL, &i2c->dev);#endif -err:return ret; }
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
Please refrain from replying off-list. Adding back the Cc's.
Quoted 5 lines · SF Markus Elfring
Quoted 3 lines
Oh, the subject line is also duff. Please describe the changes properly.
"refactoring X", "making changes to Y" are not good subject lines.
Which topic would you prefer for my update suggestion instead?
This one.
"mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()"
The function name and just describing the changes as "refactoring" do not describe the changes in a helpful way.
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Code looks fine however.
Thanks for your look.
Quoted 3 lines
Quoted 3 lines
Please re-submit the set with the aforementioned changes along with my:
Acked-by Lee Jones <[email protected]>Do you really request that I should append this tag already to messages for (my adjusted) commits you can not see so far?
Yes. The code looks fine, and if the commit log is still not up to scratch I just won't apply it. :)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
Quoted 8 lines
Quoted 1 line
Which topic would you prefer for my update suggestion instead?
This one.
"mfd: smsc-ece1099: Refactoring for
smsc_i2c_probe()"The function name and just describing the changes as "refactoring" do not describe the changes in a helpful way.
Would you find a subject like "mfd: smsc-ece1099: Better exception handling in smsc_i2c_probe()" acceptable?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Acked-by Lee Jones <[email protected]>Do you really request that I should append this tag already to messages for (my adjusted) commits you can not see so far?
Yes.
Interesting …
Quoted 1 line
The code looks fine,
Thanks for a bit of positive feedback.
Quoted 1 line
and if the commit log is still not up to scratch I just won't apply it. :)
Can we eventually agree on an useful message before I would dare another commit?
Will it be sufficient to delete the asterisks there?
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: [PATCH 0/2] mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
In reply to SF Markus ElfringThis set is confusing.
Why do you have a cover letter specifying this as a 2 patch set, yet there are 4 patches attached to it?
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:10:48 +0100
What format is this?
Quoted 10 lines
A few update suggestions were taken into account
from static source code analysis.Markus Elfring (2):
Delete an unnecessary variable initialisation
Refactoringdrivers/mfd/smsc-ece1099.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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 0/2] mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
Quoted 4 lines
This set is confusing.
Why do you have a cover letter specifying this as a 2 patch set, yet there are 4 patches attached to it?
I do not see too many messages for this update suggestion.
Quoted 4 lines
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:10:48 +0100What format is this?
Are such specifications needed to preserve the desired authorship information during the transfer of commit messages by email?
Regards,
Markus
Re: [PATCH 0/2] mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
This set is confusing.
Why do you have a cover letter specifying this as a 2 patch set, yet there are 4 patches attached to it?
I do not see too many messages for this update suggestion.
In my inbox, your set looks like this:
Dec 29 2015 SF Markus Elfring ( 0) ┬>[PATCH] mfd-dm355evm_msp: One function call less in add_child() after error detection Dec 29 2015 SF Markus Elfring ( 0) ├>[PATCH 0/2] mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe() Dec 29 2015 SF Markus Elfring ( 0) │├>[PATCH 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe() Dec 29 2015 SF Markus Elfring ( 0) │└>[PATCH 1/2] mfd: smsc-ece1099: Delete an unnecessary variable initialisation in smsc_i2c_probe() Dec 29 2015 SF Markus Elfring ( 0) └>[PATCH] mfd: twl-core: One function call less in add_numbered_child() after error detection
... which is unconventional and pretty confusing.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:10:48 +0100What format is this?
Are such specifications needed to preserve the desired authorship information during the transfer of commit messages by email?
How did you sent this set? I fear you are sending these patches manually, using your mail client. You should instead be creating patches with git format-patch and sending them using git send-email. Then the formatting will be correct.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
Quoted 1 line
In my inbox, your set looks like this:
Thanks for your information. - I find the display correct.
Quoted 1 line
... which is unconventional and pretty confusing.
Do you request that I should resend my four update suggestions for different components as a single patch series for the software area "drivers/mfd"?
Quoted 1 line
I fear you are sending these patches manually, using your mail client.
I admit that I am doing this usually.
Quoted 1 line
You should instead be creating patches with
git format-patch
This happens also …
Quoted 1 line
and sending them using
git send-email.
I prefer other software tools for this task so far.
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: mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
Quoted 9 lines · SF Markus Elfring
Quoted 1 line
In my inbox, your set looks like this:
Thanks for your information. - I find the display correct.
Quoted 1 line
... which is unconventional and pretty confusing.
Do you request that I should resend my four update suggestions for different components as a single patch series for the software area "
drivers/mfd"?
You have to make that decision yourself. What I'm saying is, if the cover letter says there are 2 patches in the set, that's what we should expect.
Quoted 3 lines
Quoted 1 line
I fear you are sending these patches manually, using your mail client.
I admit that I am doing this usually.
Please don't do that.
Quoted 7 lines
Quoted 1 line
You should instead be creating patches with
git format-patchThis happens also …
Quoted 1 line
and sending them using
git send-email.I prefer other software tools for this task so far.
Such as?
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog