Source code review around jump label usage
Subsystems (101)
PATCH 1/7 cfag12864b: Use kmalloc_array() in cfag12864b_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 14:40:48 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/auxdisplay/cfag12864b.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/auxdisplay/cfag12864b.c +3 -2
@@ -347,8 +347,9 @@ static int __init cfag12864b_init(void) goto none; } - cfag12864b_cache =kmalloc (sizeof (unsigned char ) * -CFAG12864B_SIZE ,GFP_KERNEL ); + cfag12864b_cache =kmalloc_array (CFAG12864B_SIZE , +sizeof (*cfag12864b_cache), +GFP_KERNEL );if (cfag12864b_cache =NULL ) { printk(KERN_ERR CFAG12864B_NAME ": ERROR: " "can't alloc cache buffer (%i bytes)\n",
Signature · 1 line
2.10.0
PATCH 2/7 cfag12864b: Delete an error message for a failed kmalloc_array() call
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 14:54:05 +0200
Omit an extra message for a memory allocation failure in this function.
--- drivers/auxdisplay/cfag12864b.c | 3 --- 1 file changed, 3 deletions(-)
drivers/auxdisplay/cfag12864b.c +0 -3
@@ -351,9 +351,6 @@ static int __init cfag12864b_init(void)sizeof (*cfag12864b_cache), GFP_KERNEL);if (cfag12864b_cache =NULL ) { - printk(KERN_ERR CFAG12864B_NAME ": ERROR: " -"can't alloc cache buffer (%i bytes)\n" , - CFAG12864B_SIZE); ret = -ENOMEM ; goto bufferalloced; }
Signature · 1 line
2.10.0
PATCH 3/7 cfag12864b: Return directly if the driver "ks0108" was not initialized
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 15:15:10 +0200
* Return directly if the LCD controller driver was not initialized at the beginning.
* Omit an explicit variable initialisation which became unnecessary with this refactoring.
--- drivers/auxdisplay/cfag12864b.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/cfag12864b.c +2 -2
@@ -329,13 +329,13 @@ EXPORT_SYMBOL_GPL(cfag12864b_isinited);static int __init cfag12864b_init (void ) { -int ret = -EINVAL ; +int ret;/* ks0108_init() must be called first */ if (!ks0108_isinited ()) { printk(KERN_ERR CFAG12864B_NAME ": ERROR: " "ks0108 is not initialized\n"); - goto none; +return -EINVAL ; }BUILD_BUG_ON (PAGE_SIZE <CFAG12864B_SIZE );
Signature · 1 line
2.10.0
PATCH 4/7 cfag12864b: Return directly after a failed get_zeroed_page()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 15:30:56 +0200
* Return directly after a call of the function "get_zeroed_page" failed at the beginning.
* Delete the jump label "none" which became unnecessary with this refactoring.
--- drivers/auxdisplay/cfag12864b.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/auxdisplay/cfag12864b.c +1 -4
@@ -343,8 +343,7 @@ static int __init cfag12864b_init(void)if (cfag12864b_buffer =NULL ) { printk(KERN_ERR CFAG12864B_NAME ": ERROR: " "can't get a free page\n"); - ret = -ENOMEM ; - goto none; +return -ENOMEM ; } cfag12864b_cache = kmalloc_array(CFAG12864B_SIZE,
@@ -370,8 +369,6 @@ cachealloced: bufferalloced:free_page ((unsigned long ) cfag12864b_buffer); - -none:return ret; }
Signature · 1 line
2.10.0
PATCH 5/7 cfag12864b: Rename jump labels in cfag12864b_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 15:35:02 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/auxdisplay/cfag12864b.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/auxdisplay/cfag12864b.c +4 -6
@@ -351,23 +351,21 @@ static int __init cfag12864b_init(void) GFP_KERNEL);if (cfag12864b_cache =NULL ) { ret = -ENOMEM ; - goto bufferalloced; + goto free_buffer; } cfag12864b_workqueue =create_singlethread_workqueue (CFAG12864B_NAME );if (cfag12864b_workqueue =NULL ) - goto cachealloced; + goto free_cache;cfag12864b_clear ();cfag12864b_on (); cfag12864b_inited =1 ;return 0 ; - -cachealloced: + free_cache:kfree (cfag12864b_cache); - -bufferalloced: + free_buffer:free_page ((unsigned long ) cfag12864b_buffer);return ret; }
Signature · 1 line
2.10.0
PATCH 6/7 cfag12864b: Return an error code only as a constant in cfag12864b_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 15:50:25 +0200
1. Return an error code without storing it in a local variable.
2. Do not use curly brackets at one source code place where a single statement should be sufficient.
3. Delete the local variable "ret" which became unnecessary with this refactoring.
--- drivers/auxdisplay/cfag12864b.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/auxdisplay/cfag12864b.c +2 -6
@@ -329,8 +329,6 @@ EXPORT_SYMBOL_GPL(cfag12864b_isinited);static int __init cfag12864b_init (void ) { -int ret; -/* ks0108_init() must be called first */ if (!ks0108_isinited ()) { printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
@@ -349,10 +347,8 @@ static int __init cfag12864b_init(void) cfag12864b_cache =kmalloc_array (CFAG12864B_SIZE ,sizeof (*cfag12864b_cache),GFP_KERNEL ); -if (cfag12864b_cache =NULL ) { - ret = -ENOMEM ; +if (!cfag12864b_cache) goto free_buffer; - } cfag12864b_workqueue =create_singlethread_workqueue (CFAG12864B_NAME );if (cfag12864b_workqueue =NULL )
@@ -367,7 +363,7 @@ static int __init cfag12864b_init(void)kfree (cfag12864b_cache); free_buffer:free_page ((unsigned long ) cfag12864b_buffer); -return ret; +return -ENOMEM ; } static void __exit cfag12864b_exit(void)
Signature · 1 line
2.10.0
PATCH 7/7 cfag12864b: Adjust two checks for null pointers in cfag12864b_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 16:06:19 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/auxdisplay/cfag12864b.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/auxdisplay/cfag12864b.c +2 -2
@@ -338,7 +338,7 @@ static int __init cfag12864b_init(void)BUILD_BUG_ON (PAGE_SIZE <CFAG12864B_SIZE ); cfag12864b_buffer = (unsigned char *)get_zeroed_page (GFP_KERNEL ); -if (cfag12864b_buffer =NULL ) { +if (!cfag12864b_buffer) { printk(KERN_ERR CFAG12864B_NAME ": ERROR: " "can't get a free page\n");return -ENOMEM ;
@@ -351,7 +351,7 @@ static int __init cfag12864b_init(void) goto free_buffer; cfag12864b_workqueue =create_singlethread_workqueue (CFAG12864B_NAME ); -if (cfag12864b_workqueue =NULL ) +if (!cfag12864b_workqueue) goto free_cache;cfag12864b_clear ();
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/7] cfag12864b: Fine-tuning for cfag12864b_init()
In reply to SF Markus ElfringQuoted 14 lines
Date: Sat, 10 Sep 2016 16:17:01 +0200
Some update suggestions were taken into account
from static source code analysis.Markus Elfring (7):
Usekmalloc_array()
Delete an error message for a failedkmalloc_array()call Return directly if the driver "ks0108" was not initialized Return directly after a failedget_zeroed_page()Rename jump labels
Return an error code only as a constant
Adjust two checks for null pointers
Quoted 2 lines
drivers/auxdisplay/cfag12864b.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-)
Would you like to take another look at change possibilities for this software module?
Regards,
Markus
cover RADOS Block Device: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:35:20 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (47):
Use kmalloc_array() in rbd_header_from_disk()
Less function calls in rbd_header_from_disk() after error detection Adjust the position of a jump label in rbd_header_from_disk() Refactor two calls for memory allocations in rbd_dev_image_id() One function call less in rbd_dev_image_id() after error detection Rename jump labels in rbd_add_parse_args()
Rename a jump label in rbd_dev_v2_snap_name()
Rename jump labels in rbd_dev_v2_snap_context()
Rename a jump label in rbd_spec_fill_names()
One function call less in rbd_dev_image_name() after error detection Delete three unnecessary initialisations in rbd_dev_image_name() One function call less in rbd_dev_v2_parent_info() after error detection Delete an unnecessary initialisation in rbd_dev_v2_parent_info() Rename a jump label in rbd_dev_v2_object_prefix()
Rename jump labels in rbd_dev_create()
Rename jump labels in rbd_dev_v1_header_info()
Rename jump labels in rbd_init_disk()
Fix jump targets in rbd_queue_workfn()
Rename a jump label in rbd_reregister_watch()
Rename a jump label in rbd_register_watch()
Rename jump labels in rbd_try_lock()
Rename a jump label in find_watcher()
Rename jump labels in get_lock_owner_info()
Rename jump labels in rbd_request_lock()
Fix jump targets in rbd_img_parent_read()
Rename a jump label in rbd_img_parent_read_callback()
Rename a jump label in rbd_img_request_submit()
Refactor a jump target in rbd_img_obj_exists_submit()
Delete an unnecessary initialisation in rbd_img_obj_exists_submit() Refactor a jump target in rbd_img_obj_exists_callback()
Fix three jump targets in rbd_img_obj_parent_read_full() Rename a jump label in rbd_img_obj_parent_read_full_callback() Adjust the position of a jump label in rbd_img_request_fill() Rename a jump label in rbd_img_obj_callback()
Rename jump labels in rbd_osd_req_create_copyup()
Rename jump labels in rbd_osd_req_create()
Rename a jump label in bio_chain_clone_range()
Rename jump labels in rbd_client_create()
Rename a jump label in rbd_ioctl_set_ro()
One function call less in rbd_dev_probe_parent() after error detection Rename jump labels in rbd_dev_device_setup()
Rename jump labels in rbd_dev_image_probe()
Rename jump labels in do_rbd_add()
Delete an unnecessary initialisation in do_rbd_add()
Rename a jump label in rbd_slab_init()
Rename jump labels in rbd_init()
Delete unwanted spaces behind usages of the sizeof operator
drivers/block/rbd.c | 544 ++++++++++++++++++++++++++-------------------------- 1 file changed, 272 insertions(+), 272 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/47 block-rbd: Use kmalloc_array() in rbd_header_from_disk()
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 12:21:25 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Delete the local variable "size" which became unnecessary with this refactoring.
--- drivers/block/rbd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/rbd.c +3 -4
@@ -979,7 +979,6 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,char *snap_names =NULL ;u64 *snap_sizes =NULL ;u32 snap_count; -size_t size;int ret = -ENOMEM ;u32 i;
@@ -1017,9 +1016,9 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, goto out_err;/* ...as well as the array of their sizes. */ - - size = snap_count *sizeof (*header->snap_sizes); - snap_sizes =kmalloc (size,GFP_KERNEL ); + snap_sizes =kmalloc_array (snap_count, +sizeof (*header->snap_sizes), +GFP_KERNEL );if (!snap_sizes) goto out_err;
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 01/47] block-rbd: Use kmalloc_array() in rbd_header_from_disk()
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 12:21:25 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 6 lines
This issue was detected by using the Coccinelle software.
* Delete the local variable "size" which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>
Now applied.
Thanks,
Ilya
PATCH 2/47 block-rbd: Less function calls in rbd_header_from_disk() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 13:18:57 +0200
The functions "ceph_put_snap_context" and "kfree" were called in a few cases by the function "rbd_header_from_disk" during error handling even if the passed variables contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/block/rbd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/block/rbd.c +6 -4
@@ -1001,7 +1001,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, snap_count =le32_to_cpu (ondisk->snap_count); snapc =ceph_create_snap_context (snap_count,GFP_KERNEL );if (!snapc) - goto out_err; + goto free_prefix; snapc->seq =le64_to_cpu (ondisk->snap_seq);if (snap_count) {struct rbd_image_snap_ondisk *snaps;
@@ -1013,14 +1013,14 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, goto out_2big; snap_names =kmalloc (snap_names_len,GFP_KERNEL );if (!snap_names) - goto out_err; + goto put_snap_context;/* ...as well as the array of their sizes. */ snap_sizes =kmalloc_array (snap_count,sizeof (*header->snap_sizes),GFP_KERNEL );if (!snap_sizes) - goto out_err; + goto free_names;/* * Copy the names, and fill in each snapshot's id
@@ -1066,10 +1066,12 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,return 0 ; out_2big: ret = -EIO ; -out_err:kfree (snap_sizes); + free_names:kfree (snap_names); + put_snap_context:ceph_put_snap_context (snapc); + free_prefix:kfree (object_prefix);return ret;
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 02/47] block-rbd: Less function calls in rbd_header_from_disk() after error detection
Quoted 59 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 13:18:57 +0200The functions "
ceph_put_snap_context" and "kfree" were called in a few cases by the function "rbd_header_from_disk" during error handling even if the passed variables contained a null pointer.Adjust jump targets according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/block/rbd.c +6
-5@@ -1001,7 +1001,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, snap_count =le32_to_cpu (ondisk->snap_count); snapc =ceph_create_snap_context (snap_count,GFP_KERNEL );if (!snapc) - goto out_err; + goto free_prefix; snapc->seq =le64_to_cpu (ondisk->snap_seq);if (snap_count) {struct rbd_image_snap_ondisk *snaps;@@ -1013,14 +1013,14 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, goto out_2big; snap_names =kmalloc (snap_names_len,GFP_KERNEL );if (!snap_names) - goto out_err; + goto put_snap_context;/* ...as well as the array of their sizes. */ snap_sizes =kmalloc_array (snap_count,sizeof (*header->snap_sizes),GFP_KERNEL );if (!snap_sizes) - goto out_err; + goto free_names;/* * Copy the names, and fill in each snapshot's id @@ -1066,10 +1066,12 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,return 0 ; out_2big: ret = -EIO ; -out_err:kfree (snap_sizes); + free_names:kfree (snap_names); + put_snap_context:ceph_put_snap_context (snapc); + free_prefix:kfree (object_prefix);return ret; --
Quoted 2 lines
2.10.0
Please don't send patches that restructure error handling gotos unless you've spotted a bug. These patches are easy to get wrong, especially when done in bulk, and require careful review.
Some people fancy a single sink label approach, others like separate labels for each cleanup action - as long as the code is working, it's a matter of taste.
Thanks,
Ilya
PATCH 3/47 block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 13:37:34 +0200
Add a space character before a single jump label in this function according to the current Linux coding style convention.
--- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names:
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 25 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 13:37:34 +0200Add a space character before a single jump label in this function according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/rbd.c +1
-2@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names: --
Quoted 2 lines
2.10.0
Can you point where this current convention is documented? Certainly not in CodingStyle, AFAICT...
I know some people prefer a single space in there because it makes "diff -p" work better, but nowadays with "git diff" this argument is pretty moot.
Thanks,
Ilya
Re: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 9 lines
Quoted 9 lines
drivers/block/rbd.c +1
-1@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names:
…
Quoted 1 line
Can you point where this current convention is documented?
Do you find the software update "CodingStyle: Clarify and complete chapter 7" interesting?
Quoted 1 line
Certainly not in CodingStyle, AFAICT...
I suggest to look at the current version once more.
Quoted 3 lines
I know some people prefer a single space in there because it makes "diff -p" work better, but nowadays with "git diff" this argument is pretty moot.
Would you like to discuss the corresponding software evolution a bit more?
Regards,
Markus
Ilya Dryomov
maintainerRe: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 10 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
drivers/block/rbd.c +1
-1@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names:…
Quoted 4 lines
Quoted 1 line
Can you point where this current convention is documented?
Huh. That patch is not in Linus' tree.
Quoted 6 lines
Do you find the software update "CodingStyle: Clarify and complete chapter 7" interesting?
Quoted 1 line
Certainly not in CodingStyle, AFAICT...
Quoted 8 lines
I suggest to look at the current version once more.
Quoted 3 lines
I know some people prefer a single space in there because it makes "diff -p" work better, but nowadays with "git diff" this argument is pretty moot.
Would you like to discuss the corresponding software evolution a bit more?
Jon, could you please yank 865a1caa4b6b ("CodingStyle: Clarify and complete chapter 7") from your linux-next branch or at least change "It is advised to indent labels" to something less stronger? It hasn't even hit mainline yet and we are already getting spammed.
Looks like 9 out of 10 labels are not indented
$ git grep '^[a-z0-9]\+:' -- *.c | wc -l 27945 $ git grep '^ [a-z0-9]\+:' -- *.c | wc -l 2925
so I'd say that's a bad advise as far as consistency goes, and the "diff -p" argument is pretty moot nowadays.
Thanks,
Ilya
Re: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Hi Ilya,
Thanks for adding me.
Quoted 32 lines · Ilya Dryomov
Quoted 10 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
drivers/block/rbd.c +1
-1@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names:…
Quoted 4 lines
Quoted 1 line
Can you point where this current convention is documented?
Huh. That patch is not in Linus' tree.
Quoted 13 lines
Do you find the software update "CodingStyle: Clarify and complete chapter 7" interesting?
Quoted 1 line
Certainly not in CodingStyle, AFAICT...
I suggest to look at the current version once more.
Quoted 3 lines
I know some people prefer a single space in there because it makes "diff -p" work better, but nowadays with "git diff" this argument is pretty moot.
Quoted 6 lines
Quoted 1 line
Would you like to discuss the corresponding software evolution a bit more?
Jon, could you please yank
865a1caa4b6b("CodingStyle: Clarify and complete chapter 7") from your linux-next branch or at least change "It is advised to indent labels" to something less stronger? It hasn't even hit mainline yet and we are already getting spammed.
The problem isn't the documentation update nor whether you or me like a space before labels or not. The problem is Markus Elfring. The guy just spend his time flooding maintainers with unneeded changes they never asked for. Ignore him and you'll be much better. If he was not flooding you with this, he would find something else :-(
When I wrote "It is advised to indent labels with one space", I never meant that all the existing code should be converted that way. I expressed a preference, and provided a rationale for this preference. After that, an advice is just that: an advice.
Quoted 6 lines
Looks like 9 out of 10 labels are not indented
$ git grep '^[a-z0-9]\+:' -- *.c | wc -l 27945 $ git grep '^ [a-z0-9]\+:' -- *.c | wc -l 2925
Your regexps are wrong ;-) but the ratio is correct.
Quoted 2 lines
so I'd say that's a bad advise as far as consistency goes, and the "diff -p" argument is pretty moot nowadays.
It wasn't moot when I sent the documentation update patch. Or why would you think it was? "git diff", by default, behaves exactly the same as "diff -p" with regards to unindented labels (i.e. it doesn't handle them properly.)
However, since then the issue was discussed somewhere else:
https://lkml.org/lkml/2016/9/5/214
As you can see, alternatives to indenting labels with one space were found. Therefore you will soon be correct saying "the diff -p argument is pretty moot." As soon as my patch hits mainline, actually. Which shouldn't take too long as Andrew Morton picked it 4 days ago.
Once this happens, I'm fine with CodingStyle being updated again to reflect the current situation.
Hope it clarifies,
Signature · 2 lines
Jean Delvare SUSE L3 Support
Ilya Dryomov
maintainerRe: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 44 lines · Jean Delvare
Hi Ilya,
Thanks for adding me.
Quoted 32 lines · Ilya Dryomov
Quoted 10 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
drivers/block/rbd.c +1
-1@@ -1064,7 +1064,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev, header->snap_sizes = snap_sizes;return 0 ; -out_2big: + out_2big: ret = -EIO ;kfree (snap_sizes); free_names:…
Quoted 4 lines
Quoted 1 line
Can you point where this current convention is documented?
Huh. That patch is not in Linus' tree.
Quoted 13 lines
Do you find the software update "CodingStyle: Clarify and complete chapter 7" interesting?
Quoted 1 line
Certainly not in CodingStyle, AFAICT...
I suggest to look at the current version once more.
Quoted 3 lines
I know some people prefer a single space in there because it makes "diff -p" work better, but nowadays with "git diff" this argument is pretty moot.
Quoted 6 lines
Quoted 1 line
Would you like to discuss the corresponding software evolution a bit more?
Jon, could you please yank
865a1caa4b6b("CodingStyle: Clarify and complete chapter 7") from your linux-next branch or at least change "It is advised to indent labels" to something less stronger? It hasn't even hit mainline yet and we are already getting spammed.
Quoted 8 lines
The problem isn't the documentation update nor whether you or me like a space before labels or not. The problem is Markus Elfring. The guy just spend his time flooding maintainers with unneeded changes they never asked for. Ignore him and you'll be much better. If he was not flooding you with this, he would find something else :-(
When I wrote "It is advised to indent labels with one space", I never meant that all the existing code should be converted that way. I
Hi Jean,
That much is clear, however ...
Quoted 11 lines
expressed a preference, and provided a rationale for this preference. After that, an advice is just that: an advice.
Quoted 6 lines
Looks like 9 out of 10 labels are not indented
$ git grep '^[a-z0-9]\+:' -- *.c | wc -l 27945 $ git grep '^ [a-z0-9]\+:' -- *.c | wc -l 2925Your regexps are wrong ;-) but the ratio is correct.
... one of the main points of any coding style is consistency. When someone new wanting to submit say a new driver opens CodingStyle and sees "It is advised to indent labels ...", they might start indenting labels in their code and advise others to do the same. Given the 9/10 existing ratio, that advice is wrong. If I wanted to clarify the situation, I'd have gone with "one space indented labels are also acceptable" or so. The example you've re-indented dates back to 2.6.4 times...
Quoted 8 lines
Quoted 3 lines
so I'd say that's a bad advise as far as consistency goes, and the "diff -p" argument is pretty moot nowadays.
It wasn't moot when I sent the documentation update patch. Or why would you think it was? "git diff", by default, behaves exactly the same as "diff -p" with regards to unindented labels (i.e. it doesn't handle them properly.)
The git diff xfuncname incantation is a few years old now. git diff also works on regular files, BTW.
Quoted 11 lines
However, since then the issue was discussed somewhere else:
https://lkml.org/lkml/2016/9/5/214As you can see, alternatives to indenting labels with one space were found. Therefore you will soon be correct saying "the diff -p argument is pretty moot." As soon as my patch hits mainline, actually. Which shouldn't take too long as Andrew Morton picked it 4 days ago.
Once this happens, I'm fine with CodingStyle being updated again to reflect the current situation.
I'm not sure which patch you are talking about - the message you linked is not a patch and it's impossible to follow large threads on lkml.org.
Thanks,
Ilya
Re: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 30 lines · Ilya Dryomov
Quoted 6 lines · Jean Delvare
Quoted 4 lines · Ilya Dryomov
Jon, could you please yank
865a1caa4b6b("CodingStyle: Clarify and complete chapter 7") from your linux-next branch or at least change "It is advised to indent labels" to something less stronger? It hasn't even hit mainline yet and we are already getting spammed.Quoted 8 lines
The problem isn't the documentation update nor whether you or me like a space before labels or not. The problem is Markus Elfring. The guy just spend his time flooding maintainers with unneeded changes they never asked for. Ignore him and you'll be much better. If he was not flooding you with this, he would find something else :-(
When I wrote "It is advised to indent labels with one space", I never meant that all the existing code should be converted that way. I
Hi Jean,
That much is clear, however ...
Quoted 10 lines
expressed a preference, and provided a rationale for this preference. After that, an advice is just that: an advice.
Quoted 6 lines
Looks like 9 out of 10 labels are not indented
$ git grep '^[a-z0-9]\+:' -- *.c | wc -l 27945 $ git grep '^ [a-z0-9]\+:' -- *.c | wc -l 2925
Quoted 7 lines
Quoted 1 line
Your regexps are wrong ;-) but the ratio is correct.
... one of the main points of any coding style is consistency. When someone new wanting to submit say a new driver opens CodingStyle and sees "It is advised to indent labels ...", they might start indenting labels in their code and advise others to do the same. Given the 9/10 existing ratio, that advice is wrong.
Or you could read the thread I pointed you to, where I explain why this reasoning is wrong.
Quoted 4 lines
If I wanted to clarify the
situation, I'd have gone with "one space indented labels are also acceptable" or so. The example you've re-indented dates back to 2.6.4 times...
I can't see how this is relevant.
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
so I'd say that's a bad advise as far as consistency goes, and the "diff -p" argument is pretty moot nowadays.
It wasn't moot when I sent the documentation update patch. Or why would you think it was? "git diff", by default, behaves exactly the same as "diff -p" with regards to unindented labels (i.e. it doesn't handle them properly.)
The git diff xfuncname incantation is a few years old now.
It doesn't help if a majority of developers don't know about it (as was my case until last week), and the project itself doesn't carry the required configuration bits to make it work out of the box (which hopefully will be the case soon, see below.)
Quoted 1 line
git diff also works on regular files, BTW.
I have no idea what you mean here, sorry.
Quoted 8 lines
Quoted 8 lines
However, since then the issue was discussed somewhere else:
https://lkml.org/lkml/2016/9/5/214As you can see, alternatives to indenting labels with one space were found. Therefore you will soon be correct saying "the diff -p argument is pretty moot." As soon as my patch hits mainline, actually. Which shouldn't take too long as Andrew Morton picked it 4 days ago.
Quoted 5 lines
Quoted 2 lines
Once this happens, I'm fine with CodingStyle being updated again to reflect the current situation.
I'm not sure which patch you are talking about - the message you linked is not a patch and it's impossible to follow large threads on lkml.org.
The solution was in this thread, which I expected you to read. The patch proper was sent separately:
http://marc.info/?l=linux-kernel&m=147325166209844&w=2
It uses the git diff xfuncname feature you mentioned above. To be honest I'm surprised it isn't the git default, it seems odd to have so many diff drivers included in git and not enable them on obvious file extensions. Oh well.
Signature · 2 lines
Jean Delvare SUSE L3 Support
Ilya Dryomov
maintainerRe: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Quoted 33 lines · Jean Delvare
Quoted 32 lines · Ilya Dryomov
Quoted 6 lines · Jean Delvare
Quoted 4 lines · Ilya Dryomov
Jon, could you please yank
865a1caa4b6b("CodingStyle: Clarify and complete chapter 7") from your linux-next branch or at least change "It is advised to indent labels" to something less stronger? It hasn't even hit mainline yet and we are already getting spammed.Quoted 8 lines
The problem isn't the documentation update nor whether you or me like a space before labels or not. The problem is Markus Elfring. The guy just spend his time flooding maintainers with unneeded changes they never asked for. Ignore him and you'll be much better. If he was not flooding you with this, he would find something else :-(
When I wrote "It is advised to indent labels with one space", I never meant that all the existing code should be converted that way. I
Hi Jean,
That much is clear, however ...
Quoted 11 lines
expressed a preference, and provided a rationale for this preference. After that, an advice is just that: an advice.
Quoted 6 lines
Looks like 9 out of 10 labels are not indented
$ git grep '^[a-z0-9]\+:' -- *.c | wc -l 27945 $ git grep '^ [a-z0-9]\+:' -- *.c | wc -l 2925Your regexps are wrong ;-) but the ratio is correct.
Quoted 8 lines
Quoted 5 lines
... one of the main points of any coding style is consistency. When someone new wanting to submit say a new driver opens CodingStyle and sees "It is advised to indent labels ...", they might start indenting labels in their code and advise others to do the same. Given the 9/10 existing ratio, that advice is wrong.
Or you could read the thread I pointed you to, where I explain why this reasoning is wrong.
Sorry, navigating lkml.org archive is a pain, and I was expecting to see patch. Your points
"The acceptance of an optional single space before labels dates back to at least June 2007, as supported by the very first incarnation of checkpatch.pl. So nothing really new here, except for a preference (my preference, admittedly, but I'm know I'm not alone) being expressed in the coding style document."
"Recommendations are not meant to document what people are currently doing but what we think they should be doing."
are valid, but note that there is a world of difference between an acceptance and a preference. The *only* point of whitespace guidelines is to keep the code base consistent. You don't go changing whitespace preferences in such a huge project, not unless you have a *very* good rationale and existing code base is swayed (which it isn't, given the 9/10 ratio).
Quoted 7 lines
Quoted 5 lines
If I wanted to clarify the
situation, I'd have gone with "one space indented labels are also acceptable" or so. The example you've re-indented dates back to 2.6.4 times...I can't see how this is relevant.
That was a 12 year old example, codifying an existing style used in ~90% cases, serving as a guideline for new contributors.
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
so I'd say that's a bad advise as far as consistency goes, and the "diff -p" argument is pretty moot nowadays.
It wasn't moot when I sent the documentation update patch. Or why would you think it was? "git diff", by default, behaves exactly the same as "diff -p" with regards to unindented labels (i.e. it doesn't handle them properly.)
The git diff xfuncname incantation is a few years old now.
Quoted 8 lines
It doesn't help if a majority of developers don't know about it (as was my case until last week), and the project itself doesn't carry the required configuration bits to make it work out of the box (which hopefully will be the case soon, see below.)
Quoted 1 line
git diff also works on regular files, BTW.
I have no idea what you mean here, sorry.
Oh, just that it works outside of git repos too, so you aren't stuck with diffutils if you want to diff two random .c files.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
However, since then the issue was discussed somewhere else:
https://lkml.org/lkml/2016/9/5/214As you can see, alternatives to indenting labels with one space were found. Therefore you will soon be correct saying "the diff -p argument is pretty moot." As soon as my patch hits mainline, actually. Which shouldn't take too long as Andrew Morton picked it 4 days ago.
Quoted 5 lines
Quoted 2 lines
Once this happens, I'm fine with CodingStyle being updated again to reflect the current situation.
I'm not sure which patch you are talking about - the message you linked is not a patch and it's impossible to follow large threads on lkml.org.
The solution was in this thread, which I expected you to read. The patch proper was sent separately:
Quoted 6 lines
http://marc.info/?l=linux-kernel&m=147325166209844&w=2
It uses the git diff xfuncname feature you mentioned above. To be honest I'm surprised it isn't the git default, it seems odd to have so many diff drivers included in git and not enable them on obvious file extensions. Oh well.
This came up before: http://www.spinics.net/lists/git/msg164216.html,
Linus didn't like it. I suggest you add him to the CC on this patch to see if he changed his mind.
Thanks,
Ilya
Re: [PATCH 03/47] block-rbd: Adjust the position of a jump label in rbd_header_from_disk()
Hi Ilya,
Sorry for the late answer.
Quoted 9 lines · Ilya Dryomov
Sorry, navigating lkml.org archive is a pain, and I was expecting to see patch. Your points
"The acceptance of an optional single space before labels dates back to at least June 2007, as supported by the very first incarnation of checkpatch.pl. So nothing really new here, except for a preference (my preference, admittedly, but I'm know I'm not alone) being expressed in the coding style document."
Quoted 6 lines
"Recommendations are not meant to document what people are currently doing but what we think they should be doing."
are valid, but note that there is a world of difference between an acceptance and a preference. The *only* point of whitespace guidelines is to keep the code base consistent.
Consistency is half of the reason, the other half is readability. This is why the CodingStyle document has a number of rationales explained. This is also why we put whitespace in the first place, while the C language doesn't require any ;-)
The sense of my proposal was to address a readability (or usability) issue.
Quoted 4 lines
You don't go changing whitespace
preferences in such a huge project, not unless you have a *very* good rationale and existing code base is swayed (which it isn't, given the 9/10 ratio).
I did consider the reason to be good enough to warrant a "change", actually. Or more exactly from "one space is allowed" to "one space is recommended." Which is quite different from changing all the code actively. I can understand how you don't like it, but again, this "inconsistency" has been accepted for almost a decade now, so I find it strange to see so much resistance when someone finally tries to sort it out.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
If I wanted to clarify the
situation, I'd have gone with "one space indented labels are also acceptable" or so. The example you've re-indented dates back to 2.6.4 times...I can't see how this is relevant.
That was a 12 year old example, codifying an existing style used in ~90% cases, serving as a guideline for new contributors.
OK, I get your point now. But the CodingStyle document isn't carved into stone. I see 43 changes to that file in recent history (since April 2005), some of which are actual changes or clarifications of our coding style. This very section of the document was updated in December 2014, so not so long ago.
In the end I suppose it boils down to how problematic you consider the current situation to be. Apparently you and several other maintainers think it's just fine, while me (and a few others apparently) think it is not.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
git diff also works on regular files, BTW.
I have no idea what you mean here, sorry.
Oh, just that it works outside of git repos too, so you aren't stuck with diffutils if you want to diff two random .c files.
Oh, I had never thought of that. Thanks for the hint :-)
Quoted 11 lines
Quoted 7 lines
(...)
http://marc.info/?l=linux-kernel&m=147325166209844&w=2It uses the git diff xfuncname feature you mentioned above. To be honest I'm surprised it isn't the git default, it seems odd to have so many diff drivers included in git and not enable them on obvious file extensions. Oh well.
This came up before: http://www.spinics.net/lists/git/msg164216.html,
Linus didn't like it. I suggest you add him to the CC on this patch to see if he changed his mind.
Thanks for the pointer. It is interesting to see many people had been bothered by the same problem for many years and even proposed solution for it. But also sad to see that nothing happened :-(
Well Linus suggested to improve the default, he was not opposed to the change per se I think. But it was 5 years ago and nothing happened since then, so I'd rather go with what is available today. Which means either one space before labels, or drivers in .gitattributes. Choose your poison ;-)
Thanks,
Signature · 2 lines
Jean Delvare SUSE L3 Support
PATCH 4/47 block-rbd: Refactor two calls for memory allocations in rbd_dev_image_id()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 14:48:41 +0200
* Pass the sizes for memory allocations to the corresponding functions directly without storing the calculated values in an intermediate variable.
* Delete the local variable "size" which became unnecessary with this refactoring.
--- drivers/block/rbd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/block/rbd.c +4 -6
@@ -5833,7 +5833,6 @@ again:static int rbd_dev_image_id (struct rbd_device *rbd_dev) {int ret; -size_t size;char *object_name;void *response;char *image_id;
@@ -5854,17 +5853,16 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev)* First, see if the format 2 image id file exists, and if * so, get the image's persistent id from it. */ - size =sizeof (RBD_ID_PREFIX ) +strlen (rbd_dev->spec->image_name); - object_name =kmalloc (size,GFP_NOIO ); + object_name =kmalloc (sizeof (RBD_ID_PREFIX ) + +strlen (rbd_dev->spec->image_name), +GFP_NOIO );if (!object_name)return -ENOMEM ;sprintf (object_name,"%s%s" ,RBD_ID_PREFIX , rbd_dev->spec->image_name);dout ("rbd id object name is %s\n" , object_name);/* Response will be an encoded string, which includes a length */ - - size =sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ; - response =kzalloc (size,GFP_NOIO ); + response =kzalloc (sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ,GFP_NOIO );if (!response) { ret = -ENOMEM ; goto out;
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 04/47] block-rbd: Refactor two calls for memory allocations in rbd_dev_image_id()
Quoted 50 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 14:48:41 +0200* Pass the sizes for memory allocations to the corresponding functions directly without storing the calculated values in an intermediate variable.
* Delete the local variable "size" which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/block/rbd.c +4
-7@@ -5833,7 +5833,6 @@ again:static int rbd_dev_image_id (struct rbd_device *rbd_dev) {int ret; -size_t size;char *object_name;void *response;char *image_id;@@ -5854,17 +5853,16 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev)* First, see if the format 2 image id file exists, and if * so, get the image's persistent id from it. */ - size =sizeof (RBD_ID_PREFIX ) +strlen (rbd_dev->spec->image_name); - object_name =kmalloc (size,GFP_NOIO ); + object_name =kmalloc (sizeof (RBD_ID_PREFIX ) + +strlen (rbd_dev->spec->image_name), +GFP_NOIO );if (!object_name)return -ENOMEM ;sprintf (object_name,"%s%s" ,RBD_ID_PREFIX , rbd_dev->spec->image_name);dout ("rbd id object name is %s\n" , object_name);/* Response will be an encoded string, which includes a length */ - - size =sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ; - response =kzalloc (size,GFP_NOIO ); + response =kzalloc (sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ,GFP_NOIO );if (!response) { ret = -ENOMEM ; goto out; --
Quoted 2 lines
2.10.0
How is this any better? If anything, it makes the first kmalloc() call slightly less readable.
Thanks,
Ilya
Re: [PATCH 04/47] block-rbd: Refactor two calls for memory allocations in rbd_dev_image_id()
Quoted 30 lines
Quoted 30 lines
drivers/block/rbd.c +4
-6@@ -5833,7 +5833,6 @@ again:static int rbd_dev_image_id (struct rbd_device *rbd_dev) {int ret; -size_t size;char *object_name;void *response;char *image_id;@@ -5854,17 +5853,16 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev)* First, see if the format 2 image id file exists, and if * so, get the image's persistent id from it. */ - size =sizeof (RBD_ID_PREFIX ) +strlen (rbd_dev->spec->image_name); - object_name =kmalloc (size,GFP_NOIO ); + object_name =kmalloc (sizeof (RBD_ID_PREFIX ) + +strlen (rbd_dev->spec->image_name), +GFP_NOIO );if (!object_name)return -ENOMEM ;sprintf (object_name,"%s%s" ,RBD_ID_PREFIX , rbd_dev->spec->image_name);dout ("rbd id object name is %s\n" , object_name);/* Response will be an encoded string, which includes a length */ - - size =sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ; - response =kzalloc (size,GFP_NOIO ); + response =kzalloc (sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ,GFP_NOIO );if (!response) { ret = -ENOMEM ; goto out;
…
Quoted 1 line
How is this any better?
I find it useful to omit the local variable "size" here.
Quoted 1 line
If anything, it makes the first
kmalloc()call slightly less readable.
I got an other impression. The refactored function call did not fit into a single line because of a well-known length limitation.
Does the kzalloc() call look a bit nicer for you now?
Regards,
Markus
PATCH 5/47 block-rbd: One function call less in rbd_dev_image_id() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 15:05:49 +0200
The kfree() function was called in one case by the rbd_dev_image_id() function during error handling even if the passed variable "response" contained a null pointer.
Adjust a jump target according to the Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -5865,7 +5865,7 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev) response =kzalloc (sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX ,GFP_NOIO );if (!response) { ret = -ENOMEM ; - goto out; + goto free_name; }/* If it doesn't exist we'll assume it's a format 1 image */
@@ -5893,8 +5893,8 @@ static int rbd_dev_image_id(struct rbd_device *rbd_dev) rbd_dev->spec->image_id = image_id;dout ("image_id is %s\n" , image_id); } -out:kfree (response); + free_name:kfree (object_name);return ret;
Signature · 1 line
2.10.0
Joe Perches
maintainerRe: [PATCH 00/47] RADOS Block Device: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 2 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:35:20 +0200
This email header and all children contains:
References: <[email protected]>
Markus, just stop using references lines.
Stop.
It doesn't add any value for any patch you've submitted here.
PATCH 6/47 block-rbd: Rename jump labels in rbd_add_parse_args()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 15:20:48 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/block/rbd.c +12 -12
@@ -5709,27 +5709,27 @@ static int rbd_add_parse_args(const char *buf,return -ENOMEM ;if (!*options) {rbd_warn (NULL ,"no options provided" ); - goto out_err; + goto free_options; } spec =rbd_spec_alloc ();if (!spec) - goto out_mem; + goto status_indication; spec->pool_name =dup_token (&buf,NULL );if (!spec->pool_name) - goto out_mem; + goto status_indication;if (!*spec->pool_name) {rbd_warn (NULL ,"no pool name provided" ); - goto out_err; + goto free_options; } spec->image_name =dup_token (&buf,NULL );if (!spec->image_name) - goto out_mem; + goto status_indication;if (!*spec->image_name) {rbd_warn (NULL ,"no image name provided" ); - goto out_err; + goto free_options; }/*
@@ -5742,11 +5742,11 @@ static int rbd_add_parse_args(const char *buf, len =sizeof (RBD_SNAP_HEAD_NAME ) -1 ; }else if (len >RBD_MAX_SNAP_NAME_LEN ) { ret = -ENAMETOOLONG ; - goto out_err; + goto free_options; } snap_name =kmemdup (buf, len +1 ,GFP_KERNEL );if (!snap_name) - goto out_mem; + goto status_indication; *(snap_name + len) ='\0' ; spec->snap_name = snap_name;
@@ -5754,7 +5754,7 @@ static int rbd_add_parse_args(const char *buf, rbd_opts =kzalloc (sizeof (*rbd_opts),GFP_KERNEL );if (!rbd_opts) - goto out_mem; + goto status_indication; rbd_opts->read_only =RBD_READ_ONLY_DEFAULT ; rbd_opts->queue_depth =RBD_QUEUE_DEPTH_DEFAULT ;
@@ -5764,7 +5764,7 @@ static int rbd_add_parse_args(const char *buf, parse_rbd_opts_token, rbd_opts);if (IS_ERR (copts)) { ret =PTR_ERR (copts); - goto out_err; + goto free_options; }kfree (options);
@@ -5773,9 +5773,9 @@ static int rbd_add_parse_args(const char *buf, *rbd_spec = spec;return 0 ; -out_mem: + status_indication: ret = -ENOMEM ; -out_err: + free_options:kfree (rbd_opts);rbd_spec_put (spec);kfree (options);
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 06/47] block-rbd: Rename jump labels in rbd_add_parse_args()
Quoted 93 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 11 Sep 2016 15:20:48 +0200Adjust jump labels according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/block/rbd.c +12
-13@@ -5709,27 +5709,27 @@ static int rbd_add_parse_args(const char *buf,return -ENOMEM ;if (!*options) {rbd_warn (NULL ,"no options provided" ); - goto out_err; + goto free_options; } spec =rbd_spec_alloc ();if (!spec) - goto out_mem; + goto status_indication; spec->pool_name =dup_token (&buf,NULL );if (!spec->pool_name) - goto out_mem; + goto status_indication;if (!*spec->pool_name) {rbd_warn (NULL ,"no pool name provided" ); - goto out_err; + goto free_options; } spec->image_name =dup_token (&buf,NULL );if (!spec->image_name) - goto out_mem; + goto status_indication;if (!*spec->image_name) {rbd_warn (NULL ,"no image name provided" ); - goto out_err; + goto free_options; }/* @@ -5742,11 +5742,11 @@ static int rbd_add_parse_args(const char *buf, len =sizeof (RBD_SNAP_HEAD_NAME ) -1 ; }else if (len >RBD_MAX_SNAP_NAME_LEN ) { ret = -ENAMETOOLONG ; - goto out_err; + goto free_options; } snap_name =kmemdup (buf, len +1 ,GFP_KERNEL );if (!snap_name) - goto out_mem; + goto status_indication; *(snap_name + len) ='\0' ; spec->snap_name = snap_name;@@ -5754,7 +5754,7 @@ static int rbd_add_parse_args(const char *buf, rbd_opts =kzalloc (sizeof (*rbd_opts),GFP_KERNEL );if (!rbd_opts) - goto out_mem; + goto status_indication; rbd_opts->read_only =RBD_READ_ONLY_DEFAULT ; rbd_opts->queue_depth =RBD_QUEUE_DEPTH_DEFAULT ;@@ -5764,7 +5764,7 @@ static int rbd_add_parse_args(const char *buf, parse_rbd_opts_token, rbd_opts);if (IS_ERR (copts)) { ret =PTR_ERR (copts); - goto out_err; + goto free_options; }kfree (options);@@ -5773,9 +5773,9 @@ static int rbd_add_parse_args(const char *buf, *rbd_spec = spec;return 0 ; -out_mem: + status_indication: ret = -ENOMEM ; -out_err: + free_options:kfree (rbd_opts);rbd_spec_put (spec);kfree (options); --
Quoted 1 line
2.10.0
For a ret = -ENOMEM; statement, your status_indication label actually conveys less information than out_mem did. Don't waste everybody's time by sending these pointless rename patches, please.
Thanks,
Ilya
PATCH 7/47 block-rbd: Rename a jump label in rbd_dev_v2_snap_name()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 17:53:19 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/rbd.c +3 -3
@@ -5532,18 +5532,18 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev,dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) { snap_name =ERR_PTR (ret); - goto out; + goto free_buffer; } p = reply_buf; end = reply_buf + ret; snap_name =ceph_extract_encoded_string (&p, end,NULL ,GFP_KERNEL );if (IS_ERR (snap_name)) - goto out; + goto free_buffer;dout (" snap_id 0x%016llx snap_name = %s\n" , (unsigned long long )snap_id, snap_name); -out: + free_buffer:kfree (reply_buf);return snap_name;
Signature · 1 line
2.10.0
PATCH 8/47 block-rbd: Rename jump labels in rbd_dev_v2_snap_context()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 17:55:51 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/block/rbd.c +7 -7
@@ -5465,13 +5465,13 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev) reply_buf, size);dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) - goto out; + goto free_buffer; p = reply_buf; end = reply_buf + ret; ret = -ERANGE ; -ceph_decode_64_safe (&p, end, seq, out); -ceph_decode_32_safe (&p, end, snap_count, out); +ceph_decode_64_safe (&p, end, seq, free_buffer); +ceph_decode_32_safe (&p, end, snap_count, free_buffer);/* * Make sure the reported number of snapshot ids wouldn't go
@@ -5482,16 +5482,16 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev)if (snap_count > (SIZE_MAX -sizeof (struct ceph_snap_context )) /sizeof (u64)) { ret = -EINVAL ; - goto out; + goto free_buffer; }if (!ceph_has_room (&p, end, snap_count *sizeof (__le64))) - goto out; + goto free_buffer; ret =0 ; snapc =ceph_create_snap_context (snap_count,GFP_KERNEL );if (!snapc) { ret = -ENOMEM ; - goto out; + goto free_buffer; } snapc->seq = seq;for (i =0 ; i < snap_count; i++)
@@ -5502,7 +5502,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev)dout (" snap context seq = %llu, snap_count = %u\n" , (unsigned long long )seq, (unsigned int )snap_count); -out: + free_buffer:kfree (reply_buf);return ret;
Signature · 1 line
2.10.0
PATCH 9/47 block-rbd: Rename a jump label in rbd_spec_fill_names()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 17:58:18 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/rbd.c +2 -3
@@ -5421,7 +5421,7 @@ static int rbd_spec_fill_names(struct rbd_device *rbd_dev) snap_name =rbd_snap_name (rbd_dev, spec->snap_id);if (IS_ERR (snap_name)) { ret =PTR_ERR (snap_name); - goto out_err; + goto free_name; } spec->pool_name = pool_name;
@@ -5429,8 +5429,7 @@ static int rbd_spec_fill_names(struct rbd_device *rbd_dev) spec->snap_name = snap_name;return 0 ; - -out_err: + free_name:kfree (image_name);kfree (pool_name);return ret;
Signature · 1 line
2.10.0
PATCH 10/47 block-rbd: One function call less in rbd_dev_image_name() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:00:18 +0200
The kfree() function was called in one case by the rbd_dev_image_name() function during error handling even if the passed variable "reply_buf" contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/block/rbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/block/rbd.c +4 -3
@@ -5276,14 +5276,14 @@ static char *rbd_dev_image_name(struct rbd_device *rbd_dev) size =sizeof (__le32) +RBD_IMAGE_NAME_LEN_MAX ; reply_buf =kmalloc (size,GFP_KERNEL );if (!reply_buf) - goto out; + goto free_id; ret =rbd_obj_method_sync (rbd_dev,RBD_DIRECTORY ,"rbd" ,"dir_get_name" , image_id, image_id_size, reply_buf, size);if (ret <0 ) - goto out; + goto free_buffer; p = reply_buf; end = reply_buf + ret;
@@ -5292,8 +5292,9 @@ static char *rbd_dev_image_name(struct rbd_device *rbd_dev) image_name =NULL ; else dout("%s: name is %s len is %zd\n", __func__, image_name, len); -out: + free_buffer:kfree (reply_buf); + free_id:kfree (image_id);return image_name;
Signature · 1 line
2.10.0
PATCH 11/47 block-rbd: Delete three unnecessary initialisations in rbd_dev_image_name()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:02:16 +0200
Three local variables will be set to appropriate values a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/rbd.c +3 -3
@@ -5256,9 +5256,9 @@ static char *rbd_dev_image_name(struct rbd_device *rbd_dev)void *p;void *end;size_t size; -void *reply_buf =NULL ; -size_t len =0 ; -char *image_name =NULL ; +void *reply_buf; +size_t len; +char *image_name;int ret;rbd_assert (!rbd_dev->spec->image_name);
Signature · 1 line
2.10.0
PATCH 12/47 block-rbd: One function call less in rbd_dev_v2_parent_info() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:05:00 +0200
The kfree() function was called in one case by the rbd_dev_v2_parent_info() function during error handling even if the passed variable "reply_buf" contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/block/rbd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/block/rbd.c +11 -11
@@ -5105,7 +5105,7 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) reply_buf =kmalloc (size,GFP_KERNEL );if (!reply_buf) { ret = -ENOMEM ; - goto out_err; + goto put_spec; } snapid =cpu_to_le64 (rbd_dev->spec->snap_id);
@@ -5115,12 +5115,12 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) reply_buf, size);dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) - goto out_err; + goto free_buffer; p = reply_buf; end = reply_buf + ret; ret = -ERANGE ; -ceph_decode_64_safe (&p, end, pool_id, out_err); +ceph_decode_64_safe (&p, end, pool_id, free_buffer);if (pool_id ==CEPH_NOPOOL ) {/* * Either the parent never existed, or we have
@@ -5138,7 +5138,7 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) rbd_dev->disk->disk_name); } - goto out;/* No parent? No problem. */ + goto success_indication;/* No parent? No problem. */ }/* The ceph file layout needs to fit pool id in 32 bits */
@@ -5147,16 +5147,16 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)if (pool_id > (u64 )U32_MAX ) {rbd_warn (NULL ,"parent pool id too large (%llu > %u)" , (unsigned long long )pool_id,U32_MAX ); - goto out_err; + goto free_buffer; } image_id =ceph_extract_encoded_string (&p, end,NULL ,GFP_KERNEL );if (IS_ERR (image_id)) { ret =PTR_ERR (image_id); - goto out_err; + goto free_buffer; } -ceph_decode_64_safe (&p, end, snap_id, out_err); -ceph_decode_64_safe (&p, end, overlap, out_err); +ceph_decode_64_safe (&p, end, snap_id, free_buffer); +ceph_decode_64_safe (&p, end, overlap, free_buffer);/* * The parent won't change (except when the clone is
@@ -5189,11 +5189,11 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) } } rbd_dev->parent_overlap = overlap; - -out: + success_indication: ret =0 ; -out_err: + free_buffer:kfree (reply_buf); + put_spec:rbd_spec_put (parent_spec);return ret;
Signature · 1 line
2.10.0
PATCH 13/47 block-rbd: Delete an unnecessary initialisation in rbd_dev_v2_parent_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:08:14 +0200
The local variable "reply_buf" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
@@ -5084,7 +5084,7 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) {struct rbd_spec *parent_spec;size_t size; -void *reply_buf =NULL ; +void *reply_buf;__le64 snapid;void *p;void *end;
Signature · 1 line
2.10.0
PATCH 14/47 block-rbd: Rename a jump label in rbd_dev_v2_object_prefix()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:10:02 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -5017,7 +5017,7 @@ static int rbd_dev_v2_object_prefix(struct rbd_device *rbd_dev) reply_buf, RBD_OBJ_PREFIX_LEN_MAX);dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) - goto out; + goto free_buffer; p = reply_buf; rbd_dev->header.object_prefix = ceph_extract_encoded_string(&p,
@@ -5030,7 +5030,7 @@ static int rbd_dev_v2_object_prefix(struct rbd_device *rbd_dev) }else {dout (" object_prefix = %s\n" , rbd_dev->header.object_prefix); } -out: + free_buffer:kfree (reply_buf);return ret;
Signature · 1 line
2.10.0
PATCH 15/47 block-rbd: Rename jump labels in rbd_dev_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:12:39 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/block/rbd.c +4 -5
@@ -4930,23 +4930,22 @@ static struct rbd_device *rbd_dev_create(struct rbd_client *rbdc,minor_to_rbd_dev_id (1 <<MINORBITS ), GFP_KERNEL);if (rbd_dev->dev_id <0 ) - goto fail_rbd_dev; + goto free_device;sprintf (rbd_dev->name,RBD_DRV_NAME "%d" , rbd_dev->dev_id); rbd_dev->task_wq =alloc_ordered_workqueue ("%s-tasks" ,WQ_MEM_RECLAIM , rbd_dev->name);if (!rbd_dev->task_wq) - goto fail_dev_id; + goto remove_id;/* we have a ref from do_rbd_add() */ __module_get (THIS_MODULE );dout ("%s rbd_dev %p dev_id %d\n" , __func__, rbd_dev, rbd_dev->dev_id);return rbd_dev; - -fail_dev_id: + remove_id:ida_simple_remove (&rbd_dev_id_ida, rbd_dev->dev_id); -fail_rbd_dev: + free_device:rbd_dev_free (rbd_dev);return NULL ; }
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 15/47] block-rbd: Rename jump labels in rbd_dev_create()
Quoted 43 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:12:39 +0200Adjust jump labels according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/block/rbd.c +4
-6@@ -4930,23 +4930,22 @@ static struct rbd_device *rbd_dev_create(struct rbd_client *rbdc,minor_to_rbd_dev_id (1 <<MINORBITS ), GFP_KERNEL);if (rbd_dev->dev_id <0 ) - goto fail_rbd_dev; + goto free_device;sprintf (rbd_dev->name,RBD_DRV_NAME "%d" , rbd_dev->dev_id); rbd_dev->task_wq =alloc_ordered_workqueue ("%s-tasks" ,WQ_MEM_RECLAIM , rbd_dev->name);if (!rbd_dev->task_wq) - goto fail_dev_id; + goto remove_id;/* we have a ref from do_rbd_add() */ __module_get (THIS_MODULE );dout ("%s rbd_dev %p dev_id %d\n" , __func__, rbd_dev, rbd_dev->dev_id);return rbd_dev; - -fail_dev_id: + remove_id:ida_simple_remove (&rbd_dev_id_ida, rbd_dev->dev_id); -fail_rbd_dev: + free_device:rbd_dev_free (rbd_dev);return NULL ; } --
Quoted 2 lines
2.10.0
Really? I mean out_err -> free_device I can understand, but this?
Thanks,
Ilya
PATCH 16/47 block-rbd: Rename jump labels in rbd_dev_v1_header_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:15:44 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/rbd.c +4 -4
@@ -4352,17 +4352,17 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) ret =rbd_obj_read_sync (rbd_dev, rbd_dev->header_oid.name,0 , size, ondisk);if (ret <0 ) - goto out; + goto free_header;if ((size_t )ret < size) { ret = -ENXIO ;rbd_warn (rbd_dev,"short header read (want %zd got %d)" , size, ret); - goto out; + goto free_header; }if (!rbd_dev_ondisk_valid (ondisk)) { ret = -ENXIO ;rbd_warn (rbd_dev,"invalid header" ); - goto out; + goto free_header; } names_size =le64_to_cpu (ondisk->snap_names_len);
@@ -4371,7 +4371,7 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) }while (snap_count != want_count); ret =rbd_header_from_disk (rbd_dev, ondisk); -out: + free_header:kfree (ondisk);return ret;
Signature · 1 line
2.10.0
PATCH 17/47 block-rbd: Rename jump labels in rbd_init_disk()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:26:28 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/rbd.c +4 -4
@@ -4500,12 +4500,12 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) err =blk_mq_alloc_tag_set (&rbd_dev->tag_set);if (err) - goto out_disk; + goto put_disk; q =blk_mq_init_queue (&rbd_dev->tag_set);if (IS_ERR (q)) { err =PTR_ERR (q); - goto out_tag_set; + goto free_tag_set; }queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q);
@@ -4537,9 +4537,9 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) rbd_dev->disk = disk;return 0 ; -out_tag_set: + free_tag_set:blk_mq_free_tag_set (&rbd_dev->tag_set); -out_disk: + put_disk:put_disk (disk);return err; }
Signature · 1 line
2.10.0
PATCH 18/47 block-rbd: Fix jump targets in rbd_queue_workfn()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 18:28:23 +0200
* Adjust jump targets according to the current Linux coding style convention.
* Delete a duplicate check then at the end.
--- drivers/block/rbd.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
drivers/block/rbd.c +20 -17
@@ -4113,7 +4113,7 @@ static void rbd_queue_workfn(struct work_struct *work)dout ("%s: non-fs request type %d\n" , __func__, (int ) rq->cmd_type); result = -EIO ; - goto err; + goto end_request; }if (req_op (rq) ==REQ_OP_DISCARD )
@@ -4128,7 +4128,7 @@ static void rbd_queue_workfn(struct work_struct *work)if (!length) {dout ("%s: zero-length request\n" , __func__); result =0 ; - goto err_rq; + goto put_snap_context; }/* Only reads are allowed to a read-only device */
@@ -4136,7 +4136,7 @@ static void rbd_queue_workfn(struct work_struct *work)if (op_type !=OBJ_OP_READ ) {if (rbd_dev->mapping.read_only) { result = -EROFS ; - goto err_rq; + goto warn_more; }rbd_assert (rbd_dev->spec->snap_id ==CEPH_NOSNAP ); }
@@ -4151,14 +4151,14 @@ static void rbd_queue_workfn(struct work_struct *work)dout ("request for non-existent snapshot" );rbd_assert (rbd_dev->spec->snap_id !=CEPH_NOSNAP ); result = -ENXIO ; - goto err_rq; + goto warn_more; }if (offset && length >U64_MAX - offset +1 ) {rbd_warn (rbd_dev,"bad request range (%llu~%llu)" , offset, length); result = -EINVAL ; - goto err_rq;/* Shouldn't happen */ + goto warn_more;/* Shouldn't happen */ }blk_mq_start_request (rq);
@@ -4176,7 +4176,7 @@ static void rbd_queue_workfn(struct work_struct *work)rbd_warn (rbd_dev,"beyond EOD (%llu~%llu > %llu)" , offset, length, mapping_size); result = -EIO ; - goto err_rq; + goto warn_more; }if (must_be_locked) {
@@ -4189,7 +4189,7 @@ static void rbd_queue_workfn(struct work_struct *work) snapc);if (!img_request) { result = -ENOMEM ; - goto err_unlock; + goto unlock; } img_request->rq = rq; snapc =NULL ;/* img_request consumes a ref */
@@ -4201,27 +4201,30 @@ static void rbd_queue_workfn(struct work_struct *work) result =rbd_img_request_fill (img_request,OBJ_REQUEST_BIO , rq->bio);if (result) - goto err_img_request; + goto put_request; result =rbd_img_request_submit (img_request);if (result) - goto err_img_request; + goto put_request;if (must_be_locked)up_read (&rbd_dev->lock_rwsem);return ; - -err_img_request: + put_request:rbd_img_request_put (img_request); -err_unlock: + unlock:if (must_be_locked)up_read (&rbd_dev->lock_rwsem); -err_rq: -if (result) -rbd_warn (rbd_dev,"%s %llx at %llx result %d" , -obj_op_name (op_type), length, offset, result); + warn_more: +rbd_warn (rbd_dev, +"%s %llx at %llx result %d" , +obj_op_name (op_type), + length, + offset, + result); + put_snap_context:ceph_put_snap_context (snapc); -err: + end_request:blk_mq_end_request (rq, result); }
Signature · 1 line
2.10.0
PATCH 19/47 block-rbd: Rename a jump label in rbd_reregister_watch()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:31:04 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/rbd.c +3 -4
@@ -3950,7 +3950,7 @@ static void rbd_reregister_watch(struct work_struct *work)mutex_lock (&rbd_dev->watch_mutex);if (rbd_dev->watch_state !=RBD_WATCH_STATE_ERROR ) - goto fail_unlock; + goto unlock; ret =__rbd_register_watch (rbd_dev);if (ret) {
@@ -3959,7 +3959,7 @@ static void rbd_reregister_watch(struct work_struct *work)queue_delayed_work (rbd_dev->task_wq, &rbd_dev->watch_dwork,RBD_RETRY_DELAY ); - goto fail_unlock; + goto unlock; } rbd_dev->watch_state =RBD_WATCH_STATE_REGISTERED ;
@@ -3980,8 +3980,7 @@ static void rbd_reregister_watch(struct work_struct *work)up_write (&rbd_dev->lock_rwsem);wake_requests (rbd_dev, true);return ; - -fail_unlock: + unlock:mutex_unlock (&rbd_dev->watch_mutex);up_write (&rbd_dev->lock_rwsem); }
Signature · 1 line
2.10.0
PATCH 20/47 block-rbd: Rename a jump label in rbd_register_watch()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:33:00 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/rbd.c +2 -3
@@ -3900,12 +3900,11 @@ static int rbd_register_watch(struct rbd_device *rbd_dev)rbd_assert (rbd_dev->watch_state ==RBD_WATCH_STATE_UNREGISTERED ); ret =__rbd_register_watch (rbd_dev);if (ret) - goto out; + goto unlock; rbd_dev->watch_state =RBD_WATCH_STATE_REGISTERED ; rbd_dev->watch_cookie = rbd_dev->watch_handle->linger_id; - -out: + unlock:mutex_unlock (&rbd_dev->watch_mutex);return ret; }
Signature · 1 line
2.10.0
PATCH 21/47 block-rbd: Rename jump labels in rbd_try_lock()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:35:08 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/block/rbd.c +5 -7
@@ -3478,7 +3478,7 @@ static int rbd_try_lock(struct rbd_device *rbd_dev)if (ret) {if (ret >0 ) ret =0 ;/* have to request lock */ - goto out; + goto free_lockers; } rbd_warn(rbd_dev, "%s%llu seems dead, breaking lock",
@@ -3489,7 +3489,7 @@ static int rbd_try_lock(struct rbd_device *rbd_dev)if (ret) {rbd_warn (rbd_dev,"blacklist of %s%llu failed: %d" ,ENTITY_NAME (lockers[0 ].id.name), ret); - goto out; + goto free_lockers; } ret = ceph_cls_break_lock(&client->osdc, &rbd_dev->header_oid,
@@ -3497,13 +3497,11 @@ static int rbd_try_lock(struct rbd_device *rbd_dev) lockers[0 ].id.cookie, &lockers[0].id.name);if (ret && ret != -ENOENT ) - goto out; - -again: + goto free_lockers; + again:ceph_free_lockers (lockers, num_lockers); } - -out: + free_lockers:ceph_free_lockers (lockers, num_lockers);return ret; }
Signature · 1 line
2.10.0
PATCH 22/47 block-rbd: Rename a jump label in find_watcher()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:36:23 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -3440,13 +3440,13 @@ static int find_watcher(struct rbd_device *rbd_dev, rbd_dev, cid.gid, cid.handle);rbd_set_owner_cid (rbd_dev, &cid); ret =1 ; - goto out; + goto free_watchers; } }dout ("%s rbd_dev %p no watchers\n" , __func__, rbd_dev); ret =0 ; -out: +free_watchers:kfree (watchers);return ret; }
Signature · 1 line
2.10.0
PATCH 23/47 block-rbd: Rename jump labels in get_lock_owner_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:37:52 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/block/rbd.c +4 -6
@@ -3381,20 +3381,20 @@ static int get_lock_owner_info(struct rbd_device *rbd_dev,if (*num_lockers =0 ) {dout ("%s rbd_dev %p no lockers detected\n" , __func__, rbd_dev); - goto out; + goto free_tag; }if (strcmp (lock_tag,RBD_LOCK_TAG )) {rbd_warn (rbd_dev,"locked by external mechanism, tag %s" , lock_tag); ret = -EBUSY ; - goto out; + goto free_tag; }if (lock_type =CEPH_CLS_LOCK_SHARED ) {rbd_warn (rbd_dev,"shared lock type detected" ); ret = -EBUSY ; - goto out; + goto free_tag; } if (strncmp((*lockers)[0].id.cookie, RBD_LOCK_COOKIE_PREFIX,
@@ -3402,10 +3402,8 @@ static int get_lock_owner_info(struct rbd_device *rbd_dev,rbd_warn (rbd_dev,"locked by external mechanism, cookie %s" , (*lockers)[0 ].id.cookie); ret = -EBUSY ; - goto out; } - -out: + free_tag:kfree (lock_tag);return ret; }
Signature · 1 line
2.10.0
PATCH 24/47 block-rbd: Rename jump labels in rbd_request_lock()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:38:52 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/block/rbd.c +5 -7
@@ -3297,7 +3297,7 @@ static int rbd_request_lock(struct rbd_device *rbd_dev) &reply_pages, &reply_len);if (ret && ret != -ETIMEDOUT ) {rbd_warn (rbd_dev,"failed to request lock: %d" , ret); - goto out; + goto release_page_vector; }if (reply_len >0 && reply_len <=PAGE_SIZE ) {
@@ -3321,7 +3321,7 @@ static int rbd_request_lock(struct rbd_device *rbd_dev)rbd_warn (rbd_dev,"duplicate lock owners detected" ); ret = -EIO ; - goto out; + goto release_page_vector; } lock_owner_responded = true;
@@ -3342,14 +3342,12 @@ static int rbd_request_lock(struct rbd_device *rbd_dev)rbd_warn (rbd_dev,"no lock owners detected" ); ret = -ETIMEDOUT ; } - -out: + release_page_vector:ceph_release_page_vector (reply_pages,calc_pages_for (0 , reply_len));return ret; - -e_inval: + e_inval: ret = -EINVAL ; - goto out; + goto release_page_vector; }static void wake_requests (struct rbd_device *rbd_dev,bool wake_all)
Signature · 1 line
2.10.0
PATCH 25/47 block-rbd: Fix jump targets in rbd_img_parent_read()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:39:54 +0200
* Adjust jump targets according to the current Linux coding style convention.
* Delete a duplicate check then at the end.
--- drivers/block/rbd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/block/rbd.c +6 -6
@@ -3120,7 +3120,7 @@ static void rbd_img_parent_read(struct rbd_obj_request *obj_request) obj_request->length); result = -ENOMEM ;if (!img_request) - goto out_err; + goto status_indication;if (obj_request->type ==OBJ_REQUEST_BIO ) result = rbd_img_request_fill(img_request, OBJ_REQUEST_BIO,
@@ -3129,17 +3129,17 @@ static void rbd_img_parent_read(struct rbd_obj_request *obj_request) result =rbd_img_request_fill (img_request,OBJ_REQUEST_PAGES , obj_request->pages);if (result) - goto out_err; + goto put_request; img_request->callback = rbd_img_parent_read_callback; result =rbd_img_request_submit (img_request);if (result) - goto out_err; + goto put_request;return ; -out_err: -if (img_request) -rbd_img_request_put (img_request); + put_request: +rbd_img_request_put (img_request); + status_indication: obj_request->result = result; obj_request->xferred =0 ;obj_request_done_set (obj_request);
Signature · 1 line
2.10.0
PATCH 26/47 block-rbd: Rename a jump label in rbd_img_parent_read_callback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:40:45 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -3077,7 +3077,7 @@ static void rbd_img_parent_read_callback(struct rbd_img_request *img_request) obj_request->result = img_result;if (obj_request->result) - goto out; + goto callback;/* * We need to zero anything beyond the parent overlap
@@ -3099,7 +3099,7 @@ static void rbd_img_parent_read_callback(struct rbd_img_request *img_request) }else { obj_request->xferred = img_xferred; } -out: + callback:rbd_img_obj_request_read_callback (obj_request);rbd_obj_request_complete (obj_request); }
Signature · 1 line
2.10.0
PATCH 27/47 block-rbd: Rename a jump label in rbd_img_request_submit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:43:35 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/rbd.c +2 -3
@@ -3033,10 +3033,9 @@ static int rbd_img_request_submit(struct rbd_img_request *img_request)for_each_obj_request_safe (img_request, obj_request, next_obj_request) { ret =rbd_img_obj_request_submit (obj_request);if (ret) - goto out_put_ireq; + goto put_request; } - -out_put_ireq: + put_request:rbd_img_request_put (img_request);return ret; }
Signature · 1 line
2.10.0
PATCH 28/47 block-rbd: Refactor a jump target in rbd_img_obj_exists_submit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:44:30 +0200
Adjust a jump target so that a duplicate check can then be avoided at the end.
--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/rbd.c +3 -3
@@ -2920,7 +2920,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) stat_request =rbd_obj_request_create (obj_request->object_name,0 ,0 ,OBJ_REQUEST_PAGES );if (!stat_request) - goto out; + goto put_request;rbd_obj_request_get (obj_request); stat_request->obj_request = obj_request;
@@ -2932,7 +2932,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) stat_request->osd_req =rbd_osd_req_create (rbd_dev,OBJ_OP_READ ,1 , stat_request);if (!stat_request->osd_req) - goto out; + goto put_request; stat_request->callback = rbd_img_obj_exists_callback;osd_req_op_init (stat_request->osd_req,0 ,CEPH_OSD_OP_STAT ,0 );
@@ -2942,8 +2942,8 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) osdc = &rbd_dev->rbd_client->client->osdc; ret =rbd_obj_request_submit (osdc, stat_request); -out:if (ret) + put_request:rbd_obj_request_put (obj_request);return ret;
Signature · 1 line
2.10.0
Ilya Dryomov
maintainerRe: [PATCH 28/47] block-rbd: Refactor a jump target in rbd_img_obj_exists_submit()
Quoted 44 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:44:30 +0200Adjust a jump target so that a duplicate check can then be avoided at the end.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/block/rbd.c +3
-4@@ -2920,7 +2920,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) stat_request =rbd_obj_request_create (obj_request->object_name,0 ,0 ,OBJ_REQUEST_PAGES );if (!stat_request) - goto out; + goto put_request;rbd_obj_request_get (obj_request); stat_request->obj_request = obj_request;@@ -2932,7 +2932,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) stat_request->osd_req =rbd_osd_req_create (rbd_dev,OBJ_OP_READ ,1 , stat_request);if (!stat_request->osd_req) - goto out; + goto put_request; stat_request->callback = rbd_img_obj_exists_callback;osd_req_op_init (stat_request->osd_req,0 ,CEPH_OSD_OP_STAT ,0 );@@ -2942,8 +2942,8 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) osdc = &rbd_dev->rbd_client->client->osdc; ret =rbd_obj_request_submit (osdc, stat_request); -out:if (ret) + put_request:rbd_obj_request_put (obj_request);return ret; --
Quoted 1 line
2.10.0
Don't do this. goto into an if block is rarely a good idea, more so when you are attempting to micro-optimize a very cold error path.
Thanks,
Ilya
PATCH 29/47 block-rbd: Delete an unnecessary initialisation in rbd_img_obj_exists_submit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:45:29 +0200
The local variable "pages" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
@@ -2897,7 +2897,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request)struct rbd_obj_request *stat_request;struct rbd_device *rbd_dev;struct ceph_osd_client *osdc; -struct page **pages =NULL ; +struct page **pages;u32 page_count;size_t size;int ret;
Signature · 1 line
2.10.0
PATCH 30/47 block-rbd: Refactor a jump target in rbd_img_obj_exists_callback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:46:43 +0200
Adjust a jump target so that a duplicate check can then be avoided at the end.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -2879,7 +2879,7 @@ static void rbd_img_obj_exists_callback(struct rbd_obj_request *obj_request)obj_request_existence_set (orig_request, false); }else if (result) { orig_request->result = result; - goto out; + goto complete_request; }/*
@@ -2887,8 +2887,8 @@ static void rbd_img_obj_exists_callback(struct rbd_obj_request *obj_request)* whether the target object exists. */ orig_request->result =rbd_img_obj_request_submit (orig_request); -out:if (orig_request->result) + complete_request:rbd_obj_request_complete (orig_request); }
Signature · 1 line
2.10.0
PATCH 31/47 block-rbd: Fix three jump targets in rbd_img_obj_parent_read_full()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:48:46 +0200
* Adjust jump targets according to the current Linux coding style convention.
* Delete two duplicate checks then at the end.
---
I find that this function implementation needs another close look. It seems that four lines can not be executed according to the shown control flow at the moment.
How do you think about to avoid "dead" source code there anyhow?
drivers/block/rbd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/block/rbd.c +8 -8
@@ -2789,18 +2789,18 @@ static int rbd_img_obj_parent_read_full(struct rbd_obj_request *obj_request)if (IS_ERR (pages)) { result =PTR_ERR (pages); pages =NULL ; - goto out_err; + goto status_indication; } result = -ENOMEM ; parent_request =rbd_parent_request_create (obj_request, img_offset, length);if (!parent_request) - goto out_err; + goto release_page_vector; result =rbd_img_request_fill (parent_request,OBJ_REQUEST_PAGES , pages);if (result) - goto out_err; + goto put_request; parent_request->copyup_pages = pages; parent_request->copyup_page_count = page_count;
@@ -2813,11 +2813,11 @@ static int rbd_img_obj_parent_read_full(struct rbd_obj_request *obj_request) parent_request->copyup_page_count =0 ; parent_request->obj_request =NULL ;rbd_obj_request_put (obj_request); -out_err: -if (pages) -ceph_release_page_vector (pages, page_count); -if (parent_request) -rbd_img_request_put (parent_request); + put_request: +rbd_img_request_put (parent_request); + release_page_vector: +ceph_release_page_vector (pages, page_count); + status_indication: obj_request->result = result; obj_request->xferred =0 ;obj_request_done_set (obj_request);
Signature · 1 line
2.10.0
PATCH 32/47 block-rbd: Rename a jump label in rbd_img_obj_parent_read_full_callback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:49:33 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/rbd.c +3 -3
@@ -2687,7 +2687,7 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request) }if (img_result) - goto out_err; + goto status_indication;/* * The original osd request is of no use to use any more.
@@ -2698,7 +2698,7 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request) img_result = -ENOMEM ; osd_req =rbd_osd_req_create_copyup (orig_request);if (!osd_req) - goto out_err; + goto status_indication;rbd_osd_req_destroy (orig_request->osd_req); orig_request->osd_req = osd_req; orig_request->copyup_pages = pages;
@@ -2721,7 +2721,7 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request) img_result =rbd_obj_request_submit (osdc, orig_request);if (!img_result)return ; -out_err: + status_indication:/* Record the error code and complete the request */ orig_request->result = img_result;
Signature · 1 line
2.10.0
PATCH 33/47 block-rbd: Adjust the position of a jump label in rbd_img_request_fill()
In reply to SF Markus ElfringFrom a0cfdf15bae448d9a0e2d5d6480c70cfa3f77322 Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:50:43 +0200
Subject: [PATCH 33/47] block-rbd: Adjust the position of a jump label in
rbd_img_request_fill()
Add a space character before a single jump label in this function according to the current Linux coding style convention.
--- drivers/block/rbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/rbd.c +1 -2
@@ -2588,8 +2588,7 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request, }return 0 ; - -out_unwind: + out_unwind:for_each_obj_request_safe (img_request, obj_request, next_obj_request)rbd_img_obj_request_del (img_request, obj_request);
Signature · 1 line
2.10.0
PATCH 34/47 block-rbd: Rename a jump label in rbd_img_obj_callback()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:51:29 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -2394,7 +2394,7 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request)spin_lock_irq (&img_request->completion_lock);if (which != img_request->next_completion) - goto out; + goto unlock;for_each_obj_request_from (img_request, obj_request) {rbd_assert (more);
@@ -2408,7 +2408,7 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request)rbd_assert (more ^ (which == img_request->obj_request_count)); img_request->next_completion = which; -out: + unlock:spin_unlock_irq (&img_request->completion_lock);rbd_img_request_put (img_request);
Signature · 1 line
2.10.0
PATCH 35/47 block-rbd: Rename jump labels in rbd_osd_req_create_copyup()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:53:26 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/block/rbd.c +4 -5
@@ -2046,7 +2046,7 @@ rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request) osd_req =ceph_osdc_alloc_request (osdc, snapc, num_osd_ops, false,GFP_NOIO );if (!osd_req) - goto fail; + goto put_request; osd_req->r_flags =CEPH_OSD_FLAG_WRITE |CEPH_OSD_FLAG_ONDISK ; osd_req->r_callback = rbd_osd_req_callback;
@@ -2055,14 +2055,13 @@ rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request) osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id;if (ceph_oid_aprintf (&osd_req->r_base_oid,GFP_NOIO ,"%s" , obj_request->object_name)) - goto fail; + goto put_request;if (ceph_osdc_alloc_messages (osd_req,GFP_NOIO )) - goto fail; + goto put_request;return osd_req; - -fail: + put_request:ceph_osdc_put_request (osd_req);return NULL ; }
Signature · 1 line
2.10.0
PATCH 36/47 block-rbd: Rename jump labels in rbd_osd_req_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:54:39 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/block/rbd.c +4 -5
@@ -1988,7 +1988,7 @@ static struct ceph_osd_request *rbd_osd_req_create( osd_req =ceph_osdc_alloc_request (osdc, snapc, num_ops, false,GFP_NOIO );if (!osd_req) - goto fail; + goto put_request;if (op_type ==OBJ_OP_WRITE || op_type ==OBJ_OP_DISCARD ) osd_req->r_flags =CEPH_OSD_FLAG_WRITE |CEPH_OSD_FLAG_ONDISK ;
@@ -2001,14 +2001,13 @@ static struct ceph_osd_request *rbd_osd_req_create( osd_req->r_base_oloc.pool = rbd_dev->layout.pool_id;if (ceph_oid_aprintf (&osd_req->r_base_oid,GFP_NOIO ,"%s" , obj_request->object_name)) - goto fail; + goto put_request;if (ceph_osdc_alloc_messages (osd_req,GFP_NOIO )) - goto fail; + goto put_request;return osd_req; - -fail: + put_request:ceph_osdc_put_request (osd_req);return NULL ; }
Signature · 1 line
2.10.0
PATCH 37/47 block-rbd: Rename a jump label in bio_chain_clone_range()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:56:37 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/rbd.c +3 -3
@@ -1421,12 +1421,12 @@ static struct bio *bio_chain_clone_range(struct bio **bio_src,if (!bi) {rbd_warn (NULL ,"bio_chain exhausted with %u left" , len); - goto out_err;/* EINVAL; ran out of bio's */ + goto put_chain;/* EINVAL; ran out of bio's */ } bi_size = min_t(unsigned int, bi->bi_iter.bi_size - off, len); bio =bio_clone_range (bi, off, bi_size, gfpmask);if (!bio) - goto out_err;/* ENOMEM */ + goto put_chain;/* ENOMEM */ *end = bio; end = &bio->bi_next;
@@ -1442,7 +1442,7 @@ static struct bio *bio_chain_clone_range(struct bio **bio_src, *offset = off;return chain; -out_err: + put_chain:bio_chain_put (chain);return NULL ;
Signature · 1 line
2.10.0
PATCH 38/47 block-rbd: Rename jump labels in rbd_client_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:57:19 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/block/rbd.c +6 -6
@@ -718,19 +718,19 @@ static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts)dout ("%s:\n" , __func__); rbdc =kmalloc (sizeof (struct rbd_client ),GFP_KERNEL );if (!rbdc) - goto out_opt; + goto check_input;kref_init (&rbdc->kref);INIT_LIST_HEAD (&rbdc->node); rbdc->client =ceph_create_client (ceph_opts, rbdc,0 ,0 );if (IS_ERR (rbdc->client)) - goto out_rbdc; + goto free_rbdc; ceph_opts =NULL ;/* Now rbdc->client is responsible for ceph_opts */ ret =ceph_open_session (rbdc->client);if (ret <0 ) - goto out_client; + goto destroy_client;spin_lock (&rbd_client_list_lock);list_add_tail (&rbdc->node, &rbd_client_list);
@@ -739,11 +739,11 @@ static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts)dout ("%s: rbdc %p\n" , __func__, rbdc);return rbdc; -out_client: + destroy_client:ceph_destroy_client (rbdc->client); -out_rbdc: + free_rbdc:kfree (rbdc); -out_opt: + check_input:if (ceph_opts)ceph_destroy_options (ceph_opts);dout ("%s: error %d\n" , __func__, ret);
Signature · 1 line
2.10.0
PATCH 39/47 block-rbd: Rename a jump label in rbd_ioctl_set_ro()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 19:58:22 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/rbd.c +2 -3
@@ -654,15 +654,14 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg)/* prevent others open this device */ if (rbd_dev->open_count >1 ) { ret = -EBUSY ; - goto out; + goto unlock; }if (rbd_dev->mapping.read_only != ro) { rbd_dev->mapping.read_only = ro; ro_changed = true; } - -out: + unlock:spin_unlock_irq (&rbd_dev->lock);/* set_disk_ro() may sleep, so call it after releasing rbd_dev->lock */ if (ret =0 && ro_changed)
Signature · 1 line
2.10.0
PATCH 40/47 block-rbd: One function call less in rbd_dev_probe_parent() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:00:08 +0200
The rbd_dev_destroy() function was called in two cases by the rbd_dev_probe_parent() function during error handling even if the passed variable contained a null pointer.
* Adjust jump targets according to the current Linux coding style convention.
* Delete an initialisation for the variable "parent" at the beginning which became unnecessary with this refactoring.
--- drivers/block/rbd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/block/rbd.c +7 -7
@@ -5950,7 +5950,7 @@ out_err:*/ static int rbd_dev_probe_parent (struct rbd_device *rbd_dev,int depth) { -struct rbd_device *parent =NULL ; +struct rbd_device *parent;int ret;if (!rbd_dev->parent_spec)
@@ -5959,13 +5959,13 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev, int depth)if (++depth >RBD_MAX_PARENT_CHAIN_LEN ) {pr_info ("parent chain is too long (%d)\n" , depth); ret = -EINVAL ; - goto out_err; + goto unparent_device; } parent =__rbd_dev_create (rbd_dev->rbd_client, rbd_dev->parent_spec);if (!parent) { ret = -ENOMEM ; - goto out_err; + goto unparent_device; }/*
@@ -5977,15 +5977,15 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev, int depth) ret =rbd_dev_image_probe (parent, depth);if (ret <0 ) - goto out_err; + goto destroy_device; rbd_dev->parent = parent;atomic_set (&rbd_dev->parent_ref,1 );return 0 ; - -out_err: -rbd_dev_unparent (rbd_dev); + destroy_device:rbd_dev_destroy (parent); + unparent_device: +rbd_dev_unparent (rbd_dev);return ret; }
Signature · 1 line
2.10.0
PATCH 41/47 block-rbd: Rename jump labels in rbd_dev_device_setup()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:01:03 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/block/rbd.c +8 -9
@@ -6002,7 +6002,7 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)if (!single_major) { ret =register_blkdev (0 , rbd_dev->name);if (ret <0 ) - goto err_out_unlock; + goto unlock; rbd_dev->major = ret; rbd_dev->minor =0 ;
@@ -6015,11 +6015,11 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev) ret =rbd_init_disk (rbd_dev);if (ret) - goto err_out_blkdev; + goto check_single; ret =rbd_dev_mapping_set (rbd_dev);if (ret) - goto err_out_disk; + goto free_disk;set_capacity (rbd_dev->disk, rbd_dev->mapping.size /SECTOR_SIZE );set_disk_ro (rbd_dev->disk, rbd_dev->mapping.read_only);
@@ -6027,7 +6027,7 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)dev_set_name (&rbd_dev->dev,"%d" , rbd_dev->dev_id); ret =device_add (&rbd_dev->dev);if (ret) - goto err_out_mapping; + goto clear_mapping;/* Everything's ready. Announce the disk to the world. */
@@ -6044,15 +6044,14 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev) rbd_dev->header.features);return ret; - -err_out_mapping: + clear_mapping:rbd_dev_mapping_clear (rbd_dev); -err_out_disk: + free_disk:rbd_free_disk (rbd_dev); -err_out_blkdev: + check_single:if (!single_major)unregister_blkdev (rbd_dev->major, rbd_dev->name); -err_out_unlock: + unlock:up_write (&rbd_dev->header_rwsem);return ret; }
Signature · 1 line
2.10.0
PATCH 42/47 block-rbd: Rename jump labels in rbd_dev_image_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:02:16 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/block/rbd.c +9 -10
@@ -6108,7 +6108,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) ret =rbd_dev_header_name (rbd_dev);if (ret) - goto err_out_format; + goto status_indication;if (!depth) { ret =rbd_register_watch (rbd_dev);
@@ -6117,13 +6117,13 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)pr_info ("image %s/%s does not exist\n" , rbd_dev->spec->pool_name, rbd_dev->spec->image_name); - goto err_out_format; + goto status_indication; } } ret =rbd_dev_header_info (rbd_dev);if (ret) - goto err_out_watch; + goto check_input;/* * If this image is the one being mapped, we have pool name and
@@ -6141,13 +6141,13 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) rbd_dev->spec->pool_name, rbd_dev->spec->image_name, rbd_dev->spec->snap_name); - goto err_out_probe; + goto unprobe_device; }if (rbd_dev->header.features &RBD_FEATURE_LAYERING ) { ret =rbd_dev_v2_parent_info (rbd_dev);if (ret) - goto err_out_probe; + goto unprobe_device;/* * Need to warn users if this image is the one being
@@ -6160,18 +6160,17 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) ret =rbd_dev_probe_parent (rbd_dev, depth);if (ret) - goto err_out_probe; + goto unprobe_device;dout ("discovered format %u image, header name is %s\n" , rbd_dev->image_format, rbd_dev->header_oid.name);return 0 ; - -err_out_probe: + unprobe_device:rbd_dev_unprobe (rbd_dev); -err_out_watch: + check_input:if (!depth)rbd_unregister_watch (rbd_dev); -err_out_format: + status_indication: rbd_dev->image_format =0 ;kfree (rbd_dev->spec->image_id); rbd_dev->spec->image_id =NULL ;
Signature · 1 line
2.10.0
PATCH 43/47 block-rbd: Rename jump labels in do_rbd_add()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:03:34 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/block/rbd.c +12 -13
@@ -6195,12 +6195,12 @@ static ssize_t do_rbd_add(struct bus_type *bus,/* parse add command */ rc =rbd_add_parse_args (buf, &ceph_opts, &rbd_opts, &spec);if (rc <0 ) - goto out; + goto put_module; rbdc =rbd_get_client (ceph_opts);if (IS_ERR (rbdc)) { rc =PTR_ERR (rbdc); - goto err_out_args; + goto put_spec; }/* pick the pool */
@@ -6208,14 +6208,14 @@ static ssize_t do_rbd_add(struct bus_type *bus,if (rc <0 ) {if (rc == -ENOENT )pr_info ("pool %s does not exist\n" , spec->pool_name); - goto err_out_client; + goto put_client; } spec->pool_id = (u64 )rc; rbd_dev =rbd_dev_create (rbdc, spec, rbd_opts);if (!rbd_dev) { rc = -ENOMEM ; - goto err_out_client; + goto put_client; } rbdc =NULL ;/* rbd_dev now owns this */ spec =NULL ;/* rbd_dev now owns this */
@@ -6224,14 +6224,14 @@ static ssize_t do_rbd_add(struct bus_type *bus, rbd_dev->config_info =kstrdup (buf,GFP_KERNEL );if (!rbd_dev->config_info) { rc = -ENOMEM ; - goto err_out_rbd_dev; + goto destroy_device; }down_write (&rbd_dev->header_rwsem); rc =rbd_dev_image_probe (rbd_dev,0 );if (rc <0 ) {up_write (&rbd_dev->header_rwsem); - goto err_out_rbd_dev; + goto destroy_device; }/* If we are mapping a snapshot it must be marked read-only */
@@ -6250,22 +6250,21 @@ static ssize_t do_rbd_add(struct bus_type *bus,*/ rbd_unregister_watch (rbd_dev);rbd_dev_image_release (rbd_dev); - goto out; + goto put_module; } rc = count; -out: + put_module:module_put (THIS_MODULE );return rc; - -err_out_rbd_dev: + destroy_device:rbd_dev_destroy (rbd_dev); -err_out_client: + put_client:rbd_put_client (rbdc); -err_out_args: + put_spec:rbd_spec_put (spec);kfree (rbd_opts); - goto out; + goto put_module; } static ssize_t rbd_add(struct bus_type *bus,
Signature · 1 line
2.10.0
PATCH 44/47 block-rbd: Delete an unnecessary initialisation in do_rbd_add()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:04:31 +0200
The local variable "rbd_dev" will be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
@@ -6181,7 +6181,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, const char *buf, size_t count) { -struct rbd_device *rbd_dev =NULL ; +struct rbd_device *rbd_dev;struct ceph_options *ceph_opts =NULL ;struct rbd_options *rbd_opts =NULL ;struct rbd_spec *spec =NULL ;
Signature · 1 line
2.10.0
PATCH 45/47 block-rbd: Rename a jump label in rbd_slab_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:05:42 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/rbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/rbd.c +2 -2
@@ -6454,14 +6454,14 @@ static int rbd_slab_init(void)rbd_assert (!rbd_obj_request_cache); rbd_obj_request_cache =KMEM_CACHE (rbd_obj_request,0 );if (!rbd_obj_request_cache) - goto out_err; + goto destroy_cache;rbd_assert (!rbd_segment_name_cache); rbd_segment_name_cache =kmem_cache_create ("rbd_segment_name" ,CEPH_MAX_OID_NAME_LEN +1 ,1 ,0 ,NULL );if (rbd_segment_name_cache)return 0 ; -out_err: + destroy_cache:kmem_cache_destroy (rbd_obj_request_cache); rbd_obj_request_cache =NULL ;
Signature · 1 line
2.10.0
PATCH 46/47 block-rbd: Rename jump labels in rbd_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:06:54 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/block/rbd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/block/rbd.c +6 -7
@@ -6506,20 +6506,20 @@ static int __init rbd_init(void) rbd_wq =alloc_workqueue (RBD_DRV_NAME ,WQ_MEM_RECLAIM ,0 );if (!rbd_wq) { rc = -ENOMEM ; - goto err_out_slab; + goto exit_slab; }if (single_major) { rbd_major =register_blkdev (0 ,RBD_DRV_NAME );if (rbd_major <0 ) { rc = rbd_major; - goto err_out_wq; + goto destroy_workqueue; } } rc =rbd_sysfs_init ();if (rc) - goto err_out_blkdev; + goto check_single;if (single_major)pr_info ("loaded (major %d)\n" , rbd_major);
@@ -6527,13 +6527,12 @@ static int __init rbd_init(void)pr_info ("loaded\n" );return 0 ; - -err_out_blkdev: + check_single:if (single_major)unregister_blkdev (rbd_major,RBD_DRV_NAME ); -err_out_wq: + destroy_workqueue:destroy_workqueue (rbd_wq); -err_out_slab: + exit_slab:rbd_slab_exit ();return rc; }
Signature · 1 line
2.10.0
PATCH 47/47 block-rbd: Delete unwanted spaces behind usages of the sizeof operator
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 20:10:13 +0200
* Replace the source code "sizeof (" by "sizeof("
according to the Linux coding style convention.
* Improve indentation at some places.
--- drivers/block/rbd.c | 112 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 48 deletions(-)
drivers/block/rbd.c +64 -48
@@ -101,7 +101,7 @@ static int atomic_dec_return_safe(atomic_t *v)#define RBD_SNAP_DEV_NAME_PREFIX "snap_"#define RBD_MAX_SNAP_NAME_LEN \ - (NAME_MAX - (sizeof (RBD_SNAP_DEV_NAME_PREFIX) - 1)) + (NAME_MAX - (sizeof(RBD_SNAP_DEV_NAME_PREFIX) - 1))#define RBD_MAX_SNAP_COUNT 510/* allows max snapc to fit in 4KB */
@@ -110,7 +110,7 @@ static int atomic_dec_return_safe(atomic_t *v)#define BAD_SNAP_INDEX U32_MAX/* invalid index into snap array */ /* This allows a single page to hold an image name sent by OSD */ -#define RBD_IMAGE_NAME_LEN_MAX (PAGE_SIZE - sizeof (__le32) - 1) +#define RBD_IMAGE_NAME_LEN_MAX (PAGE_SIZE - sizeof(__le32) - 1)#define RBD_IMAGE_ID_LEN_MAX 64#define RBD_OBJ_PREFIX_LEN_MAX 64
@@ -931,7 +931,7 @@ static bool rbd_dev_ondisk_valid(struct rbd_image_header_ondisk *ondisk)u32 snap_count;/* The header has to start with the magic rbd header text */ -if (memcmp (&ondisk->text,RBD_HEADER_TEXT ,sizeof (RBD_HEADER_TEXT ))) +if (memcmp (&ondisk->text,RBD_HEADER_TEXT ,sizeof (RBD_HEADER_TEXT )))return false;/* The bio layer requires at least sector-sized I/O */
@@ -941,7 +941,7 @@ static bool rbd_dev_ondisk_valid(struct rbd_image_header_ondisk *ondisk)/* If we use u64 in a few spots we may be able to loosen this */ -if (ondisk->options.order >8 *sizeof (int ) -1 ) +if (ondisk->options.order >8 *sizeof (int ) -1 )return false;/*
@@ -949,15 +949,15 @@ static bool rbd_dev_ondisk_valid(struct rbd_image_header_ondisk *ondisk)* that limits the number of snapshots. */ snap_count =le32_to_cpu (ondisk->snap_count); - size =SIZE_MAX -sizeof (struct ceph_snap_context ); -if (snap_count > size /sizeof (__le64)) + size =SIZE_MAX -sizeof (struct ceph_snap_context ); +if (snap_count > size /sizeof (__le64))return false;/* * Not only that, but the size of the entire the snapshot * header must also be representable in a size_t. */ - size -= snap_count *sizeof (__le64); + size -= snap_count *sizeof (__le64);if ((u64 ) size <le64_to_cpu (ondisk->snap_names_len))return false;
@@ -987,7 +987,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,size_t len; len =strnlen (ondisk->object_prefix, -sizeof (ondisk->object_prefix)); +sizeof (ondisk->object_prefix)); object_prefix =kmalloc (len +1 ,GFP_KERNEL );if (!object_prefix)return -ENOMEM ;
@@ -1121,7 +1121,7 @@ static u32 rbd_dev_snap_index(struct rbd_device *rbd_dev, u64 snap_id)u64 *found; found =bsearch (&snap_id, &snapc->snaps, snapc->num_snaps, -sizeof (snap_id), snapid_compare_reverse); +sizeof (snap_id), snapid_compare_reverse);return found ? (u32)(found - &snapc->snaps[0 ]) :BAD_SNAP_INDEX ; }
@@ -2906,7 +2906,7 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request)* le32 tv_nsec; * } mtime; */ - size =sizeof (__le64) +sizeof (__le32) +sizeof (__le32); + size =sizeof (__le64) +sizeof (__le32) +sizeof (__le32); page_count = (u32 )calc_pages_for (0 , size); pages =ceph_alloc_page_vector (page_count,GFP_KERNEL );if (IS_ERR (pages))
@@ -4023,7 +4023,7 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,if (outbound_size) {struct ceph_pagelist *pagelist; - pagelist =kmalloc (sizeof (*pagelist),GFP_NOFS ); + pagelist =kmalloc (sizeof (*pagelist),GFP_NOFS );if (!pagelist) goto out;
@@ -4332,8 +4332,8 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev)kfree (ondisk); - size =sizeof (*ondisk); - size += snap_count *sizeof (struct rbd_image_snap_ondisk ); + size =sizeof (*ondisk); + size += snap_count *sizeof (struct rbd_image_snap_ondisk ); size += names_size; ondisk =kmalloc (size,GFP_KERNEL );if (!ondisk)
@@ -4797,7 +4797,7 @@ static struct rbd_spec *rbd_spec_alloc(void) {struct rbd_spec *spec; - spec =kzalloc (sizeof (*spec),GFP_KERNEL ); + spec =kzalloc (sizeof (*spec),GFP_KERNEL );if (!spec)return NULL ;
@@ -4961,14 +4961,18 @@ static int _rbd_dev_v2_snap_size(struct rbd_device *rbd_dev, u64 snap_id,__le64 size; } __attribute__ ((packed)) size_buf = { 0 }; - ret =rbd_obj_method_sync (rbd_dev, rbd_dev->header_oid.name, -"rbd" ,"get_size" , - &snapid,sizeof (snapid), - &size_buf,sizeof (size_buf)); + ret =rbd_obj_method_sync (rbd_dev, + rbd_dev->header_oid.name, +"rbd" , +"get_size" , + &snapid, +sizeof (snapid), + &size_buf, +sizeof (size_buf));dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 )return ret; -if (ret <sizeof (size_buf)) +if (ret <sizeof (size_buf))return -ERANGE ;if (order) {
@@ -5036,14 +5040,18 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id,u64 unsup;int ret; - ret =rbd_obj_method_sync (rbd_dev, rbd_dev->header_oid.name, -"rbd" ,"get_features" , - &snapid,sizeof (snapid), - &features_buf,sizeof (features_buf)); + ret =rbd_obj_method_sync (rbd_dev, + rbd_dev->header_oid.name, +"rbd" , +"get_features" , + &snapid, +sizeof (snapid), + &features_buf, +sizeof (features_buf));dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 )return ret; -if (ret <sizeof (features_buf)) +if (ret <sizeof (features_buf))return -ERANGE ; unsup =le64_to_cpu (features_buf.incompat) & ~RBD_FEATURES_SUPPORTED ;
@@ -5087,10 +5095,10 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)if (!parent_spec)return -ENOMEM ; - size =sizeof (__le64) +/* pool_id */ -sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX +/* image_id */ -sizeof (__le64) +/* snap_id */ -sizeof (__le64);/* overlap */ + size =sizeof (__le64) +/* pool_id */ +sizeof (__le32) +RBD_IMAGE_ID_LEN_MAX +/* image_id */ +sizeof (__le64) +/* snap_id */ +sizeof (__le64);/* overlap */ reply_buf =kmalloc (size,GFP_KERNEL );if (!reply_buf) { ret = -ENOMEM ;
@@ -5098,10 +5106,14 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) } snapid =cpu_to_le64 (rbd_dev->spec->snap_id); - ret =rbd_obj_method_sync (rbd_dev, rbd_dev->header_oid.name, -"rbd" ,"get_parent" , - &snapid,sizeof (snapid), - reply_buf, size); + ret =rbd_obj_method_sync (rbd_dev, + rbd_dev->header_oid.name, +"rbd" , +"get_parent" , + &snapid, +sizeof (snapid), + reply_buf, + size);dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) goto free_buffer;
@@ -5194,7 +5206,7 @@ static int rbd_dev_v2_striping_info(struct rbd_device *rbd_dev)__le64 stripe_unit;__le64 stripe_count; } __attribute__ ((packed)) striping_info_buf = { 0 }; -size_t size =sizeof (striping_info_buf); +size_t size =sizeof (striping_info_buf);void *p;u64 obj_size;u64 stripe_unit;
@@ -5253,7 +5265,7 @@ static char *rbd_dev_image_name(struct rbd_device *rbd_dev)rbd_assert (!rbd_dev->spec->image_name); len =strlen (rbd_dev->spec->image_id); - image_id_size =sizeof (__le32) + len; + image_id_size =sizeof (__le32) + len; image_id =kmalloc (image_id_size,GFP_KERNEL );if (!image_id)return NULL ;
@@ -5262,7 +5274,7 @@ static char *rbd_dev_image_name(struct rbd_device *rbd_dev) end = image_id + image_id_size;ceph_encode_string (&p, end, rbd_dev->spec->image_id, (u32 )len); - size =sizeof (__le32) +RBD_IMAGE_NAME_LEN_MAX ; + size =sizeof (__le32) +RBD_IMAGE_NAME_LEN_MAX ; reply_buf =kmalloc (size,GFP_KERNEL );if (!reply_buf) goto free_id;
@@ -5443,8 +5455,8 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev)* For now we have a fixed upper limit on the number we're * prepared to receive. */ - size =sizeof (__le64) +sizeof (__le32) + -RBD_MAX_SNAP_COUNT *sizeof (__le64); + size =sizeof (__le64) +sizeof (__le32) + +RBD_MAX_SNAP_COUNT *sizeof (__le64); reply_buf =kzalloc (size,GFP_KERNEL );if (!reply_buf)return -ENOMEM ;
@@ -5468,12 +5480,12 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev)* make sure the computed size of the snapshot context we * allocate is representable in a size_t. */ -if (snap_count > (SIZE_MAX -sizeof (struct ceph_snap_context )) - /sizeof (u64)) { +if (snap_count > (SIZE_MAX -sizeof (struct ceph_snap_context )) + /sizeof (u64)) { ret = -EINVAL ; goto free_buffer; } -if (!ceph_has_room (&p, end, snap_count *sizeof (__le64))) +if (!ceph_has_room (&p, end, snap_count *sizeof (__le64))) goto free_buffer; ret =0 ;
@@ -5508,16 +5520,20 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev,void *end;char *snap_name; - size =sizeof (__le32) +RBD_MAX_SNAP_NAME_LEN ; + size =sizeof (__le32) +RBD_MAX_SNAP_NAME_LEN ; reply_buf =kmalloc (size,GFP_KERNEL );if (!reply_buf)return ERR_PTR (-ENOMEM ); snapid =cpu_to_le64 (snap_id); - ret =rbd_obj_method_sync (rbd_dev, rbd_dev->header_oid.name, -"rbd" ,"get_snapshot_name" , - &snapid,sizeof (snapid), - reply_buf, size); + ret =rbd_obj_method_sync (rbd_dev, + rbd_dev->header_oid.name, +"rbd" , +"get_snapshot_name" , + &snapid, +sizeof (snapid), + reply_buf, + size);dout ("%s: rbd_obj_method_sync returned %d\n" , __func__, ret);if (ret <0 ) { snap_name =ERR_PTR (ret);
@@ -5728,7 +5744,7 @@ static int rbd_add_parse_args(const char *buf, len =next_token (&buf);if (!len) { buf =RBD_SNAP_HEAD_NAME ;/* No snapshot supplied */ - len =sizeof (RBD_SNAP_HEAD_NAME ) -1 ; + len =sizeof (RBD_SNAP_HEAD_NAME ) -1 ; }else if (len >RBD_MAX_SNAP_NAME_LEN ) { ret = -ENAMETOOLONG ; goto free_options;
@@ -5741,7 +5757,7 @@ static int rbd_add_parse_args(const char *buf,/* Initialize all rbd options to the defaults */ - rbd_opts =kzalloc (sizeof (*rbd_opts),GFP_KERNEL ); + rbd_opts =kzalloc (sizeof (*rbd_opts),GFP_KERNEL );if (!rbd_opts) goto status_indication;
@@ -5906,7 +5922,7 @@ static void rbd_dev_unprobe(struct rbd_device *rbd_dev)kfree (header->snap_sizes);kfree (header->snap_names);kfree (header->object_prefix); -memset (header,0 ,sizeof (*header)); +memset (header,0 ,sizeof (*header)); }static int rbd_dev_v2_header_onetime (struct rbd_device *rbd_dev)
Signature · 1 line
2.10.0
Re: [PATCH 00/47] RADOS Block Device: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 54 lines
Date: Mon, 12 Sep 2016 20:35:20 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (47):
Usekmalloc_array()inrbd_header_from_disk()
Less function calls inrbd_header_from_disk()after error detection Adjust the position of a jump label inrbd_header_from_disk()Refactor two calls for memory allocations inrbd_dev_image_id()One function call less inrbd_dev_image_id()after error detection Rename jump labels inrbd_add_parse_args()
Rename a jump label inrbd_dev_v2_snap_name()
Rename jump labels inrbd_dev_v2_snap_context()
Rename a jump label inrbd_spec_fill_names()
One function call less inrbd_dev_image_name()after error detection Delete three unnecessary initialisations inrbd_dev_image_name()One function call less inrbd_dev_v2_parent_info()after error detection Delete an unnecessary initialisation inrbd_dev_v2_parent_info()Rename a jump label inrbd_dev_v2_object_prefix()
Rename jump labels inrbd_dev_create()
Rename jump labels inrbd_dev_v1_header_info()
Rename jump labels inrbd_init_disk()
Fix jump targets inrbd_queue_workfn()
Rename a jump label inrbd_reregister_watch()
Rename a jump label inrbd_register_watch()
Rename jump labels inrbd_try_lock()
Rename a jump label infind_watcher()
Rename jump labels inget_lock_owner_info()
Rename jump labels inrbd_request_lock()
Fix jump targets inrbd_img_parent_read()
Rename a jump label inrbd_img_parent_read_callback()
Rename a jump label inrbd_img_request_submit()
Refactor a jump target inrbd_img_obj_exists_submit()
Delete an unnecessary initialisation inrbd_img_obj_exists_submit()Refactor a jump target inrbd_img_obj_exists_callback()
Fix three jump targets inrbd_img_obj_parent_read_full()Rename a jump label inrbd_img_obj_parent_read_full_callback()Adjust the position of a jump label inrbd_img_request_fill()Rename a jump label inrbd_img_obj_callback()
Rename jump labels inrbd_osd_req_create_copyup()
Rename jump labels inrbd_osd_req_create()
Rename a jump label inbio_chain_clone_range()
Rename jump labels inrbd_client_create()
Rename a jump label inrbd_ioctl_set_ro()
One function call less inrbd_dev_probe_parent()after error detection Rename jump labels inrbd_dev_device_setup()
Rename jump labels inrbd_dev_image_probe()
Rename jump labels indo_rbd_add()
Delete an unnecessary initialisation indo_rbd_add()
Rename a jump label inrbd_slab_init()
Rename jump labels inrbd_init()
Delete unwanted spaces behind usages of the sizeof operator
Quoted 2 lines
drivers/block/rbd.c | 544 ++++++++++++++++++++++++++-------------------------- 1 file changed, 272 insertions(+), 272 deletions(-)
How can the clarification be continued for the shown change possibilities? (Can a bit more development discussion become helpful?)
https://lkml.org/lkml/2016/9/12/932
https://lkml.kernel.org/r/<[email protected]>
https://patchwork.kernel.org/patch/9327545/
Regards,
Markus
cover block-virtio: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 14:05:05 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Use kmalloc_array() in init_vq()
Less function calls in init_vq() after error detection Delete an unnecessary initialisation in init_vq() Rename a jump label in virtblk_get_id()
drivers/block/virtio_blk.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/4 virtio_blk: Use kmalloc_array() in init_vq()
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200
Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/virtio_blk.c +4 -4
@@ -390,13 +390,13 @@ static int init_vq(struct virtio_blk *vblk)if (err) num_vqs =1 ; - vblk->vqs =kmalloc (sizeof (*vblk->vqs) * num_vqs,GFP_KERNEL ); + vblk->vqs =kmalloc_array (num_vqs,sizeof (*vblk->vqs),GFP_KERNEL );if (!vblk->vqs)return -ENOMEM ; - names =kmalloc (sizeof (*names) * num_vqs,GFP_KERNEL ); - callbacks =kmalloc (sizeof (*callbacks) * num_vqs,GFP_KERNEL ); - vqs =kmalloc (sizeof (*vqs) * num_vqs,GFP_KERNEL ); + names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL );if (!names || !callbacks || !vqs) { err = -ENOMEM ; goto out;
Signature · 1 line
2.10.0
Re: [PATCH 1/4] virtio_blk: Use kmalloc_array() in init_vq()
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Re: [PATCH 1/4] virtio_blk: Use kmalloc_array() in init_vq()
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH 1/4 virtio_blk: Use kmalloc_array() in init_vq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 11:32:22 +0200
Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/virtio_blk.c +4 -4
@@ -390,13 +390,13 @@ static int init_vq(struct virtio_blk *vblk)if (err) num_vqs =1 ; - vblk->vqs =kmalloc (sizeof (*vblk->vqs) * num_vqs,GFP_KERNEL ); + vblk->vqs =kmalloc_array (num_vqs,sizeof (*vblk->vqs),GFP_KERNEL );if (!vblk->vqs)return -ENOMEM ; - names =kmalloc (sizeof (*names) * num_vqs,GFP_KERNEL ); - callbacks =kmalloc (sizeof (*callbacks) * num_vqs,GFP_KERNEL ); - vqs =kmalloc (sizeof (*vqs) * num_vqs,GFP_KERNEL ); + names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL );if (!names || !callbacks || !vqs) { err = -ENOMEM ; goto out;
Signature · 1 line
2.10.0
PATCH 2/4 virtio_blk: Less function calls in init_vq() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:20:44 +0200
The kfree() function was called in up to three cases by the init_vq() function during error handling even if the passed variable contained a null pointer.
* Split a condition check for memory allocation failures.
* Adjust jump targets according to the Linux coding style convention.
--- drivers/block/virtio_blk.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/block/virtio_blk.c +17 -5
@@ -395,11 +395,21 @@ static int init_vq(struct virtio_blk *vblk)return -ENOMEM ; names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); +if (!names) { + err = -ENOMEM ; + goto free_vblk_vqs; + } + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); +if (!callbacks) { + err = -ENOMEM ; + goto free_names; + } + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL ); -if (!names || !callbacks || !vqs) { +if (!vqs) { err = -ENOMEM ; - goto out; + goto free_callbacks; }for (i =0 ; i < num_vqs; i++) {
@@ -411,19 +421,21 @@ static int init_vq(struct virtio_blk *vblk)/* Discover virtqueues and write information to configuration. */ err = vdev->config->find_vqs (vdev, num_vqs, vqs, callbacks, names);if (err) - goto out; + goto free_vqs;for (i =0 ; i < num_vqs; i++) {spin_lock_init (&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } vblk->num_vqs = num_vqs; - -out: + free_vqs:kfree (vqs); + free_callbacks:kfree (callbacks); + free_names:kfree (names);if (err) + free_vblk_vqs:kfree (vblk->vqs);return err; }
Signature · 1 line
2.10.0
Re: [PATCH 2/4] virtio_blk: Less function calls in init_vq() after error detection
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:20:44 +0200The
kfree()function was called in up to three cases by theinit_vq()function during error handling even if the passed variable contained a null pointer.
Quoted 8 lines
* Split a condition check for memory allocation failures.
* Adjust jump targets according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
Can't you see from this diffstat that the patch actually seems to makes the code more complex?
In addition, please have a look at commit 347a529398e8e723338cca5d8a8ae2d9e7e93448
virtio_blk: Fix a slient kernel panic
which did the opposite of your patch. And in fact it fixed a bug. Quite obviously multiple labels are harder to read and harder to get right. For error handling with just kfree one label is just the right thing to.
Quoted 55 lines
drivers/block/virtio_blk.c +17
-5@@ -395,11 +395,21 @@ static int init_vq(struct virtio_blk *vblk)return -ENOMEM ; names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); +if (!names) { + err = -ENOMEM ; + goto free_vblk_vqs; + } + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); +if (!callbacks) { + err = -ENOMEM ; + goto free_names; + } + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL ); -if (!names || !callbacks || !vqs) { +if (!vqs) { err = -ENOMEM ; - goto out; + goto free_callbacks; }for (i =0 ; i < num_vqs; i++) {@@ -411,19 +421,21 @@ static int init_vq(struct virtio_blk *vblk)/* Discover virtqueues and write information to configuration. */ err = vdev->config->find_vqs (vdev, num_vqs, vqs, callbacks, names);if (err) - goto out; + goto free_vqs;for (i =0 ; i < num_vqs; i++) {spin_lock_init (&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } vblk->num_vqs = num_vqs; - -out: + free_vqs:kfree (vqs); + free_callbacks:kfree (callbacks); + free_names:kfree (names);if (err) + free_vblk_vqs:kfree (vblk->vqs);return err; }
Re: virtio_blk: Less function calls in init_vq() after error detection
Quoted 5 lines
Quoted 2 lines
drivers/block/virtio_blk.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)Can't you see from this diffstat that the patch actually seems to makes the code more complex?
I find that the repeated usage of a bit more error handling code is almost unavoidable if you would like to handle allocation failures more directly as I dared to propose again here.
Quoted 4 lines
In addition, please have a look at commit
347a529398e8e723338cca5d8a8ae2d9e7e93448
virtio_blk: Fix a slient kernel panicwhich did the opposite of your patch.
This software update adjusted also the jump targets. This approach triggered another update suggestion (in addition to improvements around the function "kmalloc_array").
Such a software development shows different views on the implementation for correct exception handling. I am not so "silent" on this development topic for years.
Quoted 1 line
And in fact it fixed a bug.
I get the impression from Minfei's contribution that the statement "err = -ENOMEM;" was added behind memory allocations.
It was also chosen to restructure this function implementation so that the single label "out" was used there for a while.
* Is this detail worth for another look?
* How does this name selection fit to the current Linux coding style convention?
Quoted 1 line
Quite obviously multiple labels are harder to read
I do not agree agree completely to your opinion.
Quoted 1 line
and harder to get right.
These identifiers can generate their own kind of software development challenges as usual.
Quoted 1 line
For error handling with just kfree one label is just the right thing to.
This approach can look convenient at first glance. Does the correctness aspect need any further considerations?
Regards,
Markus
Re: virtio_blk: Less function calls in init_vq() after error detection
In reply to Christian BorntraegerQuoted 2 lines
In addition, please have a look at commit
347a529398e8e723338cca5d8a8ae2d9e7e93448
virtio_blk: Fix a slient kernel panic
I would like to add another view on the implementation details in this software update.
Quoted 1 line
which did the opposite of your patch.
This update contained a different approach for error detection and corresponding exception handling.
Quoted 1 line
And in fact it fixed a bug.
This is great in principle according to an information in the commit description.
"…
To fix this bug, we should take care of allocation failure, and return correct value to let caller know what happen. …"
Quoted 2 lines
Quite obviously multiple labels are harder to read and harder to get right. For error handling with just kfree one label is just the right thing to.
Unfortunately, I get an other impression here after a closer look.
Can it be that the discussed commit from 2016-08-09 accepted (or tolerated) two weaknesses at least?
1. Commit title:
Is the word "slient" a typo?
Would you like to read "silent" there instead?
2. Source code:
Why would another memory allocation be attempted if it could be determined quicker that a previous one failed and this function implementation can not succeed then?
How much will it matter in general that two function calls are performed in this use case without checking their return values immediately?
https://cwe.mitre.org/data/definitions/252.html
if (!names || !callbacks || !vqs) { …https://cwe.mitre.org/data/definitions/754.html
Was the software development attention a bit too low as it happens occasionally?
I hope that my suggestions can improve the affected situation a bit more also for this software module.
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: virtio_blk: Less function calls in init_vq() after error detection
On 09/13/2016 07:30 PM, SF Markus Elfring wrote:
[...]
Quoted 13 lines
Unfortunately, I get an other impression here after a closer look.
Can it be that the discussed commit from 2016-08-09 accepted (or tolerated) two weaknesses at least?
1. Commit title:
Is the word "slient" a typo?
Would you like to read "silent" there instead?2. Source code:
Why would another memory allocation be attempted if it could be determined quicker that a previous one failed and this function implementation can not succeed then?
Quoted 8 lines
How much will it matter in general that two function calls are performed in this use case without checking their return values immediately? https://cwe.mitre.org/data/definitions/252.html if (!names || !callbacks || !vqs) { … https://cwe.mitre.org/data/definitions/754.html
The return values are checked, just a bit later.
Markus, kernel patches are not about be formally correct vs. CodingStyle and/or checkpatch or against code guidelines from sombody else. You will find many people consider gotos an no-go, still it is accepted in the kernel for good reasons.
You have to think about each change and its tradeoffs (e.g simplicity vs. performance) for each code part again. Here we have slow path error handling, so given the low coverage of these code parts, simplicity is important.
Yes, your code makes an unlikely error case bail out faster, but is the cost of your patch (review time, danger of adding bugs, danger of merge conflicts, making git blame less useful) in sync with the expected win? This is certainly Michaels area of maintainership and if he wants your patch, it will be fine too. (Well, having a label between the if and the function like
Quoted 3 lines
if (err)
+free_vblk_vqs:
kfree(vblk->vqs);
is certainly ugly in itself)
Quoted 5 lines
Was the software development attention a bit too low as it happens occasionally?
I hope that my suggestions can improve the affected situation a bit more also for this software module.
Do you realize that your discussion style is not very helpful?
I just grepped the last LKML mails and you already pissed of several maintainers in totally different areas. When that happens, why don't you stop for a moment and think about "what is going wrong right now".
Your attitude seems to be "I spend my spare time doing this, please thank me for that". The thing is, with each patch you actually request time from the maintainer. Now here begins the interesting part: Is the patch just a cosmetic change that does not give you any benefit or is the patch improving the code. And remember: there are always tradeoffs: performance, code size, code maintainability etc.
See, some of your patches are accepted, e.g. the memdup_user changes have usually been applied by most maintainers including myself. If maintainers won't take other change, please accept that. If you continue to waste peoples time by discussing "maybe" patches you actually risk that people will stop taking any patches from you including the "yes" ones.
Christian
--
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: virtio_blk: Less function calls in init_vq() after error detection
Quoted 9 lines
Quoted 7 lines
How much will it matter in general that two function calls are performed in this use case without checking their return values immediately? https://cwe.mitre.org/data/definitions/252.html if (!names || !callbacks || !vqs) { … https://cwe.mitre.org/data/definitions/754.htmlThe return values are checked,
I agree to this information.
Quoted 1 line
just a bit later.
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
Quoted 1 line
Markus, kernel patches are not about be formally correct vs. CodingStyle and/or checkpatch
I guess that some of the involved technical advices will also matter here, don't they?
Quoted 1 line
or against code guidelines from sombody else.
Some ideas or advices are integrated from other information sources also into various Linux software.
Quoted 1 line
You will find many people consider gotos an no-go,
I became trained also in this design direction for a while.
Quoted 1 line
still it is accepted in the kernel for good reasons.
I can follow such reasons to some degree.
Quoted 2 lines
You have to think about each change and its tradeoffs (e.g simplicity vs. performance) for each code part again.
This can happen as usual for an ordinary source code review process. I would be interested to clarify if items could be optimised for repeated checks in this work flow.
Quoted 1 line
Here we have slow path error handling, so given the low coverage of these code parts,
Would you like to add any other background information for this aspect?
Quoted 1 line
simplicity is important.
I can follow this opinion to some degree.
Quoted 1 line
Yes, your code makes an unlikely error case bail out faster,
Is this kind of functionality desired finally?
Quoted 2 lines
but is the cost of your patch (review time, danger of adding bugs, danger of merge conflicts, making git blame less useful) in sync with the expected win?
I hope so.
Do the mentioned aspects express a fear or other general concerns which hinder changes and make the proposed software improvement unlikely?
Quoted 6 lines
(Well, having a label between the if and the function like
Quoted 3 lines
if (err)
+free_vblk_vqs:
kfree(vblk->vqs);is certainly ugly in itself)
Would you find such a source code approach better if curly brackets will be added there?
Quoted 1 line
Do you realize that your discussion style is not very helpful?
I find that this view is debatable.
Quoted 2 lines
I just grepped the last LKML mails and you already pissed of several maintainers in totally different areas.
Yes. - It can happen that some contributors get occasionally grumpy.
Would you like to discuss their reasons a bit more?
Quoted 2 lines
When that happens, why don't you stop for a moment and think about "what is going wrong right now".
This happened also a few times already.
Quoted 1 line
Your attitude seems to be "I spend my spare time doing this, please thank me for that".
I guess that I am not so different in this aspect as I am trying to be another respectable free software developer for years.
Quoted 1 line
The thing is, with each patch you actually request time from the maintainer.
This is a consequence of software development as usual.
Quoted 2 lines
Now here begins the interesting part: Is the patch just a cosmetic change that does not give you any benefit or is the patch improving the code.
How do you categorise my concrete update suggestion which builds on previous contributions by others?
Quoted 1 line
And remember: there are always tradeoffs: performance, code size, code maintainability etc.
I find that I pick some of such design goals up for my software contributions already for a while.
Quoted 2 lines
See, some of your patches are accepted, e.g. the
memdup_userchanges have usually been applied by most maintainers including myself.
I thank you once more that you could also accept one of the proposed special software updates.
Quoted 1 line
If maintainers won't take other change, please accept that.
It can happen that change acceptance needs to evolve over time. Can a healthy pressure help to achieve special software improvements?
Quoted 1 line
If you continue to waste peoples time by discussing "maybe" patches
Can it be that this category of software updates has got a high potential for further clarifications because some approaches are occasionally interpreted as controversial?
Quoted 2 lines
you actually risk that people will stop taking any patches from you including the "yes" ones.
I assume that this risk is hard to avoid. - It is a matter for each contributor on how the desired communication should evolve further.
My knowledge evolved in the way that I am using some tools for static source code analysis. Such advanced tools can point various change opportunities out. I picked a few special search patterns up. It happened then that hundreds of source files were found which contain update candidates.
Further challenges are relevant then as usual.
* Handling of the search process and their results
* Communication between contributors
Search patterns can occasionally be categorised as "too special". The software technology contains also the risk for showing "false positives".
The reactions of code reviewers are varying between agreement and rejection.
The discussed concrete (and small) patch series is just another example for usual difficulties or more interesting software development challenges. I hope that they can be resolved in a systematic way.
So there are further constraints to consider, aren't 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: virtio_blk: Less function calls in init_vq() after error detection
In reply to Christian BorntraegerQuoted 9 lines
Quoted 7 lines
How much will it matter in general that two function calls are performed in this use case without checking their return values immediately? https://cwe.mitre.org/data/definitions/252.html if (!names || !callbacks || !vqs) { … https://cwe.mitre.org/data/definitions/754.htmlThe return values are checked,
I agree to this information.
Quoted 1 line
just a bit later.
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
Quoted 1 line
Markus, kernel patches are not about be formally correct vs. CodingStyle and/or checkpatch
I guess that some of the involved technical advices will also matter here, don't they?
Quoted 1 line
or against code guidelines from sombody else.
Some ideas or advices are integrated from other information sources also into various Linux software.
Quoted 1 line
You will find many people consider gotos an no-go,
I became trained also in this design direction for a while.
Quoted 1 line
still it is accepted in the kernel for good reasons.
I can follow such reasons to some degree.
Quoted 2 lines
You have to think about each change and its tradeoffs (e.g simplicity vs. performance) for each code part again.
This can happen as usual for an ordinary source code review process. I would be interested to clarify if items could be optimised for repeated checks in this work flow.
Quoted 1 line
Here we have slow path error handling, so given the low coverage of these code parts,
Would you like to add any other background information for this aspect?
Quoted 1 line
simplicity is important.
I can follow this opinion to some degree.
Quoted 1 line
Yes, your code makes an unlikely error case bail out faster,
Is this kind of functionality desired finally?
Quoted 2 lines
but is the cost of your patch (review time, danger of adding bugs, danger of merge conflicts, making git blame less useful) in sync with the expected win?
I hope so.
Do the mentioned aspects express a fear or other general concerns which hinder changes and make the proposed software improvement unlikely?
Quoted 6 lines
(Well, having a label between the if and the function like
Quoted 3 lines
if (err)
+free_vblk_vqs:
kfree(vblk->vqs);is certainly ugly in itself)
Would you find such a source code approach better if curly brackets will be added there?
Quoted 1 line
Do you realize that your discussion style is not very helpful?
I find that this view is debatable.
Quoted 2 lines
I just grepped the last LKML mails and you already pissed of several maintainers in totally different areas.
Yes. - It can happen that some contributors get occasionally grumpy.
Would you like to discuss their reasons a bit more?
Quoted 2 lines
When that happens, why don't you stop for a moment and think about "what is going wrong right now".
This happened also a few times already.
Quoted 1 line
Your attitude seems to be "I spend my spare time doing this, please thank me for that".
I guess that I am not so different in this aspect as I am trying to be another respectable free software developer for years.
Quoted 1 line
The thing is, with each patch you actually request time from the maintainer.
This is a consequence of software development as usual.
Quoted 2 lines
Now here begins the interesting part: Is the patch just a cosmetic change that does not give you any benefit or is the patch improving the code.
How do you categorise my concrete update suggestion which builds on previous contributions by others?
Quoted 1 line
And remember: there are always tradeoffs: performance, code size, code maintainability etc.
I find that I pick some of such design goals up for my software contributions already for a while.
Quoted 2 lines
See, some of your patches are accepted, e.g. the
memdup_userchanges have usually been applied by most maintainers including myself.
I thank you once more that you could also accept one of the proposed special software updates.
Quoted 1 line
If maintainers won't take other change, please accept that.
It can happen that change acceptance needs to evolve over time. Can a healthy pressure help to achieve special software improvements?
Quoted 1 line
If you continue to waste peoples time by discussing "maybe" patches
Can it be that this category of software updates has got a high potential for further clarifications because some approaches are occasionally interpreted as controversial?
Quoted 2 lines
you actually risk that people will stop taking any patches from you including the "yes" ones.
I assume that this risk is hard to avoid. - It is a matter for each contributor on how the desired communication should evolve further.
My knowledge evolved in the way that I am using some tools for static source code analysis. Such advanced tools can point various change opportunities out. I picked a few special search patterns up. It happened then that hundreds of source files were found which contain update candidates.
Further challenges are relevant then as usual.
* Handling of the search process and their results
* Communication between contributors
Search patterns can occasionally be categorised as "too special". The software technology contains also the risk for showing "false positives".
The reactions of code reviewers are varying between agreement and rejection.
The discussed concrete (and small) patch series is just another example for usual difficulties or more interesting software development challenges. I hope that they can be resolved in a systematic way.
So there are further constraints to consider, aren't there?
Regards,
Markus
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: virtio_blk: Less function calls in init_vq() after error detection
In reply to Christian BorntraegerQuoted 5 lines · On Tue, 13 Sep 2016 20:24:58 +0200 Christian Borntraeger…
See, some of your patches are accepted, e.g. the
memdup_userchanges have usually been applied by most maintainers including myself. If maintainers won't take other change, please accept that. If you continue to waste peoples time by discussing "maybe" patches you actually risk that people will stop taking any patches from you including the "yes" ones.
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so. So while I won't object if you choose to apply selected patches, I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
Re: virtio_blk: Clarification for communication difficulties?
Quoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
Regards,
Markus
Re: virtio_blk: Clarification for communication difficulties?
Quoted 8 lines · SF Markus Elfring
Quoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Quoted 8 lines
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion. Your communication style is exhausting and you've pushed into the territory where any benefits of taking the patches are not worth the time and hassle of dealing with you.
I left Reviewed-bys on two patches. Maybe they will get picked up. But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
Stefan
Re: virtio_blk: Clarification for communication difficulties?
Quoted 3 lines
Quoted 1 line
I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion.
Thanks for another feedback.
Quoted 1 line
Your communication style is exhausting
How did you get this impression?
Quoted 1 line
and you've pushed into the territory where any benefits of taking
Would you dare to acknowledge benefits from my update suggestions for any other software components?
Quoted 1 line
the patches are not worth the time and hassle of dealing with you.
How are the chances that such a conclusion will change?
Quoted 1 line
I left Reviewed-bys on two patches.
Thanks for your constructive responses.
Quoted 1 line
Maybe they will get picked up.
I am also curious on how the software evolution will be continued.
Quoted 2 lines
But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
I risk something just by proposing so many software updates for places where change opportunities were found by special source code search patterns.
Regards,
Markus
Re: virtio_blk: Clarification for communication difficulties?
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Quoted 8 lines
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
I can understand why others are fed up with this discussion. Your communication style is exhausting and you've pushed into the territory where any benefits of taking the patches are not worth the time and hassle of dealing with you.
I left Reviewed-bys on two patches. Maybe they will get picked up. But please think again about what Christian explained. Reviewers and maintainers spend time on your patches so make it worth their while.
Stefan
Re: virtio_blk: Clarification for communication difficulties?
In reply to Cornelia HuckQuoted 2 lines
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so.
How did I "pester" you "offline"?
Quoted 1 line
So while I won't object if you choose to apply selected patches,
Another bit of interesting information, isn't it?
Quoted 2 lines
I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
I find this reaction strange. - I hope that our collaboration potential can be still constructive, can't it?
Regards,
Markus
Re: virtio_blk: Less function calls in init_vq() after error detection
In reply to Christian BorntraegerQuoted 5 lines · On Tue, 13 Sep 2016 20:24:58 +0200 Christian Borntraeger…
See, some of your patches are accepted, e.g. the
memdup_userchanges have usually been applied by most maintainers including myself. If maintainers won't take other change, please accept that. If you continue to waste peoples time by discussing "maybe" patches you actually risk that people will stop taking any patches from you including the "yes" ones.
FWIW, he already gained a place on my ignore list for pestering me offline about his patches and not stopping even when told to do so. So while I won't object if you choose to apply selected patches, I won't comment on any and won't take any (hey, I even won't see them unless someone else replies...)
Re: virtio_blk: Less function calls in init_vq() after error detection
In reply to Christian BorntraegerQuoted 2 lines
In addition, please have a look at commit
347a529398e8e723338cca5d8a8ae2d9e7e93448
virtio_blk: Fix a slient kernel panic
I would like to add another view on the implementation details in this software update.
Quoted 1 line
which did the opposite of your patch.
This update contained a different approach for error detection and corresponding exception handling.
Quoted 1 line
And in fact it fixed a bug.
This is great in principle according to an information in the commit description.
"…
To fix this bug, we should take care of allocation failure, and return correct value to let caller know what happen. …"
Quoted 2 lines
Quite obviously multiple labels are harder to read and harder to get right. For error handling with just kfree one label is just the right thing to.
Unfortunately, I get an other impression here after a closer look.
Can it be that the discussed commit from 2016-08-09 accepted (or tolerated) two weaknesses at least?
1. Commit title:
Is the word "slient" a typo?
Would you like to read "silent" there instead?
2. Source code:
Why would another memory allocation be attempted if it could be determined quicker that a previous one failed and this function implementation can not succeed then?
How much will it matter in general that two function calls are performed in this use case without checking their return values immediately?
https://cwe.mitre.org/data/definitions/252.html
if (!names || !callbacks || !vqs) { …https://cwe.mitre.org/data/definitions/754.html
Was the software development attention a bit too low as it happens occasionally?
I hope that my suggestions can improve the affected situation a bit more also for this software module.
Regards,
Markus
Re: [PATCH 2/4] virtio_blk: Less function calls in init_vq() after error detection
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:20:44 +0200The
kfree()function was called in up to three cases by theinit_vq()function during error handling even if the passed variable contained a null pointer.
Quoted 8 lines
* Split a condition check for memory allocation failures.
* Adjust jump targets according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
Can't you see from this diffstat that the patch actually seems to makes the code more complex?
In addition, please have a look at commit 347a529398e8e723338cca5d8a8ae2d9e7e93448
virtio_blk: Fix a slient kernel panic
which did the opposite of your patch. And in fact it fixed a bug. Quite obviously multiple labels are harder to read and harder to get right. For error handling with just kfree one label is just the right thing to.
Quoted 55 lines
drivers/block/virtio_blk.c +17
-5@@ -395,11 +395,21 @@ static int init_vq(struct virtio_blk *vblk)return -ENOMEM ; names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); +if (!names) { + err = -ENOMEM ; + goto free_vblk_vqs; + } + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); +if (!callbacks) { + err = -ENOMEM ; + goto free_names; + } + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL ); -if (!names || !callbacks || !vqs) { +if (!vqs) { err = -ENOMEM ; - goto out; + goto free_callbacks; }for (i =0 ; i < num_vqs; i++) {@@ -411,19 +421,21 @@ static int init_vq(struct virtio_blk *vblk)/* Discover virtqueues and write information to configuration. */ err = vdev->config->find_vqs (vdev, num_vqs, vqs, callbacks, names);if (err) - goto out; + goto free_vqs;for (i =0 ; i < num_vqs; i++) {spin_lock_init (&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } vblk->num_vqs = num_vqs; - -out: + free_vqs:kfree (vqs); + free_callbacks:kfree (callbacks); + free_names:kfree (names);if (err) + free_vblk_vqs:kfree (vblk->vqs);return err; }
PATCH 2/4 virtio_blk: Less function calls in init_vq() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:20:44 +0200
The kfree() function was called in up to three cases by the init_vq() function during error handling even if the passed variable contained a null pointer.
* Split a condition check for memory allocation failures.
* Adjust jump targets according to the Linux coding style convention.
--- drivers/block/virtio_blk.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/block/virtio_blk.c +17 -5
@@ -395,11 +395,21 @@ static int init_vq(struct virtio_blk *vblk)return -ENOMEM ; names =kmalloc_array (num_vqs,sizeof (*names),GFP_KERNEL ); +if (!names) { + err = -ENOMEM ; + goto free_vblk_vqs; + } + callbacks =kmalloc_array (num_vqs,sizeof (*callbacks),GFP_KERNEL ); +if (!callbacks) { + err = -ENOMEM ; + goto free_names; + } + vqs =kmalloc_array (num_vqs,sizeof (*vqs),GFP_KERNEL ); -if (!names || !callbacks || !vqs) { +if (!vqs) { err = -ENOMEM ; - goto out; + goto free_callbacks; }for (i =0 ; i < num_vqs; i++) {
@@ -411,19 +421,21 @@ static int init_vq(struct virtio_blk *vblk)/* Discover virtqueues and write information to configuration. */ err = vdev->config->find_vqs (vdev, num_vqs, vqs, callbacks, names);if (err) - goto out; + goto free_vqs;for (i =0 ; i < num_vqs; i++) {spin_lock_init (&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } vblk->num_vqs = num_vqs; - -out: + free_vqs:kfree (vqs); + free_callbacks:kfree (callbacks); + free_names:kfree (names);if (err) + free_vblk_vqs:kfree (vblk->vqs);return err; }
Signature · 1 line
2.10.0
PATCH 3/4 virtio_blk: Delete an unnecessary initialisation in init_vq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200
The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.
--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
Signature · 1 line
2.10.0
Re: [PATCH 3/4] virtio_blk: Delete an unnecessary initialisation in init_vq()
Quoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static void virtblk_config_changed(struct virtio_device *vdev) · line 382
Quoted 8 lines
drivers/block/virtio_blk.c +1
-1@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
Re: [PATCH 3/4] virtio_blk: Delete an unnecessary initialisation in init_vq()
In reply to SF Markus ElfringQuoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static void virtblk_config_changed(struct virtio_device *vdev) · line 382
Quoted 8 lines
drivers/block/virtio_blk.c +1
-1@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
PATCH 3/4 virtio_blk: Delete an unnecessary initialisation in init_vq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:43:50 +0200
The local variable "err" will be set to an appropriate value by a following statement.
Thus omit the explicit initialisation at the beginning.
--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)static int init_vq (struct virtio_blk *vblk) { -int err =0 ; +int err;int i;vq_callback_t **callbacks;const char **names;
Signature · 1 line
2.10.0
PATCH 4/4 virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +2 -2
@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:blk_put_request (req);return err; }
Signature · 1 line
2.10.0
Re: [PATCH 4/4] virtio_blk: Rename a jump label in virtblk_get_id()
Quoted 4 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <linux/jump_label.h>.
Quoted 10 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 9 lines
drivers/block/virtio_blk.c +2
-2@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:
I checked Documentation/CodingStyle and see no reason to rename the label.
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Re: virtio_blk: Rename a jump label in virtblk_get_id()
Quoted 4 lines
Quoted 1 line
Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <
linux/jump_label.h>.
Does a "goto" statement jump to the code position finally which is specified by the label?
Quoted 7 lines
Quoted 7 lines
drivers/block/virtio_blk.c +1
-1@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request;
Quoted 5 lines
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 3 lines
drivers/block/virtio_blk.c +1
-1err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:I checked
Documentation/CodingStyleand see no reason to rename the label.
Can the suggested longer identifier explain better the "what" and "why" for this software situation?
Quoted 2 lines
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Do you find information from a commit like "docs: Remove space-before-label guidance
from CodingStyle" (from 2016-09-21) interesting? ;-)
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?idyc70c304b0b443429b2a0019518532c5162817a
Regards,
Markus
Re: virtio_blk: Rename a jump label in virtblk_get_id()
In reply to Stefan HajnocziQuoted 4 lines
Quoted 1 line
Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <
linux/jump_label.h>.
Does a "goto" statement jump to the code position finally which is specified by the label?
Quoted 7 lines
Quoted 7 lines
drivers/block/virtio_blk.c +1
-1@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request;
Quoted 5 lines
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 3 lines
drivers/block/virtio_blk.c +1
-1err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:I checked
Documentation/CodingStyleand see no reason to rename the label.
Can the suggested longer identifier explain better the "what" and "why" for this software situation?
Quoted 2 lines
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Do you find information from a commit like "docs: Remove space-before-label guidance
from CodingStyle" (from 2016-09-21) interesting? ;-)
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id=79c70c304b0b443429b2a0019518532c5162817a
Regards,
Markus
Re: [PATCH 4/4] virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200Adjust a jump label according to the current Linux coding style convention.
I think you mean "goto label". "Jump label" has a different meaning, see <linux/jump_label.h>.
Quoted 10 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static int virtblk_get_id(struct gendisk *disk, char *id_str) · line 253
Quoted 9 lines
drivers/block/virtio_blk.c +2
-2@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:
I checked Documentation/CodingStyle and see no reason to rename the label.
It's also not clear why you added a space. The CodingStyle example does not use a space before the label.
Michael S. Tsirkin
maintainerRe: [PATCH 4/4] virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200Adjust a jump label according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>
Please don't send me such patches, I'm not really interested in renaming labels unless it clearly adds to a significant improvement in readability.
Quoted 23 lines
--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/block/virtio_blk.c +2
-2@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:blk_put_request (req);return err; }Signature · 1 line
2.10.0
Re: virtio_blk: Rename a jump label in virtblk_get_id()
Quoted 1 line
Please don't send me such patches, I'm not really interested in renaming labels
Thanks for your feedback.
Quoted 1 line
unless it clearly adds to a significant improvement in readability.
Have you got any more concrete conditions for the selection of appropriate identifiers in this use case according to your software development view?
Regards,
Markus
PATCH 4/4 virtio_blk: Rename a jump label in virtblk_get_id()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 13:50:56 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/block/virtio_blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +2 -2
@@ -247,10 +247,10 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str) err =blk_rq_map_kern (q, req, id_str,VIRTIO_BLK_ID_BYTES ,GFP_KERNEL );if (err) - goto out; + goto put_request; err =blk_execute_rq (vblk->disk->queue, vblk->disk, req, false); -out: + put_request:blk_put_request (req);return err; }
Signature · 1 line
2.10.0
cover AGPGART: Fine-tuning for four function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 22:34:56 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (7):
Use kmalloc_array() in compat_agpioc_reserve_wrap() Use memdup_user() rather than duplicating its implementation Rename jump labels in compat_agp_ioctl()
Use kmalloc_array() in agp_sgi_init()
Use kmalloc_array() in uninorth_create_gatt_table() Rename a jump label in uninorth_create_gatt_table() Delete an unnecessary check in uninorth_create_gatt_table()
drivers/char/agp/compat_ioctl.c | 31 +++++++++++++------------------ drivers/char/agp/sgi-agp.c | 6 +++--- drivers/char/agp/uninorth-agp.c | 12 ++++++------ 3 files changed, 22 insertions(+), 27 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/7 AGPGART: Use kmalloc_array() in compat_agpioc_reserve_wrap()
From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 17:51:32 +0200
Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/char/agp/compat_ioctl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/char/agp/compat_ioctl.c +6 -2
@@ -98,11 +98,15 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __userif (ureserve.seg_count >=16384 )return -EINVAL ; - usegment =kmalloc (sizeof (*usegment) * ureserve.seg_count,GFP_KERNEL ); + usegment =kmalloc_array (ureserve.seg_count, +sizeof (*usegment), +GFP_KERNEL );if (!usegment)return -ENOMEM ; - ksegment =kmalloc (sizeof (*ksegment) * kreserve.seg_count,GFP_KERNEL ); + ksegment =kmalloc_array (kreserve.seg_count, +sizeof (*ksegment), +GFP_KERNEL );if (!ksegment) {kfree (usegment);return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/7 AGPGART: Use memdup_user() rather than duplicating its implementation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 21:00:44 +0200
* Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
* Try this copy operation before allocating memory for the local variable "ksegment".
--- drivers/char/agp/compat_ioctl.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/char/agp/compat_ioctl.c +4 -12
@@ -98,11 +98,10 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __userif (ureserve.seg_count >=16384 )return -EINVAL ; - usegment =kmalloc_array (ureserve.seg_count, -sizeof (*usegment), -GFP_KERNEL ); -if (!usegment) -return -ENOMEM ; + usegment =memdup_user ((void __user *) ureserve.seg_list, +sizeof (*usegment) * ureserve.seg_count); +if (IS_ERR (usegment)) +return PTR_ERR (usegment); ksegment = kmalloc_array(kreserve.seg_count, sizeof(*ksegment),
@@ -112,13 +111,6 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __userreturn -ENOMEM ; } -if (copy_from_user (usegment, (void __user *) ureserve.seg_list, -sizeof (*usegment) * ureserve.seg_count)) { -kfree (usegment); -kfree (ksegment); -return -EFAULT ; - } -for (seg =0 ; seg < ureserve.seg_count; seg++) { ksegment[seg].pg_start = usegment[seg].pg_start; ksegment[seg].pg_count = usegment[seg].pg_count;
Signature · 1 line
2.10.0
PATCH 3/7 AGPGART: Rename jump labels in compat_agp_ioctl()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 21:12:02 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/agp/compat_ioctl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/char/agp/compat_ioctl.c +5 -6
@@ -209,24 +209,24 @@ long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if ((agp_fe.current_controller =NULL ) && (cmd !=AGPIOC_ACQUIRE32 )) { ret_val = -EINVAL ; - goto ioctl_out; + goto unlock; }if ((agp_fe.backend_acquired != true) && (cmd !=AGPIOC_ACQUIRE32 )) { ret_val = -EBUSY ; - goto ioctl_out; + goto unlock; }if (cmd !=AGPIOC_ACQUIRE32 ) {if (!(test_bit (AGP_FF_IS_CONTROLLER , &curr_priv->access_flags))) { ret_val = -EPERM ; - goto ioctl_out; + goto unlock; }/* Use the original pid of the controller, * in case it's threaded */ if (agp_fe.current_controller->pid != curr_priv->my_pid) { ret_val = -EBUSY ; - goto ioctl_out; + goto unlock; } }
@@ -274,8 +274,7 @@ long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case AGPIOC_CHIPSET_FLUSH32 :break ; } - -ioctl_out: + unlock:DBG ("ioctl returns %d\n" , ret_val);mutex_unlock (&(agp_fe.agp_mutex));return ret_val;
Signature · 1 line
2.10.0
PATCH 4/7 AGPGART-SGI: Use kmalloc_array() in agp_sgi_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 21:30:58 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/char/agp/sgi-agp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/agp/sgi-agp.c +3 -3
@@ -280,9 +280,9 @@ static int agp_sgi_init(void)else return 0 ; - sgi_tioca_agp_bridges =kmalloc (tioca_gart_found * -sizeof (struct agp_bridge_data *), -GFP_KERNEL ); + sgi_tioca_agp_bridges =kmalloc_array (tioca_gart_found, +sizeof (*sgi_tioca_agp_bridges), +GFP_KERNEL );if (!sgi_tioca_agp_bridges)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 5/7 AGPGART-UniNorth: Use kmalloc_array() in uninorth_create_gatt_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 21:50:44 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/char/agp/uninorth-agp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/agp/uninorth-agp.c +3 -1
@@ -402,7 +402,9 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)if (table =NULL )return -ENOMEM ; - uninorth_priv.pages_arr =kmalloc ((1 << page_order) *sizeof (struct page *),GFP_KERNEL ); + uninorth_priv.pages_arr =kmalloc_array (1 << page_order, +sizeof (*uninorth_priv.pages_arr), +GFP_KERNEL );if (uninorth_priv.pages_arr =NULL ) goto enomem;
Signature · 1 line
2.10.0
PATCH 6/7 AGPGART-UniNorth: Rename a jump label in uninorth_create_gatt_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 22:00:19 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/char/agp/uninorth-agp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/char/agp/uninorth-agp.c +2 -3
@@ -406,7 +406,7 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)sizeof (*uninorth_priv.pages_arr), GFP_KERNEL);if (uninorth_priv.pages_arr =NULL ) - goto enomem; + goto free_page_array; table_end = table + ((PAGE_SIZE * (1 << page_order)) -1 );
@@ -436,8 +436,7 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge) bridge->gatt_table[i] = scratch_value;return 0 ; - -enomem: + free_page_array:kfree (uninorth_priv.pages_arr);if (table)free_pages ((unsigned long )table, page_order);
Signature · 1 line
2.10.0
kbuild test robot
build botRe: [PATCH 6/7] AGPGART-UniNorth: Rename a jump label in uninorth_create_gatt_table()
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Markus,
[auto build test ERROR on drm/drm-next]
[also build test ERROR on v4.8-rc6 next-20160915]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]
url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/AGPGART-Fine-tuning-for-four-function-implementations/20160914-045406 base: git://people.freedesktop.org/~airlied/linux.git drm-next config: powerpc-pmac32_defconfig (attached as .config) compiler: powerpc-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc
All errors (new ones prefixed by >>):
drivers/char/agp/uninorth-agp.c: In function 'uninorth_create_gatt_table':
>> drivers/char/agp/uninorth-agp.c:426:3: error: label 'enomem' used but not defined
goto enomem;
^vim +/enomem +426 drivers/char/agp/uninorth-agp.c
e8a5f9001 Michel Dänzer 2009-08-04 420 /* Need to clear out any dirty data still sitting in caches */ e8a5f9001 Michel Dänzer 2009-08-04 421 flush_dcache_range((unsigned long)table, 79905ad50 Paul Mackerras 2010-06-01 422 (unsigned long)table_end + 1); 5ada62b10 Denis Kirjanov 2015-06-12 423 bridge->gatt_table = vmap(uninorth_priv.pages_arr, (1 << page_order), 0, PAGE_KERNEL_NCG); e8a5f9001 Michel Dänzer 2009-08-04 424 e8a5f9001 Michel Dänzer 2009-08-04 425 if (bridge->gatt_table == NULL) e8a5f9001 Michel Dänzer 2009-08-04 @426 goto enomem; e8a5f9001 Michel Dänzer 2009-08-04 427
6a12235c7 David Woodhouse 2009-07-29 428 bridge->gatt_bus_addr = virt_to_phys(table);
^1da177e4 Linus Torvalds 2005-04-16 429
:::::: The code at line 426 was first introduced by commit
:::::: e8a5f900148d058bce2d7bdce3d6bcbcb40267ec agp/uninorth: Simplify cache flushing.
:::::: TO: Michel Dänzer <[email protected]> :::::: CC: Benjamin Herrenschmidt <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 6/7] AGPGART-UniNorth: Rename a jump label in uninorth_create_gatt_table()
Quoted 6 lines
drivers/char/agp/uninorth-agp.c: In function 'uninorth_create_gatt_table':Quoted 1 line
Quoted 1 line
drivers/char/agp/uninorth-agp.c:426:3: error: label 'enomem' used but not definedgoto enomem; ^vim +/enomem +426
drivers/char/agp/uninorth-agp.c
This error message points a glitch out which was triggered by my update suggestion. Unfortunately, it means that the proposed renaming of such an identifier was incomplete at this source code place.
In which ways would you like to improve the shown software situation?
* Would you like to fix a single identifier anyhow directly?
* Do you expect that I should resend a corrected patch series as a whole package?
* Would it be sufficient to send another update only for the software module "AGPGART-UniNorth" a bit later?
* Can I worry about this programming mistake a bit less just because the suggested renaming would eventually be rejected?
Regards,
Markus
PATCH 7/7 AGPGART-UniNorth: Delete an unnecessary check in uninorth_create_gatt_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 22:15:56 +0200
The check for the local variable "table" is unnecessary at the end of this function because the corresponding source code place should only be reached with a non-zero pointer for it after a failed call of the function "kmalloc_array".
Thus remove it.
--- drivers/char/agp/uninorth-agp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/char/agp/uninorth-agp.c +1 -2
@@ -438,8 +438,7 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)return 0 ; free_page_array:kfree (uninorth_priv.pages_arr); -if (table) -free_pages ((unsigned long )table, page_order); +free_pages ((unsigned long )table, page_order);return -ENOMEM ; }
Signature · 1 line
2.10.0
cover virtio-console: Fine-tuning for 14 function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:43:21 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (11):
Use kmalloc_array() in init_vqs()
Less function calls in init_vqs() after error detection Rename a jump label in init()
Rename jump labels in virtcons_probe()
Rename jump labels in add_port()
Rename a jump label in port_fops_open()
Rename a jump label in port_fops_splice_write() Rename jump labels in port_fops_write()
Rename a jump label in __send_to_port()
Rename jump labels in alloc_buf()
Rename a jump label in five functions
drivers/char/virtio_console.c | 155 ++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 68 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/11 virtio_console: Use kmalloc_array() in init_vqs()
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 11:23:59 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specifications of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/char/virtio_console.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +11 -7
@@ -1881,13 +1881,17 @@ static int init_vqs(struct ports_device *portdev) nr_ports = portdev->config.max_nr_ports; nr_queues =use_multiport (portdev) ? (nr_ports +1 ) *2 :2 ; - vqs =kmalloc (nr_queues *sizeof (struct virtqueue *),GFP_KERNEL ); - io_callbacks =kmalloc (nr_queues *sizeof (vq_callback_t *),GFP_KERNEL ); - io_names =kmalloc (nr_queues *sizeof (char *),GFP_KERNEL ); - portdev->in_vqs =kmalloc (nr_ports *sizeof (struct virtqueue *), -GFP_KERNEL ); - portdev->out_vqs =kmalloc (nr_ports *sizeof (struct virtqueue *), -GFP_KERNEL ); + vqs =kmalloc_array (nr_queues,sizeof (*vqs),GFP_KERNEL ); + io_callbacks =kmalloc_array (nr_queues, +sizeof (*io_callbacks), +GFP_KERNEL ); + io_names =kmalloc_array (nr_queues,sizeof (*io_names),GFP_KERNEL ); + portdev->in_vqs =kmalloc_array (nr_ports, +sizeof (*portdev->in_vqs), +GFP_KERNEL ); + portdev->out_vqs =kmalloc_array (nr_ports, +sizeof (*portdev->out_vqs), +GFP_KERNEL );if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs || !portdev->out_vqs) { err = -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 1/11 virtio_console: Use kmalloc_array() in init_vqs()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 11:23:59 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specifications of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/char/virtio_console.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +11 -7
@@ -1881,13 +1881,17 @@ static int init_vqs(struct ports_device *portdev) nr_ports = portdev->config.max_nr_ports; nr_queues =use_multiport (portdev) ? (nr_ports +1 ) *2 :2 ; - vqs =kmalloc (nr_queues *sizeof (struct virtqueue *),GFP_KERNEL ); - io_callbacks =kmalloc (nr_queues *sizeof (vq_callback_t *),GFP_KERNEL ); - io_names =kmalloc (nr_queues *sizeof (char *),GFP_KERNEL ); - portdev->in_vqs =kmalloc (nr_ports *sizeof (struct virtqueue *), -GFP_KERNEL ); - portdev->out_vqs =kmalloc (nr_ports *sizeof (struct virtqueue *), -GFP_KERNEL ); + vqs =kmalloc_array (nr_queues,sizeof (*vqs),GFP_KERNEL ); + io_callbacks =kmalloc_array (nr_queues, +sizeof (*io_callbacks), +GFP_KERNEL ); + io_names =kmalloc_array (nr_queues,sizeof (*io_names),GFP_KERNEL ); + portdev->in_vqs =kmalloc_array (nr_ports, +sizeof (*portdev->in_vqs), +GFP_KERNEL ); + portdev->out_vqs =kmalloc_array (nr_ports, +sizeof (*portdev->out_vqs), +GFP_KERNEL );if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs || !portdev->out_vqs) { err = -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 2/11 virtio_console: Less function calls in init_vqs() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:00:35 +0200
The kfree() function was called in up to five cases by the init_vqs() function during error handling even if the passed variable contained a null pointer.
* Return directly after a call of the function "kmalloc_array" failed at the beginning.
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
* Adjust jump targets according to the Linux coding style convention.
--- drivers/char/virtio_console.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/char/virtio_console.c +26 -6
@@ -1882,20 +1882,37 @@ static int init_vqs(struct ports_device *portdev) nr_queues =use_multiport (portdev) ? (nr_ports +1 ) *2 :2 ; vqs =kmalloc_array (nr_queues,sizeof (*vqs),GFP_KERNEL ); +if (!vqs) +return -ENOMEM ; + io_callbacks =kmalloc_array (nr_queues,sizeof (*io_callbacks),GFP_KERNEL ); +if (!io_callbacks) { + err = -ENOMEM ; + goto free_vqs; + } + io_names =kmalloc_array (nr_queues,sizeof (*io_names),GFP_KERNEL ); +if (!io_names) { + err = -ENOMEM ; + goto free_callbacks; + } + portdev->in_vqs =kmalloc_array (nr_ports,sizeof (*portdev->in_vqs),GFP_KERNEL ); +if (!portdev->in_vqs) { + err = -ENOMEM ; + goto free_names; + } + portdev->out_vqs =kmalloc_array (nr_ports,sizeof (*portdev->out_vqs),GFP_KERNEL ); -if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs || - !portdev->out_vqs) { +if (!portdev->out_vqs) { err = -ENOMEM ; - goto free; + goto free_in_vqs; }/*
@@ -1929,7 +1946,7 @@ static int init_vqs(struct ports_device *portdev) io_callbacks, (const char **)io_names);if (err) - goto free; + goto free_out_vqs; j =0 ; portdev->in_vqs[0 ] = vqs[0 ];
@@ -1950,12 +1967,15 @@ static int init_vqs(struct ports_device *portdev)kfree (vqs);return 0 ; - -free: + free_out_vqs:kfree (portdev->out_vqs); + free_in_vqs:kfree (portdev->in_vqs); + free_names:kfree (io_names); + free_callbacks:kfree (io_callbacks); + free_vqs:kfree (vqs);return err;
Signature · 1 line
2.10.0
Re: [PATCH 02/11] virtio_console: Less function calls in init_vqs() after error detection
Hi,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:00:35 +0200The
kfree()function was called in up to five cases by theinit_vqs()function during error handling even if the passed variable contained a null pointer.* Return directly after a call of the function "
kmalloc_array" failed at the beginning.
Quoted 8 lines
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"* Adjust jump targets according to the Linux coding style convention.
So I've seen this series and I'm not yet sure how I feel about the patches - f.e. in this one, it adds more lines than it removes to achieve the same effect. I think the code is currently more readable than after these changes. And even if kfree is called multiple times, it isn't a huge bother -- it's error case anyway, very unlikely to trigger, but keeps everything very readble.
Amit
Re: virtio_console: Less function calls in init_vqs() after error detection
Quoted 14 lines
Quoted 14 lines
The
kfree()function was called in up to five cases by theinit_vqs()function during error handling even if the passed variable contained a null pointer.* Return directly after a call of the function "
kmalloc_array" failed at the beginning.* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
Quoted 5 lines
Quoted 1 line
* Adjust jump targets according to the Linux coding style convention.
So I've seen this series and I'm not yet sure how I feel about the patches - f.e. in this one, it adds more lines than it removes to achieve the same effect.
I find this consequence still debatable.
Quoted 1 line
I think the code is currently more readable than after these changes.
Thanks for your constructive feedback.
Can it be that an other software development concern is eventually overlooked?
Quoted 1 line
And even if kfree is called multiple times, it isn't a huge bother
I know also that the implementation of this function tolerates the passing of null pointers.
Quoted 1 line
-- it's error case anyway, very unlikely to trigger, but keeps everything very readble.
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
* How much will it matter in general that four function call were performed in this use case without checking their return values immediately?
* Should it usually be determined quicker if a required resource like memory could be acquired before trying the next allocation?
Regards,
Markus
PATCH 3/11 virtio_console: Rename a jump label in init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:10:24 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +3 -3
@@ -2309,7 +2309,7 @@ static int __init init(void) err =register_virtio_driver (&virtio_console);if (err <0 ) {pr_err ("Error %d registering virtio driver\n" , err); - goto free; + goto remove; } err =register_virtio_driver (&virtio_rproc_serial);if (err <0 ) {
@@ -2318,9 +2318,9 @@ static int __init init(void) goto unregister; }return 0 ; -unregister: + unregister:unregister_virtio_driver (&virtio_console); -free: + remove:debugfs_remove_recursive (pdrvdata.debugfs_dir);class_destroy (pdrvdata.class);return err;
Signature · 1 line
2.10.0
PATCH 3/11 virtio_console: Rename a jump label in init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:10:24 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +3 -3
@@ -2309,7 +2309,7 @@ static int __init init(void) err =register_virtio_driver (&virtio_console);if (err <0 ) {pr_err ("Error %d registering virtio driver\n" , err); - goto free; + goto remove; } err =register_virtio_driver (&virtio_rproc_serial);if (err <0 ) {
@@ -2318,9 +2318,9 @@ static int __init init(void) goto unregister; }return 0 ; -unregister: + unregister:unregister_virtio_driver (&virtio_console); -free: + remove:debugfs_remove_recursive (pdrvdata.debugfs_dir);class_destroy (pdrvdata.class);return err;
Signature · 1 line
2.10.0
PATCH 4/11 virtio_console: Rename jump labels in virtcons_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:24:05 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/char/virtio_console.c +8 -9
@@ -2037,7 +2037,7 @@ static int virtcons_probe(struct virtio_device *vdev) portdev =kmalloc (sizeof (*portdev),GFP_KERNEL );if (!portdev) { err = -ENOMEM ; - goto fail; + goto exit; }/* Attach this portdev to this virtio_device, and vice-versa. */
@@ -2051,7 +2051,7 @@ static int virtcons_probe(struct virtio_device *vdev)"Error %d registering chrdev for device %u\n" , portdev->chr_major, vdev->index); err = portdev->chr_major; - goto free; + goto free_port; } multiport = false;
@@ -2068,7 +2068,7 @@ static int virtcons_probe(struct virtio_device *vdev) err =init_vqs (portdev);if (err <0 ) {dev_err (&vdev->dev,"Error %d initializing vqs\n" , err); - goto free_chrdev; + goto unregister; }spin_lock_init (&portdev->ports_lock);
@@ -2091,7 +2091,7 @@ static int virtcons_probe(struct virtio_device *vdev)dev_err (&vdev->dev,"Error allocating buffers for control queue\n" ); err = -ENOMEM ; - goto free_vqs; + goto send_control_message; } }else {/*
@@ -2121,17 +2121,16 @@ static int virtcons_probe(struct virtio_device *vdev)wait_for_completion (&early_console_added);return 0 ; - -free_vqs: + send_control_message:/* The host might want to notify mgmt sw about device add failure */ __send_control_msg (portdev,VIRTIO_CONSOLE_BAD_ID ,VIRTIO_CONSOLE_DEVICE_READY ,0 );remove_vqs (portdev); -free_chrdev: + unregister:unregister_chrdev (portdev->chr_major,"virtio-portsdev" ); -free: + free_port:kfree (portdev); -fail: + exit:return err; }
Signature · 1 line
2.10.0
PATCH 4/11 virtio_console: Rename jump labels in virtcons_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:24:05 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/char/virtio_console.c +8 -9
@@ -2037,7 +2037,7 @@ static int virtcons_probe(struct virtio_device *vdev) portdev =kmalloc (sizeof (*portdev),GFP_KERNEL );if (!portdev) { err = -ENOMEM ; - goto fail; + goto exit; }/* Attach this portdev to this virtio_device, and vice-versa. */
@@ -2051,7 +2051,7 @@ static int virtcons_probe(struct virtio_device *vdev)"Error %d registering chrdev for device %u\n" , portdev->chr_major, vdev->index); err = portdev->chr_major; - goto free; + goto free_port; } multiport = false;
@@ -2068,7 +2068,7 @@ static int virtcons_probe(struct virtio_device *vdev) err =init_vqs (portdev);if (err <0 ) {dev_err (&vdev->dev,"Error %d initializing vqs\n" , err); - goto free_chrdev; + goto unregister; }spin_lock_init (&portdev->ports_lock);
@@ -2091,7 +2091,7 @@ static int virtcons_probe(struct virtio_device *vdev)dev_err (&vdev->dev,"Error allocating buffers for control queue\n" ); err = -ENOMEM ; - goto free_vqs; + goto send_control_message; } }else {/*
@@ -2121,17 +2121,16 @@ static int virtcons_probe(struct virtio_device *vdev)wait_for_completion (&early_console_added);return 0 ; - -free_vqs: + send_control_message:/* The host might want to notify mgmt sw about device add failure */ __send_control_msg (portdev,VIRTIO_CONSOLE_BAD_ID ,VIRTIO_CONSOLE_DEVICE_READY ,0 );remove_vqs (portdev); -free_chrdev: + unregister:unregister_chrdev (portdev->chr_major,"virtio-portsdev" ); -free: + free_port:kfree (portdev); -fail: + exit:return err; }
Signature · 1 line
2.10.0
PATCH 5/11 virtio_console: Rename jump labels in add_port()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:53:00 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/char/virtio_console.c +10 -11
@@ -1399,7 +1399,7 @@ static int add_port(struct ports_device *portdev, u32 id) port =kmalloc (sizeof (*port),GFP_KERNEL );if (!port) { err = -ENOMEM ; - goto fail; + goto send_control_message; }kref_init (&port->kref);
@@ -1434,7 +1434,7 @@ static int add_port(struct ports_device *portdev, u32 id)if (err <0 ) {dev_err (&port->portdev->vdev->dev,"Error %d adding cdev for port %u\n" , err, id); - goto free_cdev; + goto delete_cdev; } port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, devt, port, "vport%up%u",
@@ -1444,7 +1444,7 @@ static int add_port(struct ports_device *portdev, u32 id)dev_err (&port->portdev->vdev->dev,"Error %d creating device for port %u\n" , err, id); - goto free_cdev; + goto delete_cdev; }spin_lock_init (&port->inbuf_lock);
@@ -1456,7 +1456,7 @@ static int add_port(struct ports_device *portdev, u32 id)if (!nr_added_bufs) {dev_err (port->dev,"Error allocating inbufs\n" ); err = -ENOMEM ; - goto free_device; + goto destroy_device; }if (is_rproc_serial (port->portdev->vdev))
@@ -1473,7 +1473,7 @@ static int add_port(struct ports_device *portdev, u32 id)*/ err =init_port_console (port);if (err) - goto free_inbufs; + goto free_buffers; }spin_lock_irq (&portdev->ports_lock);
@@ -1500,17 +1500,16 @@ static int add_port(struct ports_device *portdev, u32 id) &port_debugfs_ops); }return 0 ; - -free_inbufs: + free_buffers:while ((buf =virtqueue_detach_unused_buf (port->in_vq)))free_buf (buf, true); -free_device: + destroy_device:device_destroy (pdrvdata.class, port->dev->devt); -free_cdev: + delete_cdev:cdev_del (port->cdev); -free_port: + free_port:kfree (port); -fail: + send_control_message:/* The host might want to notify management sw about port add failure */ __send_control_msg (portdev, id,VIRTIO_CONSOLE_PORT_READY ,0 );return err;
Signature · 1 line
2.10.0
PATCH 5/11 virtio_console: Rename jump labels in add_port()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:53:00 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/char/virtio_console.c +10 -11
@@ -1399,7 +1399,7 @@ static int add_port(struct ports_device *portdev, u32 id) port =kmalloc (sizeof (*port),GFP_KERNEL );if (!port) { err = -ENOMEM ; - goto fail; + goto send_control_message; }kref_init (&port->kref);
@@ -1434,7 +1434,7 @@ static int add_port(struct ports_device *portdev, u32 id)if (err <0 ) {dev_err (&port->portdev->vdev->dev,"Error %d adding cdev for port %u\n" , err, id); - goto free_cdev; + goto delete_cdev; } port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, devt, port, "vport%up%u",
@@ -1444,7 +1444,7 @@ static int add_port(struct ports_device *portdev, u32 id)dev_err (&port->portdev->vdev->dev,"Error %d creating device for port %u\n" , err, id); - goto free_cdev; + goto delete_cdev; }spin_lock_init (&port->inbuf_lock);
@@ -1456,7 +1456,7 @@ static int add_port(struct ports_device *portdev, u32 id)if (!nr_added_bufs) {dev_err (port->dev,"Error allocating inbufs\n" ); err = -ENOMEM ; - goto free_device; + goto destroy_device; }if (is_rproc_serial (port->portdev->vdev))
@@ -1473,7 +1473,7 @@ static int add_port(struct ports_device *portdev, u32 id)*/ err =init_port_console (port);if (err) - goto free_inbufs; + goto free_buffers; }spin_lock_irq (&portdev->ports_lock);
@@ -1500,17 +1500,16 @@ static int add_port(struct ports_device *portdev, u32 id) &port_debugfs_ops); }return 0 ; - -free_inbufs: + free_buffers:while ((buf =virtqueue_detach_unused_buf (port->in_vq)))free_buf (buf, true); -free_device: + destroy_device:device_destroy (pdrvdata.class, port->dev->devt); -free_cdev: + delete_cdev:cdev_del (port->cdev); -free_port: + free_port:kfree (port); -fail: + send_control_message:/* The host might want to notify management sw about port add failure */ __send_control_msg (portdev, id,VIRTIO_CONSOLE_PORT_READY ,0 );return err;
Signature · 1 line
2.10.0
PATCH 6/11 virtio_console: Rename a jump label in port_fops_open()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 14:58:24 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +3 -3
@@ -1058,7 +1058,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)*/ if (is_console_port (port)) { ret = -ENXIO ; - goto out; + goto put_ref; }/* Allow only one process to open a particular port at a time */
@@ -1066,7 +1066,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)if (port->guest_connected) {spin_unlock_irq (&port->inbuf_lock); ret = -EBUSY ; - goto out; + goto put_ref; } port->guest_connected = true;
@@ -1087,7 +1087,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)send_control_msg (filp->private_data,VIRTIO_CONSOLE_PORT_OPEN ,1 );return 0 ; -out: + put_ref:kref_put (&port->kref, remove_port);return ret; }
Signature · 1 line
2.10.0
PATCH 7/11 virtio_console: Rename a jump label in port_fops_splice_write()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:01:51 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/char/virtio_console.c +4 -5
@@ -947,17 +947,17 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,pipe_lock (pipe);if (!pipe->nrbufs) { ret =0 ; - goto error_out; + goto unlock; } ret =wait_port_writable (port, filp->f_flags &O_NONBLOCK );if (ret <0 ) - goto error_out; + goto unlock; buf =alloc_buf (port->out_vq,0 , pipe->nrbufs);if (!buf) { ret = -ENOMEM ; - goto error_out; + goto unlock; } sgl.n =0 ;
@@ -973,8 +973,7 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,if (unlikely (ret <=0 ))free_buf (buf, true);return ret; - -error_out: + unlock:pipe_unlock (pipe);return ret; }
Signature · 1 line
2.10.0
PATCH 8/11 virtio_console: Rename jump labels in port_fops_write()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:07:42 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/char/virtio_console.c +4 -5
@@ -842,7 +842,7 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ret =copy_from_user (buf->buf, ubuf, count);if (ret) { ret = -EFAULT ; - goto free_buf; + goto free_buffer; }/*
@@ -857,11 +857,10 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ret =__send_to_port (port, sg,1 , count, buf, nonblock);if (nonblock && ret >0 ) - goto out; - -free_buf: + goto exit; + free_buffer:free_buf (buf, true); -out: + exit:return ret; }
Signature · 1 line
2.10.0
PATCH 8/11 virtio_console: Rename jump labels in port_fops_write()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:07:42 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/char/virtio_console.c +4 -5
@@ -842,7 +842,7 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ret =copy_from_user (buf->buf, ubuf, count);if (ret) { ret = -EFAULT ; - goto free_buf; + goto free_buffer; }/*
@@ -857,11 +857,10 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ret =__send_to_port (port, sg,1 , count, buf, nonblock);if (nonblock && ret >0 ) - goto out; - -free_buf: + goto exit; + free_buffer:free_buf (buf, true); -out: + exit:return ret; }
Signature · 1 line
2.10.0
PATCH 9/11 virtio_console: Rename a jump label in __send_to_port()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:15:06 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +3 -3
@@ -634,14 +634,14 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,if (err) { in_count =0 ; - goto done; + goto unlock; }if (out_vq->num_free =0 ) port->outvq_full = true;if (nonblock) - goto done; + goto unlock;/* * Wait till the host acknowledges it pushed out the data we
@@ -655,7 +655,7 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,while (!virtqueue_get_buf (out_vq, &len) && !virtqueue_is_broken (out_vq))cpu_relax (); -done: + unlock:spin_unlock_irqrestore (&port->outvq_lock, flags); port->stats.bytes_sent += in_count;
Signature · 1 line
2.10.0
PATCH 9/11 virtio_console: Rename a jump label in __send_to_port()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:15:06 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/virtio_console.c +3 -3
@@ -634,14 +634,14 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,if (err) { in_count =0 ; - goto done; + goto unlock; }if (out_vq->num_free ==0 ) port->outvq_full = true;if (nonblock) - goto done; + goto unlock;/* * Wait till the host acknowledges it pushed out the data we
@@ -655,7 +655,7 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,while (!virtqueue_get_buf (out_vq, &len) && !virtqueue_is_broken (out_vq))cpu_relax (); -done: + unlock:spin_unlock_irqrestore (&port->outvq_lock, flags); port->stats.bytes_sent += in_count;
Signature · 1 line
2.10.0
PATCH 10/11 virtio_console: Rename jump labels in alloc_buf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:20:30 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/char/virtio_console.c +5 -6
@@ -431,7 +431,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size, buf =kmalloc (sizeof (*buf) +sizeof (struct scatterlist ) * pages,GFP_KERNEL );if (!buf) - goto fail; + goto exit; buf->sgpages = pages;if (pages >0 ) {
@@ -451,7 +451,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,* in dma-coherent.c */ if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent) - goto free_buf; + goto free_buffer; buf->dev = vq->vdev->dev.parent->parent;/* Increase device refcnt to avoid freeing it */
@@ -464,15 +464,14 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size, }if (!buf->buf) - goto free_buf; + goto free_buffer; buf->len =0 ; buf->offset =0 ; buf->size = buf_size;return buf; - -free_buf: + free_buffer:kfree (buf); -fail: + exit:return NULL ; }
Signature · 1 line
2.10.0
PATCH 10/11 virtio_console: Rename jump labels in alloc_buf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:20:30 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/char/virtio_console.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/char/virtio_console.c +5 -6
@@ -431,7 +431,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size, buf =kmalloc (sizeof (*buf) +sizeof (struct scatterlist ) * pages,GFP_KERNEL );if (!buf) - goto fail; + goto exit; buf->sgpages = pages;if (pages >0 ) {
@@ -451,7 +451,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,* in dma-coherent.c */ if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent) - goto free_buf; + goto free_buffer; buf->dev = vq->vdev->dev.parent->parent;/* Increase device refcnt to avoid freeing it */
@@ -464,15 +464,14 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size, }if (!buf->buf) - goto free_buf; + goto free_buffer; buf->len =0 ; buf->offset =0 ; buf->size = buf_size;return buf; - -free_buf: + free_buffer:kfree (buf); -fail: + exit:return NULL ; }
Signature · 1 line
2.10.0
PATCH 11/11 virtio_console: Rename a jump label in five functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 15:37:52 +0200
Adjust a jump label according to the current Linux coding style convention. Thus replace the identifier "out" by "unlock".
--- drivers/char/virtio_console.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/char/virtio_console.c +10 -10
@@ -257,11 +257,11 @@ static struct port *find_port_by_vtermno(u32 vtermno)list_for_each_entry (cons, &pdrvdata.consoles, list) {if (cons->vtermno = vtermno) { port = container_of(cons, struct port, cons); - goto out; + goto unlock; } } port =NULL ; -out: + unlock:spin_unlock_irqrestore (&pdrvdata_lock, flags);return port; }
@@ -276,11 +276,11 @@ static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev,list_for_each_entry (port, &portdev->ports, list) {if (port->cdev->dev = dev) {kref_get (&port->kref); - goto out; + goto unlock; } } port =NULL ; -out: + unlock:spin_unlock_irqrestore (&portdev->ports_lock, flags);return port;
@@ -296,10 +296,10 @@ static struct port *find_port_by_devt(dev_t dev)list_for_each_entry (portdev, &pdrvdata.portdevs, list) { port =find_port_by_devt_in_portdev (portdev, dev);if (port) - goto out; + goto unlock; } port =NULL ; -out: + unlock:spin_unlock_irqrestore (&pdrvdata_lock, flags);return port; }
@@ -312,9 +312,9 @@ static struct port *find_port_by_id(struct ports_device *portdev, u32 id)spin_lock_irqsave (&portdev->ports_lock, flags);list_for_each_entry (port, &portdev->ports, list)if (port->id = id) - goto out; + goto unlock; port =NULL ; -out: + unlock:spin_unlock_irqrestore (&portdev->ports_lock, flags);return port;
@@ -329,9 +329,9 @@ static struct port *find_port_by_vq(struct ports_device *portdev,spin_lock_irqsave (&portdev->ports_lock, flags);list_for_each_entry (port, &portdev->ports, list)if (port->in_vq = vq || port->out_vq = vq) - goto out; + goto unlock; port =NULL ; -out: + unlock:spin_unlock_irqrestore (&portdev->ports_lock, flags);return port; }
Signature · 1 line
2.10.0
Re: [PATCH 00/11] virtio-console: Fine-tuning for 14 function implementations
In reply to SF Markus ElfringQuoted 18 lines
Date: Wed, 14 Sep 2016 15:43:21 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (11):
Usekmalloc_array()ininit_vqs()
Less function calls ininit_vqs()after error detection Rename a jump label ininit()
Rename jump labels invirtcons_probe()
Rename jump labels inadd_port()
Rename a jump label inport_fops_open()
Rename a jump label inport_fops_splice_write()Rename jump labels inport_fops_write()
Rename a jump label in__send_to_port()
Rename jump labels inalloc_buf()
Rename a jump label in five functions
Quoted 2 lines
drivers/char/virtio_console.c | 155 ++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 68 deletions(-)
Would you like to take another look at change possibilities for this software module?
Regards,
Markus
Re: [PATCH 00/11] virtio-console: Fine-tuning for 14 function implementations
In reply to SF Markus ElfringQuoted 18 lines
Date: Wed, 14 Sep 2016 15:43:21 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (11):
Usekmalloc_array()ininit_vqs()
Less function calls ininit_vqs()after error detection Rename a jump label ininit()
Rename jump labels invirtcons_probe()
Rename jump labels inadd_port()
Rename a jump label inport_fops_open()
Rename a jump label inport_fops_splice_write()Rename jump labels inport_fops_write()
Rename a jump label in__send_to_port()
Rename jump labels inalloc_buf()
Rename a jump label in five functions
Quoted 2 lines
drivers/char/virtio_console.c | 155 ++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 68 deletions(-)
Would you like to take another look at change possibilities for this software module?
Regards,
Markus
cover clk/Renesas-MSTP: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:48:48 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Use kmalloc_array() in cpg_mstp_clocks_init()
Delete an error message for a failed memory allocation Less function calls in cpg_mstp_clocks_init() after error detection Rename jump labels in cpg_mstp_attach_dev()
drivers/clk/renesas/clk-mstp.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/4 clk/Renesas-MSTP: Use kmalloc_array() in cpg_mstp_clocks_init()
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:10:47 +0200
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/clk/renesas/clk-mstp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/renesas/clk-mstp.c +1 -1
@@ -167,7 +167,7 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)unsigned int i; group =kzalloc (sizeof (*group),GFP_KERNEL ); - clks =kmalloc (MSTP_MAX_CLOCKS *sizeof (*clks),GFP_KERNEL ); + clks =kmalloc_array (MSTP_MAX_CLOCKS ,sizeof (*clks),GFP_KERNEL );if (group =NULL || clks =NULL ) {kfree (group);kfree (clks);
Signature · 1 line
2.10.0
Re: [PATCH 1/4] clk/Renesas-MSTP: Use kmalloc_array() in cpg_mstp_clocks_init()
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:10:47 +0200A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
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
Stephen Boyd
AppliedRe: [PATCH 1/4] clk/Renesas-MSTP: Use kmalloc_array() in cpg_mstp_clocks_init()
In reply to SF Markus ElfringQuoted 11 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:10:47 +0200A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 2/4 clk/Renesas-MSTP: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:17:18 +0200
Omit an extra message for a memory allocation failure in this function.
--- drivers/clk/renesas/clk-mstp.c | 1 - 1 file changed, 1 deletion(-)
drivers/clk/renesas/clk-mstp.c +0 -1
@@ -171,7 +171,6 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)if (group =NULL || clks =NULL ) {kfree (group);kfree (clks); -pr_err ("%s: failed to allocate group\n" , __func__);return ; }
Signature · 1 line
2.10.0
Re: [PATCH 2/4] clk/Renesas-MSTP: Delete an error message for a failed memory allocation
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:17:18 +0200Omit an extra message for a memory allocation failure in this function.
Signed-off-by Markus Elfring <[email protected]>
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
Laurent Pinchart
maintainerRe: [PATCH 2/4] clk/Renesas-MSTP: Delete an error message for a failed memory allocation
Quoted 6 lines · On Thursday 15 Sep 2016 21:07:17 Geert Uytterhoeven wrote:
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:17:18 +0200Omit an extra message for a memory allocation failure in this function.
Quoted 7 lines
Quoted 5 lines
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refacto
r_Strings-WSang_0.pdfSigned-off-by Markus Elfring <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>
There are two other memory allocation failures printed by drivers in the same directory that, you'll get my ack if you extend this patch to remove the three messages in one go.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/4] clk/Renesas-MSTP: Delete an error message for a failed memory allocation
Quoted 11 lines · Laurent Pinchart
Quoted 10 lines · On Thursday 15 Sep 2016 21:07:17 Geert Uytterhoeven wrote:
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:17:18 +0200Omit an extra message for a memory allocation failure in this function.
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refacto
r_Strings-WSang_0.pdf
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>There are two other memory allocation failures printed by drivers in the same directory that, you'll get my ack if you extend this patch to remove the three messages in one go.
I agree.
Re: clk/Renesas-MSTP: Delete an error message for a failed memory allocation
In reply to Laurent PinchartQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Omit an extra message for a memory allocation failure in this function.
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refacto
r_Strings-WSang_0.pdf
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>There are two other memory allocation failures printed by drivers in the same directory that, you'll get my ack
Does this kind of feedback express a general acceptance for the deletion of similar error messages?
Quoted 1 line
if you extend this patch to remove the three messages in one go.
Does this wish influence the handling of suggested changes for the source file "drivers/clk/renesas/clk-mstp.c" anyhow?
https://patchwork.kernel.org/patch/9332363/
Regards,
Markus
Laurent Pinchart
maintainerRe: clk/Renesas-MSTP: Delete an error message for a failed memory allocation
Quoted 8 lines · On Thursday 15 Sep 2016 22:17:41 SF Markus Elfring wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Omit an extra message for a memory allocation failure in this function.
Link:
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refact
or_Strings-WSang_0.pdfSigned-off-by Markus Elfring <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Geert Uytterhoeven <[email protected]>There are two other memory allocation failures printed by drivers in the same directory that, you'll get my ack
Does this kind of feedback express a general acceptance for the deletion of similar error messages?
No, it's my opinion only.
Quoted 5 lines
Quoted 1 line
if you extend this patch to remove the three messages in one go.
Does this wish influence the handling of suggested changes for the source file "
drivers/clk/renesas/clk-mstp.c" anyhow?
https://patchwork.kernel.org/patch/9332363/
Yes, please submit a new version of this patch that removes all the memory allocation error messages from drivers/clk/renesas/ in one go.
Signature · 3 lines
Regards, Laurent Pinchart
Re: clk/Renesas-MSTP: Delete an error message for a failed memory allocation
Quoted 6 lines
Quoted 3 lines
Does this wish influence the handling of suggested changes for the source file "
drivers/clk/renesas/clk-mstp.c" anyhow?
https://patchwork.kernel.org/patch/9332363/Yes, please submit a new version of this patch that removes all the memory allocation error messages from
drivers/clk/renesas/in one go.
I find this kind of feedback a bit surprising and it seems to be promising to increase software development in this design direction.
Have you got any corresponding scripts for the semantic patch language prepared to make such a source code adjustment safer (and a bit more convenient with the help of the Coccinelle software)?
I am also curious on how the change acceptance will evolve for the other three update steps from this patch series when this one indicates further software update opportunities already.
Regards,
Markus
PATCH 1/1 clk/Renesas: Delete an error message for a failed memory allocation in three functions
In reply to Laurent PinchartFrom: Markus Elfring <[email protected]>
Date: Mon, 25 Sep 2017 10:10:51 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus fix affected source code places.
--- drivers/clk/renesas/clk-mstp.c | 5 +---- drivers/clk/renesas/clk-rcar-gen2.c | 1 - 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/clk/renesas/clk-mstp.c +1 -4
@@ -156,10 +156,8 @@ static struct clk * __init cpg_mstp_clock_register(const char *name,struct clk *clk; clock =kzalloc (sizeof (*clock),GFP_KERNEL ); -if (!clock) { -pr_err ("%s: failed to allocate MSTP clock.\n" , __func__); +if (!clock)return ERR_PTR (-ENOMEM ); - } init.name = name; init.ops = &cpg_mstp_clock_ops;
@@ -196,7 +194,6 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)if (group =NULL || clks =NULL ) {kfree (group);kfree (clks); -pr_err ("%s: failed to allocate group\n" , __func__);return ; }
drivers/clk/renesas/clk-rcar-gen2.c +0 -1
@@ -423,7 +423,6 @@ static void __init rcar_gen2_cpg_clocks_init(struct device_node *np)/* We're leaking memory on purpose, there's no point in cleaning * up as the system won't boot anyway. */ -pr_err ("%s: failed to allocate cpg\n" , __func__);return ; }
Signature · 1 line
2.14.1
Re: [PATCH] clk/Renesas: Delete an error message for a failed memory allocation in three functions
Hi Markus,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 25 Sep 2017 10:10:51 +0200The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus fix affected source code places.
Signed-off-by Markus Elfring <[email protected]>
i.e. will queue in clk-renesas-for-v4.15, split in two commits:
- clk: renesas: rcar-gen2: Delete error message for failed memory allocation
- clk: renesas: mstp: Delete error messages for failed memory allocations
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 3/4 clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:30:27 +0200
The kfree() function was called in up to two cases
by the cpg_mstp_clocks_init() function during error handling even if the passed variable contained a null pointer.
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
* Return directly after a call of the function "kzalloc" failed at the beginning.
--- drivers/clk/renesas/clk-mstp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/renesas/clk-mstp.c +4 -2
@@ -167,10 +167,12 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)unsigned int i; group =kzalloc (sizeof (*group),GFP_KERNEL ); +if (!group) +return ; + clks =kmalloc_array (MSTP_MAX_CLOCKS ,sizeof (*clks),GFP_KERNEL ); -if (group =NULL || clks =NULL ) { +if (!clks) {kfree (group); -kfree (clks);return ; }
Signature · 1 line
2.10.0
Geert Uytterhoeven
reviewerRe: [PATCH 3/4] clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection
Hi Markus,
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:30:27 +0200The
kfree()function was called in up to two cases
by thecpg_mstp_clocks_init()function during error handling even if the passed variable contained a null pointer.
It's perfectly legal to call kfree() on a NULL pointer.
Quoted 9 lines
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"* Return directly after a call of the function "kzalloc" failed at the beginning.
Both calls are already close together.
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/clk/renesas/clk-mstp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
In addition, your patch increases the LoC, IMHO without improving the code.
Quoted 9 lines
drivers/clk/renesas/clk-mstp.c +0
-0@@ -167,10 +167,12 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)unsigned int i; group =kzalloc (sizeof (*group),GFP_KERNEL );
drivers/clk/renesas/clk-mstp.c static void __init cpg_mstp_clocks_init(struct device_node *np) · line 177
Quoted 10 lines
drivers/clk/renesas/clk-mstp.c +4
-2+if (!group) +return ; + clks =kmalloc_array (MSTP_MAX_CLOCKS ,sizeof (*clks),GFP_KERNEL ); -if (group =NULL || clks =NULL ) { +if (!clks) {kfree (group); -kfree (clks);return ; }
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
Re: [PATCH 3/4] clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection
Quoted 1 line
It's perfectly legal to call
kfree()on a NULL pointer.
I know this function property well.
Quoted 11 lines
Quoted 9 lines
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"* Return directly after a call of the function "kzalloc" failed at the beginning.
Both calls are already close together.
Can it be that an other software development concern is eventually overlooked because of this "neighbourship" (or is categorised with a lower priority)?
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
* How much will it matter in general that one function call was performed in this use case without checking its return values immediately?
* Should it usually be determined quicker if a required resource like memory could be acquired before trying the next allocation?
Quoted 1 line
In addition, your patch increases the LoC, IMHO without improving the code.
I find this consequence still debatable.
Quoted 7 lines
Quoted 7 lines
drivers/clk/renesas/clk-mstp.c +0
-0@@ -167,10 +167,12 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)unsigned int i;
Quoted 11 lines
drivers/clk/renesas/clk-mstp.c static void __init cpg_mstp_clocks_init(struct device_node *np) · line 177
Quoted 11 lines
drivers/clk/renesas/clk-mstp.c +4
-2group =kzalloc (sizeof (*group),GFP_KERNEL ); +if (!group) +return ; + clks =kmalloc_array (MSTP_MAX_CLOCKS ,sizeof (*clks),GFP_KERNEL ); -if (group =NULL || clks =NULL ) { +if (!clks) {kfree (group); -kfree (clks);return ; }
Is this update suggestion worth for another look?
Regards,
Markus
Geert Uytterhoeven
reviewerRe: [PATCH 3/4] clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection
Quoted 16 lines · SF Markus Elfring
Quoted 11 lines
Quoted 9 lines
* Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"* Return directly after a call of the function "kzalloc" failed at the beginning.
Both calls are already close together.
Can it be that an other software development concern is eventually overlooked because of this "neighbourship" (or is categorised with a lower priority)?
Quoted 8 lines
I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module.
* How much will it matter in general that one function call was performed in this use case without checking its return values immediately?
* Should it usually be determined quicker if a required resource like memory could be acquired before trying the next allocation?
Note that if memory allocation fails in this driver, the system won't boot at all. So even not checking for allocation failures at all could be acceptable.
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
Re: clk/Renesas-MSTP: Less function calls in cpg_mstp_clocks_init() after error detection
Quoted 5 lines
Quoted 2 lines
* Should it usually be determined quicker if a required resource like memory could be acquired before trying the next allocation?
Note that if memory allocation fails in this driver, the system won't boot at all.
Thanks for this information.
Quoted 1 line
So even not checking for allocation failures at all could be acceptable.
I find this opinion interesting somehow.
I would generally prefer to check return values from various function calls immediately instead of keeping the discussed source code structure unchanged.
Regards,
Markus
PATCH 4/4 clk/Renesas-MSTP: Rename jump labels in cpg_mstp_attach_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:41:50 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/clk/renesas/clk-mstp.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/clk/renesas/clk-mstp.c +7 -9
@@ -256,19 +256,18 @@ int cpg_mstp_attach_dev(struct generic_pm_domain *unused, struct device *dev) &clkspec)) {if (of_device_is_compatible (clkspec.np,"renesas,cpg-mstp-clocks" )) - goto found; + goto get_clk;/* BSC on r8a73a4/sh73a0 uses zb_clk instead of an mstp clock */ if (!strcmp (clkspec.np->name,"zb_clk" )) - goto found; + goto get_clk;of_node_put (clkspec.np); i++; }return 0 ; - -found: + get_clk: clk =of_clk_get_from_provider (&clkspec);of_node_put (clkspec.np);
@@ -278,20 +277,19 @@ found: error =pm_clk_create (dev);if (error) {dev_err (dev,"pm_clk_create failed %d\n" , error); - goto fail_put; + goto put_clk; } error =pm_clk_add_clk (dev, clk);if (error) {dev_err (dev,"pm_clk_add_clk %pC failed %d\n" , clk, error); - goto fail_destroy; + goto destroy_clk; }return 0 ; - -fail_destroy: + destroy_clk:pm_clk_destroy (dev); -fail_put: + put_clk:clk_put (clk);return error; }
Signature · 1 line
2.10.0
Geert Uytterhoeven
reviewerRe: [PATCH 4/4] clk/Renesas-MSTP: Rename jump labels in cpg_mstp_attach_dev()
Hi Markus,
Quoted 24 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 14 Sep 2016 21:41:50 +0200Adjust jump labels according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/clk/renesas/clk-mstp.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)drivers/clk/renesas/clk-mstp.c +1
-2@@ -256,19 +256,18 @@ int cpg_mstp_attach_dev(struct generic_pm_domain *unused, struct device *dev) &clkspec)) {if (of_device_is_compatible (clkspec.np,"renesas,cpg-mstp-clocks" )) - goto found; + goto get_clk;/* BSC on r8a73a4/sh73a0 uses zb_clk instead of an mstp clock */ if (!strcmp (clkspec.np->name,"zb_clk" )) - goto found;
drivers/clk/renesas/clk-mstp.c int cpg_mstp_attach_dev(struct generic_pm_domain *unused, struct device *dev) · line 270
Quoted 10 lines
drivers/clk/renesas/clk-mstp.c +2
-2+ goto get_clk;of_node_put (clkspec.np); i++; }return 0 ; - -found: + get_clk:
"Choose label names which say what the goto does or why the goto exists."
I prefer the "why" over the "what".
And the "indent labels with a single space" rule will be removed soon, as there's no longer a technical reason for it after
https://lkml.org/lkml/2016/9/7/316
Quoted 15 lines
drivers/clk/renesas/clk-mstp.c +1
-2clk =of_clk_get_from_provider (&clkspec);of_node_put (clkspec.np);@@ -278,20 +277,19 @@ found: error =pm_clk_create (dev);if (error) {dev_err (dev,"pm_clk_create failed %d\n" , error); - goto fail_put; + goto put_clk; } error =pm_clk_add_clk (dev, clk);if (error) {dev_err (dev,"pm_clk_add_clk %pC failed %d\n" , clk, error); - goto fail_destroy;
drivers/clk/renesas/clk-mstp.c found: · line 292
Quoted 10 lines
drivers/clk/renesas/clk-mstp.c +3
-3+ goto destroy_clk; }return 0 ; - -fail_destroy: + destroy_clk:pm_clk_destroy (dev); -fail_put: + put_clk:
Same here.
drivers/clk/renesas/clk-mstp.c found: · line 295
Quoted 3 lines
drivers/clk/renesas/clk-mstp.c +0
-0clk_put (clk);return error; }
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
Re: clk/Renesas-MSTP: Rename jump labels in cpg_mstp_attach_dev()
Quoted 3 lines
"Choose label names which say what the goto does or why the goto exists."
I prefer the "why" over the "what".
Does your opinion indicate also that you would appreciate another adjustment around the quoted sentence from "Chapter 7: Centralized exiting of functions" of the document "CodingStyle"?
Would you like to achieve that the potential for confusion will be reduced a bit more there?
Quoted 1 line
And the "indent labels with a single space" rule will be removed soon,
I am unsure on how this "story" will evolve further.
Will the indentation rules become any more precise for Linux source code?
Quoted 2 lines
as there's no longer a technical reason for it after
https://lkml.org/lkml/2016/9/7/316
The software update "Set git diff driver for C source code files" is also interesting for current versions.
Will language-specific rules which are supported by recent Git software influence any capabilities for the command "diff --show-c-function"?
Regards,
Markus
crypto-caamhash: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 16:27:23 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (6):
Use kmalloc_array() in ahash_setkey()
Rename jump labels in ahash_setkey()
Rename a jump label in five functions
Return a value directly in caam_hash_cra_init() Delete an unnecessary initialisation in seven functions Move common error handling code in two functions
drivers/crypto/caam/caamhash.c | 111 +++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 59 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/6 crypto-caamhash: Use kmalloc_array() in ahash_setkey()
From: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 11:20:09 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/crypto/caam/caamhash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/crypto/caam/caamhash.c +3 -2
@@ -525,8 +525,9 @@ static int ahash_setkey(struct crypto_ahash *ahash,#endif if (keylen > blocksize) { - hashed_key =kmalloc (sizeof (u8) * digestsize,GFP_KERNEL | -GFP_DMA ); + hashed_key =kmalloc_array (digestsize, +sizeof (*hashed_key), +GFP_KERNEL |GFP_DMA );if (!hashed_key)return -ENOMEM ; ret = hash_digest_key(ctx, key, &keylen, hashed_key,
Signature · 1 line
2.10.0
Horia Geanta Neag
maintainerRe: [PATCH 1/6] crypto-caamhash: Use kmalloc_array() in ahash_setkey()
Quoted 23 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 11:20:09 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/crypto/caam/caamhash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/crypto/caam/caamhash.c +0
-0
drivers/crypto/caam/caamhash.c static int ahash_setkey(struct crypto_ahash *ahash, · line 530
Quoted 8 lines
drivers/crypto/caam/caamhash.c +3
-2@@ -525,8 +525,9 @@ static int ahash_setkey(struct crypto_ahash *ahash,#endif if (keylen > blocksize) { - hashed_key =kmalloc (sizeof (u8) * digestsize,GFP_KERNEL | -GFP_DMA ); + hashed_key =kmalloc_array (digestsize, +sizeof (*hashed_key), +GFP_KERNEL |GFP_DMA );
While correct, instead I would go with kmalloc() and get rid of sizeof(u8).
Horia
PATCH 2/6 crypto-caamhash: Rename jump labels in ahash_setkey()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 13:54:49 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/crypto/caam/caamhash.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/crypto/caam/caamhash.c +5 -6
@@ -533,7 +533,7 @@ static int ahash_setkey(struct crypto_ahash *ahash, ret =hash_digest_key (ctx, key, &keylen, hashed_key, digestsize);if (ret) - goto badkey; + goto bad_free_key; key = hashed_key; }
@@ -551,14 +551,14 @@ static int ahash_setkey(struct crypto_ahash *ahash, ret =gen_split_hash_key (ctx, key, keylen);if (ret) - goto badkey; + goto bad_free_key; ctx->key_dma =dma_map_single (jrdev, ctx->key, ctx->split_key_pad_len,DMA_TO_DEVICE );if (dma_mapping_error (jrdev, ctx->key_dma)) {dev_err (jrdev,"unable to map key i/o memory\n" ); ret = -ENOMEM ; - goto map_err; + goto error_free_key; }#ifdef DEBUG print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
@@ -571,11 +571,10 @@ static int ahash_setkey(struct crypto_ahash *ahash,dma_unmap_single (jrdev, ctx->key_dma, ctx->split_key_pad_len,DMA_TO_DEVICE ); } - -map_err: + error_free_key:kfree (hashed_key);return ret; -badkey: + bad_free_key:kfree (hashed_key);crypto_ahash_set_flags (ahash,CRYPTO_TFM_RES_BAD_KEY_LEN );return -EINVAL ;
Signature · 1 line
2.10.0
PATCH 3/6 crypto-caamhash: Rename a jump label in five functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 14:43:38 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/crypto/caam/caamhash.c | 49 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
drivers/crypto/caam/caamhash.c +22 -27
@@ -889,7 +889,7 @@ static int ahash_update_ctx(struct ahash_request *req) ret =ctx_map_to_sec4_sg (desc, jrdev, state, ctx->ctx_len, edesc->sec4_sg,DMA_BIDIRECTIONAL );if (ret) - goto err; + goto unmap_ctx; state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1,
@@ -919,7 +919,7 @@ static int ahash_update_ctx(struct ahash_request *req)if (dma_mapping_error (jrdev, edesc->sec4_sg_dma)) {dev_err (jrdev,"unable to map S/G table\n" ); ret = -ENOMEM ; - goto err; + goto unmap_ctx; } append_seq_in_ptr(desc, edesc->sec4_sg_dma, ctx->ctx_len +
@@ -935,7 +935,7 @@ static int ahash_update_ctx(struct ahash_request *req) ret =caam_jr_enqueue (jrdev, desc, ahash_done_bi, req);if (ret) - goto err; + goto unmap_ctx; ret = -EINPROGRESS ; }else if (*next_buflen) {
@@ -953,8 +953,7 @@ static int ahash_update_ctx(struct ahash_request *req)#endif return ret; - - err: + unmap_ctx:ahash_unmap_ctx (jrdev, edesc, req, ctx->ctx_len,DMA_BIDIRECTIONAL );kfree (edesc);return ret;
@@ -996,7 +995,7 @@ static int ahash_final_ctx(struct ahash_request *req) ret =ctx_map_to_sec4_sg (desc, jrdev, state, ctx->ctx_len, edesc->sec4_sg,DMA_TO_DEVICE );if (ret) - goto err; + goto unmap_ctx; state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, buf, state->buf_dma, buflen,
@@ -1009,7 +1008,7 @@ static int ahash_final_ctx(struct ahash_request *req)if (dma_mapping_error (jrdev, edesc->sec4_sg_dma)) {dev_err (jrdev,"unable to map S/G table\n" ); ret = -ENOMEM ; - goto err; + goto unmap_ctx; } append_seq_in_ptr(desc, edesc->sec4_sg_dma, ctx->ctx_len + buflen,
@@ -1020,7 +1019,7 @@ static int ahash_final_ctx(struct ahash_request *req)if (dma_mapping_error (jrdev, edesc->dst_dma)) {dev_err (jrdev,"unable to map dst\n" ); ret = -ENOMEM ; - goto err; + goto unmap_ctx; }#ifdef DEBUG
@@ -1030,11 +1029,10 @@ static int ahash_final_ctx(struct ahash_request *req) ret =caam_jr_enqueue (jrdev, desc, ahash_done_ctx_src, req);if (ret) - goto err; + goto unmap_ctx;return -EINPROGRESS ; - -err: + unmap_ctx:ahash_unmap_ctx (jrdev, edesc, req, digestsize,DMA_FROM_DEVICE );kfree (edesc);return ret;
@@ -1094,7 +1092,7 @@ static int ahash_finup_ctx(struct ahash_request *req) ret =ctx_map_to_sec4_sg (desc, jrdev, state, ctx->ctx_len, edesc->sec4_sg,DMA_TO_DEVICE );if (ret) - goto err; + goto unmap_ctx; state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, buf, state->buf_dma, buflen,
@@ -1104,14 +1102,14 @@ static int ahash_finup_ctx(struct ahash_request *req) sec4_sg_src_index, ctx->ctx_len + buflen, req->nbytes);if (ret) - goto err; + goto unmap_ctx; edesc->dst_dma =map_seq_out_ptr_result (desc, jrdev, req->result, digestsize);if (dma_mapping_error (jrdev, edesc->dst_dma)) {dev_err (jrdev,"unable to map dst\n" ); ret = -ENOMEM ; - goto err; + goto unmap_ctx; }#ifdef DEBUG
@@ -1121,11 +1119,10 @@ static int ahash_finup_ctx(struct ahash_request *req) ret =caam_jr_enqueue (jrdev, desc, ahash_done_ctx_src, req);if (ret) - goto err; + goto unmap_ctx;return -EINPROGRESS ; - -err: + unmap_ctx:ahash_unmap_ctx (jrdev, edesc, req, digestsize,DMA_FROM_DEVICE );kfree (edesc);return ret;
@@ -1350,14 +1347,14 @@ static int ahash_update_no_ctx(struct ahash_request *req)if (dma_mapping_error (jrdev, edesc->sec4_sg_dma)) {dev_err (jrdev,"unable to map S/G table\n" ); ret = -ENOMEM ; - goto err; + goto unmap_ctx; }append_seq_in_ptr (desc, edesc->sec4_sg_dma, to_hash,LDST_SGF ); ret =map_seq_out_ptr_ctx (desc, jrdev, state, ctx->ctx_len);if (ret) - goto err; + goto unmap_ctx;#ifdef DEBUG print_hex_dump(KERN_ERR, "jobdesc@"__stringify(__LINE__)": ",
@@ -1367,7 +1364,7 @@ static int ahash_update_no_ctx(struct ahash_request *req) ret =caam_jr_enqueue (jrdev, desc, ahash_done_ctx_dst, req);if (ret) - goto err; + goto unmap_ctx; ret = -EINPROGRESS ; state->update = ahash_update_ctx;
@@ -1388,8 +1385,7 @@ static int ahash_update_no_ctx(struct ahash_request *req)#endif return ret; - -err: + unmap_ctx:ahash_unmap_ctx (jrdev, edesc, req, ctx->ctx_len,DMA_TO_DEVICE );kfree (edesc);return ret;
@@ -1548,7 +1544,7 @@ static int ahash_update_first(struct ahash_request *req) ret =ahash_edesc_add_src (ctx, edesc, req, mapped_nents,0 ,0 , to_hash);if (ret) - goto err; + goto unmap_ctx;if (*next_buflen) scatterwalk_map_and_copy(next_buf, req->src, to_hash,
@@ -1558,7 +1554,7 @@ static int ahash_update_first(struct ahash_request *req) ret =map_seq_out_ptr_ctx (desc, jrdev, state, ctx->ctx_len);if (ret) - goto err; + goto unmap_ctx;#ifdef DEBUG print_hex_dump(KERN_ERR, "jobdesc@"__stringify(__LINE__)": ",
@@ -1568,7 +1564,7 @@ static int ahash_update_first(struct ahash_request *req) ret =caam_jr_enqueue (jrdev, desc, ahash_done_ctx_dst, req);if (ret) - goto err; + goto unmap_ctx; ret = -EINPROGRESS ; state->update = ahash_update_ctx;
@@ -1588,8 +1584,7 @@ static int ahash_update_first(struct ahash_request *req)#endif return ret; - -err: + unmap_ctx:ahash_unmap_ctx (jrdev, edesc, req, ctx->ctx_len,DMA_TO_DEVICE );kfree (edesc);return ret;
Signature · 1 line
2.10.0
PATCH 4/6 crypto-caamhash: Return a value directly in caam_hash_cra_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 14:56:12 +0200
* Return a value at the end without storing it in an intermediate variable.
* Delete the local variable "ret" which became unnecessary with this refactoring.
--- drivers/crypto/caam/caamhash.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/crypto/caam/caamhash.c +1 -5
@@ -1846,7 +1846,6 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)HASH_MSG_LEN +SHA256_DIGEST_SIZE ,HASH_MSG_LEN +64 , HASH_MSG_LEN + SHA512_DIGEST_SIZE }; -int ret =0 ;/* * Get a Job ring from Job Ring driver to ensure in-order
@@ -1866,10 +1865,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)crypto_ahash_set_reqsize (__crypto_ahash_cast (tfm),sizeof (struct caam_hash_state )); - - ret =ahash_set_sh_desc (ahash); - -return ret; +return ahash_set_sh_desc (ahash); }static void caam_hash_cra_exit (struct crypto_tfm *tfm)
Signature · 1 line
2.10.0
PATCH 5/6 crypto-caamhash: Delete an unnecessary initialisation in seven functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 15:24:02 +0200
The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/crypto/caam/caamhash.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/crypto/caam/caamhash.c +7 -7
@@ -440,7 +440,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,u32 *desc;struct split_key_result result;dma_addr_t src_dma, dst_dma; -int ret =0 ; +int ret; desc =kmalloc (CAAM_CMD_SZ *8 +CAAM_PTR_SZ *2 ,GFP_KERNEL |GFP_DMA );if (!desc) {
@@ -517,7 +517,7 @@ static int ahash_setkey(struct crypto_ahash *ahash,struct device *jrdev = ctx->jrdev;int blocksize =crypto_tfm_alg_blocksize (&ahash->base);int digestsize =crypto_ahash_digestsize (ahash); -int ret =0 ; +int ret;u8 *hashed_key =NULL ;#ifdef DEBUG
@@ -975,7 +975,7 @@ static int ahash_final_ctx(struct ahash_request *req)int sec4_sg_bytes, sec4_sg_src_index;int digestsize =crypto_ahash_digestsize (ahash);struct ahash_edesc *edesc; -int ret =0 ; +int ret; sec4_sg_src_index =1 + (buflen ?1 :0 ); sec4_sg_bytes = sec4_sg_src_index *sizeof (struct sec4_sg_entry );
@@ -1055,7 +1055,7 @@ static int ahash_finup_ctx(struct ahash_request *req)int src_nents, mapped_nents;int digestsize =crypto_ahash_digestsize (ahash);struct ahash_edesc *edesc; -int ret =0 ; +int ret; src_nents =sg_nents_for_len (req->src, req->nbytes);if (src_nents <0 ) {
@@ -1139,7 +1139,7 @@ static int ahash_digest(struct ahash_request *req)int digestsize =crypto_ahash_digestsize (ahash);int src_nents, mapped_nents;struct ahash_edesc *edesc; -int ret =0 ; +int ret; src_nents =sg_nents_for_len (req->src, req->nbytes);if (src_nents <0 ) {
@@ -1218,7 +1218,7 @@ static int ahash_final_no_ctx(struct ahash_request *req)u32 *desc;int digestsize =crypto_ahash_digestsize (ahash);struct ahash_edesc *edesc; -int ret =0 ; +int ret;/* allocate space for base edesc and hw desc commands, link tables */ edesc = ahash_edesc_alloc(ctx, 0, ctx->sh_desc_digest,
@@ -1408,7 +1408,7 @@ static int ahash_finup_no_ctx(struct ahash_request *req)int sec4_sg_bytes, sec4_sg_src_index, src_nents, mapped_nents;int digestsize =crypto_ahash_digestsize (ahash);struct ahash_edesc *edesc; -int ret =0 ; +int ret; src_nents =sg_nents_for_len (req->src, req->nbytes);if (src_nents <0 ) {
Signature · 1 line
2.10.0
PATCH 6/6 crypto-caamhash: Move common error handling code in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 16:00:55 +0200
Move statements for error handling which were identical in two if branches to the end of these functions.
--- drivers/crypto/caam/caamhash.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/crypto/caam/caamhash.c +14 -12
@@ -1231,9 +1231,7 @@ static int ahash_final_no_ctx(struct ahash_request *req) state->buf_dma =dma_map_single (jrdev, buf, buflen,DMA_TO_DEVICE );if (dma_mapping_error (jrdev, state->buf_dma)) {dev_err (jrdev,"unable to map src\n" ); -ahash_unmap (jrdev, edesc, req, digestsize); -kfree (edesc); -return -ENOMEM ; + goto unmap; }append_seq_in_ptr (desc, state->buf_dma, buflen,0 );
@@ -1242,9 +1240,7 @@ static int ahash_final_no_ctx(struct ahash_request *req) digestsize);if (dma_mapping_error (jrdev, edesc->dst_dma)) {dev_err (jrdev,"unable to map dst\n" ); -ahash_unmap (jrdev, edesc, req, digestsize); -kfree (edesc); -return -ENOMEM ; + goto unmap; } edesc->src_nents =0 ;
@@ -1262,6 +1258,11 @@ static int ahash_final_no_ctx(struct ahash_request *req) }return ret; + unmap: +ahash_unmap (jrdev, edesc, req, digestsize); +kfree (edesc); +return -ENOMEM ; + }/* submit ahash update if it the first job descriptor after update */
@@ -1453,18 +1454,14 @@ static int ahash_finup_no_ctx(struct ahash_request *req) req->nbytes);if (ret) {dev_err (jrdev,"unable to map S/G table\n" ); -ahash_unmap (jrdev, edesc, req, digestsize); -kfree (edesc); -return -ENOMEM ; + goto unmap; } edesc->dst_dma =map_seq_out_ptr_result (desc, jrdev, req->result, digestsize);if (dma_mapping_error (jrdev, edesc->dst_dma)) {dev_err (jrdev,"unable to map dst\n" ); -ahash_unmap (jrdev, edesc, req, digestsize); -kfree (edesc); -return -ENOMEM ; + goto unmap; }#ifdef DEBUG
@@ -1481,6 +1478,11 @@ static int ahash_finup_no_ctx(struct ahash_request *req) }return ret; + unmap: +ahash_unmap (jrdev, edesc, req, digestsize); +kfree (edesc); +return -ENOMEM ; + }/* submit first update job descriptor after init */
Signature · 1 line
2.10.0
Re: crypto-caamhash: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 14 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 16:27:23 +0200Some update suggestions were taken into account
from static source code analysis.Markus Elfring (6):
Usekmalloc_array()inahash_setkey()
Rename jump labels inahash_setkey()
Rename a jump label in five functions
Return a value directly incaam_hash_cra_init()Delete an unnecessary initialisation in seven functions Move common error handling code in two functions
Quoted 3 lines
drivers/crypto/caam/caamhash.c | 111 +++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 59 deletions(-)
Thanks Markus!
For patches 2-6:
though headline prefix should be changed to "crypto: caam -"
Horia
--
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
Herbert Xu
maintainerRe: crypto-caamhash: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 14 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 15 Sep 2016 16:27:23 +0200Some update suggestions were taken into account
from static source code analysis.Markus Elfring (6):
Usekmalloc_array()inahash_setkey()
Rename jump labels inahash_setkey()
Rename a jump label in five functions
Return a value directly incaam_hash_cra_init()Delete an unnecessary initialisation in seven functions Move common error handling code in two functions
Quoted 2 lines
drivers/crypto/caam/caamhash.c | 111 +++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 59 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
cover ste_dma40: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:56:56 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (24):
Use kmalloc_array() in d40_lcla_allocate()
Return directly after a failed kmalloc_array()
Rename a jump label in d40_lcla_allocate()
Move an assignment in d40_lcla_allocate()
Improve a size determination in d40_of_probe()
Replace four kzalloc() calls by kcalloc() in d40_hw_detect_init() Use kmalloc_array() in d40_hw_detect_init()
Less checks in d40_hw_detect_init() after error detection Delete unnecessary variable initialisations in d40_hw_detect_init() Adjust the position of a jump label in d40_probe() Rename a jump label in d40_probe()
Rename jump labels in d40_dmaengine_init()
Rename a jump label in d40_alloc_chan_resources()
One check less in d40_prep_sg() after error detection Move two assignments in d40_prep_sg()
Rename a jump label in d40_prep_desc()
Move an assignment in d40_prep_desc()
Rename a jump label in d40_is_paused()
Rename a jump label in d40_free_dma()
Rename a jump label in d40_alloc_mask_free()
Rename jump labels in d40_alloc_mask_set()
Rename a jump label in dma_tasklet()
Rename a jump label in __d40_execute_command_phy() Rename a jump label in d40_log_lli_to_lcxa()
drivers/dma/ste_dma40.c | 253 +++++++++++++++++++++++------------------------- 1 file changed, 122 insertions(+), 131 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/24 ste_dma40: Use kmalloc_array() in d40_lcla_allocate()
From: Markus Elfring <[email protected]>
Date: Fri, 16 Sep 2016 17:56:07 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/dma/ste_dma40.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +3 -3
@@ -3409,9 +3409,9 @@ static int __init d40_lcla_allocate(struct d40_base *base)* To full fill this hardware requirement without wasting 256 kb * we allocate pages until we get an aligned one. */ - page_list =kmalloc (sizeof (unsigned long ) *MAX_LCLA_ALLOC_ATTEMPTS , -GFP_KERNEL ); - + page_list =kmalloc_array (MAX_LCLA_ALLOC_ATTEMPTS , +sizeof (*page_list), +GFP_KERNEL );if (!page_list) { ret = -ENOMEM ; goto failure;
Signature · 1 line
2.10.0
PATCH 2/24 ste_dma40: Return directly after a failed kmalloc_array()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 08:21:30 +0200
Return directly after a memory allocation failed in this function at the beginning.
--- drivers/dma/ste_dma40.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma/ste_dma40.c +2 -4
@@ -3412,10 +3412,8 @@ static int __init d40_lcla_allocate(struct d40_base *base) page_list =kmalloc_array (MAX_LCLA_ALLOC_ATTEMPTS ,sizeof (*page_list),GFP_KERNEL ); -if (!page_list) { - ret = -ENOMEM ; - goto failure; - } +if (!page_list) +return -ENOMEM ;/* Calculating how many pages that are required */ base->lcla_pool.pages =SZ_1K * base->num_phy_chans /PAGE_SIZE ;
Signature · 1 line
2.10.0
PATCH 3/24 ste_dma40: Rename a jump label in d40_lcla_allocate()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 08:23:37 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dma/ste_dma40.c +4 -4
@@ -3429,7 +3429,7 @@ static int __init d40_lcla_allocate(struct d40_base *base)for (j =0 ; j < i; j++)free_pages (page_list[j], base->lcla_pool.pages); - goto failure; + goto free_page_list; } if ((virt_to_phys((void *)page_list[i]) &
@@ -3456,7 +3456,7 @@ static int __init d40_lcla_allocate(struct d40_base *base) GFP_KERNEL);if (!base->lcla_pool.base_unaligned) { ret = -ENOMEM ; - goto failure; + goto free_page_list; } base->lcla_pool.base = PTR_ALIGN(base->lcla_pool.base_unaligned,
@@ -3469,12 +3469,12 @@ static int __init d40_lcla_allocate(struct d40_base *base)if (dma_mapping_error (base->dev, pool->dma_addr)) { pool->dma_addr =0 ; ret = -ENOMEM ; - goto failure; + goto free_page_list; }writel (virt_to_phys (base->lcla_pool.base), base->virtbase +D40_DREG_LCLA ); -failure: + free_page_list:kfree (page_list);return ret; }
Signature · 1 line
2.10.0
PATCH 4/24 ste_dma40: Move an assignment in d40_lcla_allocate()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 08:24:46 +0200
Move one assignment for the local variable "ret" so that its setting will only be performed after corresponding data processing succeeded by this function.
--- drivers/dma/ste_dma40.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/ste_dma40.c +2 -1
@@ -3402,7 +3402,7 @@ static int __init d40_lcla_allocate(struct d40_base *base)struct d40_lcla_pool *pool = &base->lcla_pool;unsigned long *page_list;int i, j; -int ret =0 ; +int ret;/* * This is somewhat ugly. We need 8192 bytes that are 18 bit aligned,
@@ -3474,6 +3474,7 @@ static int __init d40_lcla_allocate(struct d40_base *base)writel (virt_to_phys (base->lcla_pool.base), base->virtbase +D40_DREG_LCLA ); + ret =0 ; free_page_list:kfree (page_list);return ret;
Signature · 1 line
2.10.0
PATCH 5/24 ste_dma40: Improve a size determination in d40_of_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 08:28:05 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/dma/ste_dma40.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/dma/ste_dma40.c +1 -3
@@ -3487,9 +3487,7 @@ static int __init d40_of_probe(struct platform_device *pdev,int num_phy =0 , num_memcpy =0 , num_disabled =0 ;const __be32 *list; - pdata =devm_kzalloc (&pdev->dev, -sizeof (struct stedma40_platform_data ), -GFP_KERNEL ); + pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)return -ENOMEM ;
Signature · 1 line
2.10.0
PATCH 6/24 ste_dma40: Replace four kzalloc() calls by kcalloc() in d40_hw_detect_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 09:56:32 +0200
* The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer kcalloc over kzalloc with multiply
Thus fix the affected source code places.
* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/dma/ste_dma40.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/dma/ste_dma40.c +10 -7
@@ -3281,19 +3281,20 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) base->gen_dmac.init_reg_size =ARRAY_SIZE (dma_init_reg_v4a); } - base->phy_res =kzalloc (num_phy_chans *sizeof (struct d40_phy_res ), + base->phy_res =kcalloc (num_phy_chans, +sizeof (*base->phy_res),GFP_KERNEL );if (!base->phy_res) goto failure; - base->lookup_phy_chans =kzalloc (num_phy_chans * -sizeof (struct d40_chan *), + base->lookup_phy_chans =kcalloc (num_phy_chans, +sizeof (*base->lookup_phy_chans),GFP_KERNEL );if (!base->lookup_phy_chans) goto failure; - base->lookup_log_chans =kzalloc (num_log_chans * -sizeof (struct d40_chan *), + base->lookup_log_chans =kcalloc (num_log_chans, +sizeof (*base->lookup_log_chans),GFP_KERNEL );if (!base->lookup_log_chans) goto failure;
@@ -3304,9 +3305,10 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)if (!base->reg_val_backup_chan) goto failure; - base->lcla_pool.alloc_map -kzalloc (num_phy_chans *sizeof (struct d40_desc *) - *D40_LCLA_LINK_PER_EVENT_GRP ,GFP_KERNEL ); + base->lcla_pool.alloc_map =kcalloc (num_phy_chans + *D40_LCLA_LINK_PER_EVENT_GRP , +sizeof (*base->lcla_pool.alloc_map), +GFP_KERNEL );if (!base->lcla_pool.alloc_map) goto failure;
Signature · 1 line
2.10.0
PATCH 7/24 ste_dma40: Use kmalloc_array() in d40_hw_detect_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 11:44:55 +0200
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected also by using the Coccinelle software.
--- drivers/dma/ste_dma40.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +3 -3
@@ -3299,9 +3299,9 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)if (!base->lookup_log_chans) goto failure; - base->reg_val_backup_chan =kmalloc (base->num_phy_chans * -sizeof (d40_backup_regs_chan), -GFP_KERNEL ); + base->reg_val_backup_chan =kmalloc_array (base->num_phy_chans, +sizeof (d40_backup_regs_chan), +GFP_KERNEL );if (!base->reg_val_backup_chan) goto failure;
Signature · 1 line
2.10.0
PATCH 8/24 ste_dma40: Less checks in d40_hw_detect_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 14:10:47 +0200
Four checks could be repeated by the d40_hw_detect_init() function during error handling even if the passed variables contained a null pointer.
* Adjust jump targets according to the Linux coding style convention.
* Call the interface "iounmap" only once at the end.
* Delete the repeated checks which became unnecessary with this refactoring.
--- drivers/dma/ste_dma40.c | 67 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 34 deletions(-)
drivers/dma/ste_dma40.c +33 -34
@@ -3158,27 +3158,27 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) clk =clk_get (&pdev->dev,NULL );if (IS_ERR (clk)) {d40_err (&pdev->dev,"No matching clock found\n" ); - goto failure; + goto check_prepare_enabled; } clk_ret =clk_prepare_enable (clk);if (clk_ret) {d40_err (&pdev->dev,"Failed to prepare/enable clock\n" ); - goto failure; + goto disable_unprepare; }/* Get IO for DMAC base address */ res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"base" );if (!res) - goto failure; + goto disable_unprepare;if (request_mem_region (res->start,resource_size (res),D40_NAME " I/O base" ) =NULL ) - goto failure; + goto release_region; virtbase =ioremap (res->start,resource_size (res));if (!virtbase) - goto failure; + goto release_region;/* This is just a regular AMBA PrimeCell ID actually */ for (pid =0 , i =0 ; i <4 ; i++)
@@ -3190,13 +3190,13 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)if (cid !=AMBA_CID ) {d40_err (&pdev->dev,"Unknown hardware! No PrimeCell ID\n" ); - goto failure; + goto unmap_io; }if (AMBA_MANF_BITS (pid) !=AMBA_VENDOR_ST ) {d40_err (&pdev->dev,"Unknown designer! Got %x wanted %x\n" ,AMBA_MANF_BITS (pid),AMBA_VENDOR_ST ); - goto failure; + goto unmap_io; }/* * HW revision:
@@ -3210,7 +3210,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) rev =AMBA_REV_BITS (pid);if (rev <2 ) {d40_err (&pdev->dev,"hardware revision: %d is not supported" , rev); - goto failure; + goto unmap_io; }/* The number of physical channels on this HW */
@@ -3236,7 +3236,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) sizeof(struct d40_chan), GFP_KERNEL);if (base =NULL ) - goto failure; + goto unmap_io; base->rev = rev; base->clk = clk;
@@ -3285,63 +3285,62 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)sizeof (*base->phy_res), GFP_KERNEL);if (!base->phy_res) - goto failure; + goto free_base; base->lookup_phy_chans =kcalloc (num_phy_chans,sizeof (*base->lookup_phy_chans),GFP_KERNEL );if (!base->lookup_phy_chans) - goto failure; + goto free_phy_res; base->lookup_log_chans =kcalloc (num_log_chans,sizeof (*base->lookup_log_chans),GFP_KERNEL );if (!base->lookup_log_chans) - goto failure; + goto free_phy_chans; base->reg_val_backup_chan =kmalloc_array (base->num_phy_chans,sizeof (d40_backup_regs_chan),GFP_KERNEL );if (!base->reg_val_backup_chan) - goto failure; + goto free_log_chans; base->lcla_pool.alloc_map =kcalloc (num_phy_chans *D40_LCLA_LINK_PER_EVENT_GRP ,sizeof (*base->lcla_pool.alloc_map),GFP_KERNEL );if (!base->lcla_pool.alloc_map) - goto failure; + goto free_backup_chan; base->desc_slab =kmem_cache_create (D40_NAME ,sizeof (struct d40_desc ),0 ,SLAB_HWCACHE_ALIGN ,NULL );if (base->desc_slab =NULL ) - goto failure; + goto free_map;return base; - -failure: + free_map: +kfree (base->lcla_pool.alloc_map); + free_backup_chan: +kfree (base->reg_val_backup_chan); + free_log_chans: +kfree (base->lookup_log_chans); + free_phy_chans: +kfree (base->lookup_phy_chans); + free_phy_res: +kfree (base->phy_res); + free_base: +kfree (base); + unmap_io: +iounmap (virtbase); + release_region: +release_mem_region (res->start,resource_size (res)); + check_prepare_enabled:if (!clk_ret) + disable_unprepare:clk_disable_unprepare (clk);if (!IS_ERR (clk))clk_put (clk); -if (virtbase) -iounmap (virtbase); -if (res) -release_mem_region (res->start, -resource_size (res)); -if (virtbase) -iounmap (virtbase); - -if (base) { -kfree (base->lcla_pool.alloc_map); -kfree (base->reg_val_backup_chan); -kfree (base->lookup_log_chans); -kfree (base->lookup_phy_chans); -kfree (base->phy_res); -kfree (base); - } -return NULL ; }
Signature · 1 line
2.10.0
PATCH 9/24 ste_dma40: Delete unnecessary variable initialisations in d40_hw_detect_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 14:34:18 +0200
Five local variables will be set to an appropriate value a bit later. Thus omit the explicit initialisation which became unnecessary with a previous update step.
--- drivers/dma/ste_dma40.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/ste_dma40.c +5 -5
@@ -3142,11 +3142,11 @@ static int __init d40_phy_res_init(struct d40_base *base)static struct d40_base *__init d40_hw_detect_init (struct platform_device *pdev) {struct stedma40_platform_data *plat_data =dev_get_platdata (&pdev->dev); -struct clk *clk =NULL ; -void __iomem *virtbase =NULL ; -struct resource *res =NULL ; -struct d40_base *base =NULL ; -int num_log_chans =0 ; +struct clk *clk; +void __iomem *virtbase; +struct resource *res; +struct d40_base *base; +int num_log_chans;int num_phy_chans;int num_memcpy_chans;int clk_ret = -EINVAL ;
Signature · 1 line
2.10.0
PATCH 10/24 ste_dma40: Adjust the position of a jump label in d40_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 14:36:26 +0200
Add a space character before a single jump label in this function according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/ste_dma40.c +1 -1
@@ -3728,7 +3728,7 @@ failure:kfree (base->lookup_phy_chans);kfree (base->phy_res);kfree (base); -report_failure: + report_failure:d40_err (&pdev->dev,"probe failed\n" );return ret; }
Signature · 1 line
2.10.0
PATCH 11/24 ste_dma40: Rename a jump label in d40_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 14:50:53 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/dma/ste_dma40.c +12 -13
@@ -3570,7 +3570,7 @@ static int __init d40_probe(struct platform_device *pdev)if (!res) { ret = -ENOENT ;d40_err (&pdev->dev,"No \"lcpa\" memory resource\n" ); - goto failure; + goto destroy_cache; } base->lcpa_size =resource_size (res); base->phy_lcpa = res->start;
@@ -3579,7 +3579,7 @@ static int __init d40_probe(struct platform_device *pdev) D40_NAME " I/O lcpa") = NULL) { ret = -EBUSY ;d40_err (&pdev->dev,"Failed to request LCPA region %pR\n" , res); - goto failure; + goto destroy_cache; }/* We make use of ESRAM memory for this. */
@@ -3595,7 +3595,7 @@ static int __init d40_probe(struct platform_device *pdev)if (!base->lcpa_base) { ret = -ENOMEM ;d40_err (&pdev->dev,"Failed to ioremap LCPA region\n" ); - goto failure; + goto destroy_cache; }/* If lcla has to be located in ESRAM we don't need to allocate */ if (base->plat_data->use_esram_lcla) {
@@ -3605,14 +3605,14 @@ static int __init d40_probe(struct platform_device *pdev) ret = -ENOENT ;d40_err (&pdev->dev,"No \"lcla_esram\" memory resource\n" ); - goto failure; + goto destroy_cache; } base->lcla_pool.base =ioremap (res->start,resource_size (res));if (!base->lcla_pool.base) { ret = -ENOMEM ;d40_err (&pdev->dev,"Failed to ioremap LCLA region\n" ); - goto failure; + goto destroy_cache; }writel (res->start, base->virtbase +D40_DREG_LCLA );
@@ -3620,7 +3620,7 @@ static int __init d40_probe(struct platform_device *pdev) ret =d40_lcla_allocate (base);if (ret) {d40_err (&pdev->dev,"Failed to allocate LCLA area\n" ); - goto failure; + goto destroy_cache; } }
@@ -3631,7 +3631,7 @@ static int __init d40_probe(struct platform_device *pdev) ret =request_irq (base->irq, d40_handle_interrupt,0 ,D40_NAME , base);if (ret) {d40_err (&pdev->dev,"No IRQ defined\n" ); - goto failure; + goto destroy_cache; }if (base->plat_data->use_esram_lcla) {
@@ -3641,7 +3641,7 @@ static int __init d40_probe(struct platform_device *pdev)d40_err (&pdev->dev,"Failed to get lcpa_regulator\n" ); ret =PTR_ERR (base->lcpa_regulator); base->lcpa_regulator =NULL ; - goto failure; + goto destroy_cache; } ret =regulator_enable (base->lcpa_regulator);
@@ -3650,7 +3650,7 @@ static int __init d40_probe(struct platform_device *pdev) "Failed to enable lcpa_regulator\n");regulator_put (base->lcpa_regulator); base->lcpa_regulator =NULL ; - goto failure; + goto destroy_cache; } }
@@ -3665,13 +3665,13 @@ static int __init d40_probe(struct platform_device *pdev) ret =d40_dmaengine_init (base, num_reserved_chans);if (ret) - goto failure; + goto destroy_cache; base->dev->dma_parms = &base->dma_parms; ret =dma_set_max_seg_size (base->dev,STEDMA40_MAX_SEG_SIZE );if (ret) {d40_err (&pdev->dev,"Failed to set dma max seg size\n" ); - goto failure; + goto destroy_cache; }d40_hw_init (base);
@@ -3685,8 +3685,7 @@ static int __init d40_probe(struct platform_device *pdev)dev_info (base->dev,"initialized\n" );return 0 ; - -failure: + destroy_cache:kmem_cache_destroy (base->desc_slab);if (base->virtbase)iounmap (base->virtbase);
Signature · 1 line
2.10.0
PATCH 12/24 ste_dma40: Rename jump labels in d40_dmaengine_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:10:15 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dma/ste_dma40.c +6 -6
@@ -2889,7 +2889,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,if (err) {d40_err (base->dev,"Failed to register slave channels\n" ); - goto failure1; + goto exit; } d40_chan_init(base, &base->dma_memcpy, base->log_chans,
@@ -2906,7 +2906,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,if (err) {d40_err (base->dev,"Failed to register memcpy only channels\n" ); - goto failure2; + goto unregister_slave; } d40_chan_init(base, &base->dma_both, base->phy_chans,
@@ -2924,14 +2924,14 @@ static int __init d40_dmaengine_init(struct d40_base *base,if (err) {d40_err (base->dev,"Failed to register logical and physical capable channels\n" ); - goto failure3; + goto unregister_memcpy; }return 0 ; -failure3: + unregister_memcpy:dma_async_device_unregister (&base->dma_memcpy); -failure2: + unregister_slave:dma_async_device_unregister (&base->dma_slave); -failure1: + exit:return err; }
Signature · 1 line
2.10.0
PATCH 13/24 ste_dma40: Rename a jump label in d40_alloc_chan_resources()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:15:15 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +3 -3
@@ -2424,7 +2424,7 @@ static int d40_alloc_chan_resources(struct dma_chan *chan) err =d40_config_memcpy (d40c);if (err) {chan_err (d40c,"Failed to configure memcpy channel\n" ); - goto fail; + goto mark_last_busy; } }
@@ -2432,7 +2432,7 @@ static int d40_alloc_chan_resources(struct dma_chan *chan)if (err) {chan_err (d40c,"Failed to allocate channel\n" ); d40c->configured = false; - goto fail; + goto mark_last_busy; }pm_runtime_get_sync (d40c->base->dev);
@@ -2466,7 +2466,7 @@ static int d40_alloc_chan_resources(struct dma_chan *chan)*/ if (is_free_phy)d40_config_write (d40c); -fail: + mark_last_busy:pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);spin_unlock_irqrestore (&d40c->lock, flags);
Signature · 1 line
2.10.0
PATCH 14/24 ste_dma40: One check less in d40_prep_sg() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:34:07 +0200
* Adjust jump targets according to the Linux coding style convention.
* Delete a repeated check which became unnecessary with this refactoring.
--- drivers/dma/ste_dma40.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/dma/ste_dma40.c +5 -6
@@ -2251,7 +2251,7 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src, desc =d40_prep_desc (chan, sg_src, sg_len, dma_flags);if (desc =NULL ) - goto err; + goto unlock;if (sg_next (&sg_src[sg_len -1 ]) = sg_src) desc->cyclic = true;
@@ -2271,7 +2271,7 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,if (ret) {chan_err (chan,"Failed to prepare %s sg job: %d\n" ,chan_is_logical (chan) ?"log" :"phy" , ret); - goto err; + goto free_desc; }/*
@@ -2283,10 +2283,9 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,spin_unlock_irqrestore (&chan->lock, flags);return &desc->txd; - -err: -if (desc) -d40_desc_free (chan, desc); + free_desc: +d40_desc_free (chan, desc); + unlock:spin_unlock_irqrestore (&chan->lock, flags);return NULL ; }
Signature · 1 line
2.10.0
PATCH 15/24 ste_dma40: Move two assignments in d40_prep_sg()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:40:05 +0200
Move assignments for two local variables so that their setting will only be performed after corresponding data processing succeeded by this function.
--- drivers/dma/ste_dma40.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/dma/ste_dma40.c +4 -2
@@ -2236,8 +2236,8 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src, enum dma_transfer_direction direction, unsigned long dma_flags) { struct d40_chan *chan = container_of(dchan, struct d40_chan, chan); -dma_addr_t src_dev_addr =0 ; -dma_addr_t dst_dev_addr =0 ; +dma_addr_t src_dev_addr; +dma_addr_t dst_dev_addr;struct d40_desc *desc;unsigned long flags;int ret;
@@ -2256,6 +2256,8 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,if (sg_next (&sg_src[sg_len -1 ]) = sg_src) desc->cyclic = true; + src_dev_addr =0 ; + dst_dev_addr =0 ;if (direction =DMA_DEV_TO_MEM ) src_dev_addr = chan->runtime_addr;else if (direction =DMA_MEM_TO_DEV )
Signature · 1 line
2.10.0
PATCH 16/24 ste_dma40: Rename a jump label in d40_prep_desc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:51:37 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/dma/ste_dma40.c +3 -4
@@ -2208,13 +2208,13 @@ d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg, cfg->dst_info.data_width);if (desc->lli_len <0 ) {chan_err (chan,"Unaligned size\n" ); - goto err; + goto free_desc; } ret =d40_pool_lli_alloc (chan, desc, desc->lli_len);if (ret <0 ) {chan_err (chan,"Could not allocate lli\n" ); - goto err; + goto free_desc; } desc->lli_current =0 ;
@@ -2224,8 +2224,7 @@ d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg,dma_async_tx_descriptor_init (&desc->txd, &chan->chan);return desc; - -err: + free_desc:d40_desc_free (chan, desc);return NULL ; }
Signature · 1 line
2.10.0
PATCH 17/24 ste_dma40: Move an assignment in d40_prep_desc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 15:54:12 +0200
Move one assignment for the local variable "cfg" so that its setting will only be performed after a call of the function "d40_desc_get" succeeded by this function.
--- drivers/dma/ste_dma40.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/ste_dma40.c +2 -1
@@ -2196,7 +2196,7 @@ static struct d40_desc * d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg, unsigned int sg_len, unsigned long dma_flags) { - struct stedma40_chan_cfg *cfg = &chan->dma_cfg; + struct stedma40_chan_cfg *cfg;struct d40_desc *desc;int ret;
@@ -2204,6 +2204,7 @@ d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg,if (!desc)return NULL ; + cfg = &chan->dma_cfg; desc->lli_len =d40_sg_2_dmalen (sg, sg_len, cfg->src_info.data_width, cfg->dst_info.data_width);if (desc->lli_len <0 ) {
Signature · 1 line
2.10.0
PATCH 18/24 ste_dma40: Rename a jump label in d40_is_paused()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:00:05 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/dma/ste_dma40.c +3 -4
@@ -2092,8 +2092,7 @@ static bool d40_is_paused(struct d40_chan *d40c)D40_CHAN_POS (d40c->phy_chan->num);if (status =D40_DMA_SUSPENDED || status =D40_DMA_STOP ) is_paused = true; - - goto _exit; + goto unlock; } if (d40c->dma_cfg.dir = DMA_MEM_TO_DEV ||
@@ -2103,7 +2102,7 @@ static bool d40_is_paused(struct d40_chan *d40c) status =readl (chanbase +D40_CHAN_REG_SSLNK ); }else {chan_err (d40c,"Unknown direction\n" ); - goto _exit; + goto unlock; } status = (status & D40_EVENTLINE_MASK(event)) >>
@@ -2111,7 +2110,7 @@ static bool d40_is_paused(struct d40_chan *d40c)if (status !=D40_DMA_RUN ) is_paused = true; -_exit: + unlock:spin_unlock_irqrestore (&d40c->lock, flags);return is_paused;
Signature · 1 line
2.10.0
PATCH 19/24 ste_dma40: Rename a jump label in d40_free_dma()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:04:46 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +2 -3
@@ -2045,7 +2045,7 @@ static int d40_free_dma(struct d40_chan *d40c) res =d40_channel_execute_command (d40c,D40_DMA_STOP );if (res) {chan_err (d40c,"stop failed\n" ); - goto out; + goto mark_last_busy; }d40_alloc_mask_free (phy, is_src,chan_is_logical (d40c) ? event :0 );
@@ -2063,8 +2063,7 @@ static int d40_free_dma(struct d40_chan *d40c) d40c->busy = false; d40c->phy_chan =NULL ; d40c->configured = false; -out: - + mark_last_busy:pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);return res;
Signature · 1 line
2.10.0
PATCH 20/24 ste_dma40: Rename a jump label in d40_alloc_mask_free()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:10:41 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +2 -3
@@ -1829,7 +1829,7 @@ static bool d40_alloc_mask_free(struct d40_phy_res *phy, bool is_src, phy->allocated_dst =D40_ALLOC_FREE ; phy->allocated_src =D40_ALLOC_FREE ; is_free = true; - goto out; + goto unlock; }/* Logical channel */
@@ -1845,8 +1845,7 @@ static bool d40_alloc_mask_free(struct d40_phy_res *phy, bool is_src, is_free = ((phy->allocated_src | phy->allocated_dst) =D40_ALLOC_FREE ); - -out: + unlock:spin_unlock_irqrestore (&phy->lock, flags);return is_free;
Signature · 1 line
2.10.0
PATCH 21/24 ste_dma40: Rename jump labels in d40_alloc_mask_set()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:16:42 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/dma/ste_dma40.c +10 -12
@@ -1778,42 +1778,40 @@ static bool d40_alloc_mask_set(struct d40_phy_res *phy, phy->allocated_dst = D40_ALLOC_FREE) { phy->allocated_dst =D40_ALLOC_PHY ; phy->allocated_src =D40_ALLOC_PHY ; - goto found; + goto found_unlock; } else - goto not_found; + goto not_found_unlock; }/* Logical channel */ if (is_src) {if (phy->allocated_src =D40_ALLOC_PHY ) - goto not_found; + goto not_found_unlock;if (phy->allocated_src =D40_ALLOC_FREE ) phy->allocated_src =D40_ALLOC_LOG_FREE ;if (!(phy->allocated_src &BIT (log_event_line))) { phy->allocated_src |=BIT (log_event_line); - goto found; + goto found_unlock; }else - goto not_found; + goto not_found_unlock; }else {if (phy->allocated_dst =D40_ALLOC_PHY ) - goto not_found; + goto not_found_unlock;if (phy->allocated_dst =D40_ALLOC_FREE ) phy->allocated_dst =D40_ALLOC_LOG_FREE ;if (!(phy->allocated_dst &BIT (log_event_line))) { phy->allocated_dst |=BIT (log_event_line); - goto found; - }else - goto not_found; + goto found_unlock; + } } - -not_found: + not_found_unlock:spin_unlock_irqrestore (&phy->lock, flags);return false; -found: + found_unlock:spin_unlock_irqrestore (&phy->lock, flags);return true; }
Signature · 1 line
2.10.0
PATCH 22/24 ste_dma40: Rename a jump label in dma_tasklet()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:23:43 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +2 -3
@@ -1606,7 +1606,7 @@ static void dma_tasklet(unsigned long data)/* Check if we have reached here for cyclic job */ d40d =d40_first_active_get (d40c);if (d40d =NULL || !d40d->cyclic) - goto err; + goto check_pending_tx; }if (!d40d->cyclic)
@@ -1648,8 +1648,7 @@ static void dma_tasklet(unsigned long data)dmaengine_desc_callback_invoke (&cb,NULL );return ; - -err: + check_pending_tx:/* Rescue manouver if receiving double interrupts */ if (d40c->pending_tx >0 ) d40c->pending_tx--;
Signature · 1 line
2.10.0
PATCH 23/24 ste_dma40: Rename a jump label in __d40_execute_command_phy()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:28:54 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/ste_dma40.c +2 -2
@@ -1083,7 +1083,7 @@ static int __d40_execute_command_phy(struct d40_chan *d40c,D40_CHAN_POS (d40c->phy_chan->num);if (status =D40_DMA_SUSPENDED || status =D40_DMA_STOP ) - goto done; + goto unlock; } wmask =0xffffffff & ~(D40_CHAN_POS_MASK (d40c->phy_chan->num));
@@ -1119,7 +1119,7 @@ static int __d40_execute_command_phy(struct d40_chan *d40c, } } -done: + unlock:spin_unlock_irqrestore (&d40c->base->execmd_lock, flags);return ret; }
Signature · 1 line
2.10.0
PATCH 24/24 ste_dma40: Rename a jump label in d40_log_lli_to_lcxa()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:39:06 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/dma/ste_dma40.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +2 -3
@@ -874,7 +874,7 @@ static void d40_log_lli_to_lcxa(struct d40_chan *chan, struct d40_desc *desc) }if (curr_lcla <0 ) - goto out; + goto set_current;for (; lli_current < lli_len; lli_current++) { unsigned int lcla_offset = chan->phy_chan->num * 1024 +
@@ -925,8 +925,7 @@ static void d40_log_lli_to_lcxa(struct d40_chan *chan, struct d40_desc *desc)break ; } } - -out: + set_current: desc->lli_current = lli_current; }
Signature · 1 line
2.10.0
Re: [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:56:56 +0200Several update suggestions were taken into account from static source code analysis.
All look very nice!
Vinod, please apply them all!
Yours,
Linus Walleij
Vinod Koul
AppliedRe: [PATCH 00/24] ste_dma40: Fine-tuning for several function implementations
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 16:56:56 +0200Several update suggestions were taken into account from static source code analysis.
Applied all, thanks
Signature · 1 line
~Vinod
cover firewire-net: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 08:04:02 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (10):
Use kmalloc_array() in fwnet_broadcast_start() Rename a jump label in fwnet_broadcast_start() Rename jump labels in fwnet_init()
Rename jump labels in fwnet_probe()
Rename a jump label in fwnet_tx()
Rename a jump label in fwnet_send_packet() Rename a jump label in fwnet_incoming_packet() Rename a jump label in fwnet_finish_incoming_packet() Rename jump labels in fwnet_pd_new()
Adjust checks for null pointers in five functions
drivers/firewire/net.c | 94 +++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 50 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/1 firewire-net: Use kmalloc_array() in fwnet_broadcast_start()
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 21:55:42 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/firewire/net.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firewire/net.c +1 -2
@@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) max_receive =1U << (dev->card->max_receive +1 ); num_packets = (FWNET_ISO_PAGE_COUNT *PAGE_SIZE ) / max_receive; - - ptrptr =kmalloc (sizeof (void *) * num_packets,GFP_KERNEL ); + ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; goto failed;
Signature · 1 line
2.10.0
Re: [PATCH 01/] firewire-net: Use kmalloc_array() in fwnet_broadcast_start()
Quoted 23 lines · On Sep 18 SF Markus Elfring wrote:
From: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 21:55:42 +0200* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firewire/net.c +0
-0
drivers/firewire/net.c static int fwnet_broadcast_start(struct fwnet_device *dev) · line 1109
Quoted 9 lines
drivers/firewire/net.c +1
-2@@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) max_receive =1U << (dev->card->max_receive +1 ); num_packets = (FWNET_ISO_PAGE_COUNT *PAGE_SIZE ) / max_receive; - - ptrptr =kmalloc (sizeof (void *) * num_packets,GFP_KERNEL ); + ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; goto failed;
Coccinelle enabled you to determine that kmalloc_array /could/ be used here. But whether it /should/ be used here is another question, and it is not addressed in your changelog. (You state that there is an "issue" but do not explain.)
kmalloc_array is a kmalloc wrapper which adds an inline check for integer overflow. So, can sizeof(void *) * num_packets ever overflow size_t?
If yes,
do we want a runtime check here (which kmalloc_array provides), or do we want a compile-time check?
If no,
then the remaining benefit of the patch is that it is more obvious to the reader that dev->broadcast_rcv_buffer_ptrs is an array, but possibly at the cost of superfluous code. Is gcc's optimizer able to resolve kmalloc_array's check at compile time as always false, such that the superfluous code is eliminated as dead code?
I believe I know answers to this but prefer to hear what you as the patch author think about it.
Signature · 3 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/
Re: [PATCH 01/10] firewire-net: Use kmalloc_array() in fwnet_broadcast_start()
Quoted 12 lines
drivers/firewire/net.c static int fwnet_broadcast_start(struct fwnet_device *dev) · line 1109
Quoted 10 lines
drivers/firewire/net.c +1
-2@@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) max_receive =1U << (dev->card->max_receive +1 ); num_packets = (FWNET_ISO_PAGE_COUNT *PAGE_SIZE ) / max_receive; - - ptrptr =kmalloc (sizeof (void *) * num_packets,GFP_KERNEL ); + ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; goto failed;Coccinelle enabled you to determine that
kmalloc_array/could/ be used here.
A script for the semantic patch language pointed hundreds of source files out with such software update opportunities.
Quoted 2 lines
But whether it /should/ be used here is another question, and it is not addressed in your changelog.
I can expand the corresponding description when it will be desired.
Quoted 1 line
(You state that there is an "issue" but do not explain.)
Do you prefer an other wording for such an update candidate?
Quoted 4 lines
kmalloc_arrayis a kmalloc wrapper which adds an inline check for integer overflow. So, cansizeof(void *)*num_packetsever overflowsize_t?If yes,
Is there a probability that the calculated number of packets will become too big for the preferred system limits anyhow?
Quoted 1 line
do we want a runtime check here (which
kmalloc_arrayprovides),
Did you notice the information from the commit "mm: faster kmalloc_array(), kcalloc()" (from 2016-07-26) already?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id‘c6a05f72a996bee5133e76374ab3ad7d3b9b72
Quoted 1 line
or do we want a compile-time check?
I guess that some software developers and subsystem maintainers are looking for a bit more clarification around involved design dependencies.
Quoted 3 lines
If no,
then the remaining benefit of the patch is that it is more obvious to the reader that dev->broadcast_rcv_buffer_ptrs is an array,
How do you value such a kind of source code annotation?
Quoted 1 line
but possibly at the cost of superfluous code.
How do you think about to care for a bit more consistent use of Linux programming interfaces?
Quoted 2 lines
Is gcc's optimizer able to resolve kmalloc_array's check at compile time as always false, such that the superfluous code is eliminated as dead code?
Which versions of compiler implementations would you like to check further?
Quoted 2 lines
I believe I know answers to this but prefer to hear what you as the patch author think about it.
I presented another update suggestion also for this software module as a result from a general source code search pattern.
The corresponding change acceptance varies and is evolving as usual.
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/10 firewire-net: Rename a jump label in fwnet_broadcast_start()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:02:44 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/firewire/net.c +6 -7
@@ -1106,7 +1106,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) ptrptr =kmalloc_array (num_packets,sizeof (*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; - goto failed; + goto stop_broadcast; } dev->broadcast_rcv_buffer_ptrs = ptrptr;
@@ -1116,13 +1116,13 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) fwnet_receive_broadcast, dev);if (IS_ERR (context)) { retval =PTR_ERR (context); - goto failed; + goto stop_broadcast; } retval =fw_iso_buffer_init (&dev->broadcast_rcv_buffer, dev->card,FWNET_ISO_PAGE_COUNT ,DMA_FROM_DEVICE );if (retval <0 ) - goto failed; + goto stop_broadcast; dev->broadcast_state =FWNET_BROADCAST_STOPPED ;
@@ -1148,7 +1148,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) retval =fw_iso_context_queue (context, &packet, &dev->broadcast_rcv_buffer, offset);if (retval <0 ) - goto failed; + goto stop_broadcast; offset += max_receive; }
@@ -1158,7 +1158,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) retval =fw_iso_context_start (context,-1 ,0 ,FW_ISO_CONTEXT_MATCH_ALL_TAGS );/* ??? sync */ if (retval <0 ) - goto failed; + goto stop_broadcast;/* FIXME: adjust it according to the min. speed of all known peers? */ dev->broadcast_xmt_max_payload =IEEE1394_MAX_PAYLOAD_S100
@@ -1166,8 +1166,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) dev->broadcast_state =FWNET_BROADCAST_RUNNING ;return 0 ; - - failed: + stop_broadcast:__fwnet_broadcast_stop (dev);return retval; }
Signature · 1 line
2.10.0
Re: [PATCH 02/10] firewire-net: Rename a jump label in fwnet_broadcast_start()
Quoted 2 lines · On Sep 18 SF Markus Elfring wrote:
Adjust jump labels according to the current Linux coding style convention.
The current CodingStyle says: "Choose label names which say what the goto does or why the goto exists." Given the choice between /what/ and /why/, I for one lean towards /why/.
In this instance, the what and why is "clean up and exit after an error occurred". 'failed' looks to me to be a better shorthand of this than 'stop_broadcast'. The latter merely says /how/ the cleanup is done.
Quoted 25 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)drivers/firewire/net.c +2
-2@@ -1106,7 +1106,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) ptrptr = kmalloc_array(num_packets, sizeof(*ptrptr),GFP_KERNEL );if (!ptrptr) { retval = -ENOMEM ; - goto failed; + goto stop_broadcast; } dev->broadcast_rcv_buffer_ptrs = ptrptr;@@ -1116,13 +1116,13 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) fwnet_receive_broadcast, dev);if (IS_ERR (context)) { retval =PTR_ERR (context); - goto failed; + goto stop_broadcast; }
[...]
drivers/firewire/net.c static int fwnet_broadcast_start(struct · line 1172
Quoted 10 lines
drivers/firewire/net.c +1
-2@@ -1166,8 +1166,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) dev->broadcast_state = FWNET_BROADCAST_RUNNING;return 0 ; - - failed: + stop_broadcast:__fwnet_broadcast_stop (dev);return retval; }
I see no reason to remove the blank line between the return statement and the label.
Signature · 3 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/
PATCH 3/10 firewire-net: Rename jump labels in fwnet_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:11:25 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/firewire/net.c +4 -4
@@ -1662,14 +1662,14 @@ static int __init fwnet_init(void)#if IS_ENABLED (CONFIG_IPV6 ) err =fw_core_add_descriptor (&rfc3146_unit_directory);if (err) - goto out; + goto remove_descriptor_rfc2374;#endif fwnet_packet_task_cache =kmem_cache_create ("packet_task" ,sizeof (struct fwnet_packet_task ),0 ,0 ,NULL );if (!fwnet_packet_task_cache) { err = -ENOMEM ; - goto out2; + goto remove_descriptor_rfc3146; } err =driver_register (&fwnet_driver.driver);
@@ -1677,10 +1677,10 @@ static int __init fwnet_init(void)return 0 ;kmem_cache_destroy (fwnet_packet_task_cache); -out2: + remove_descriptor_rfc3146:#if IS_ENABLED (CONFIG_IPV6 )fw_core_remove_descriptor (&rfc3146_unit_directory); -out: + remove_descriptor_rfc2374:#endif fw_core_remove_descriptor (&rfc2374_unit_directory);
Signature · 1 line
2.10.0
PATCH 4/10 firewire-net: Rename jump labels in fwnet_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:17:12 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/firewire/net.c +5 -5
@@ -1442,7 +1442,7 @@ static int fwnet_probe(struct fw_unit *unit, dev =fwnet_dev_find (card);if (dev) { net = dev->netdev; - goto have_dev; + goto add_peer; } net = alloc_netdev(sizeof(*dev), "firewire%d", NET_NAME_UNKNOWN,
@@ -1469,7 +1469,7 @@ static int fwnet_probe(struct fw_unit *unit, ret =fwnet_fifo_start (dev);if (ret <0 ) - goto out; + goto stop_fifo; dev->local_fifo = dev->handler.offset;/*
@@ -1492,17 +1492,17 @@ static int fwnet_probe(struct fw_unit *unit, ret =register_netdev (net);if (ret) - goto out; + goto stop_fifo;list_add_tail (&dev->dev_link, &fwnet_device_list);dev_notice (&net->dev,"IP over IEEE 1394 on card %s\n" ,dev_name (card->device)); - have_dev: + add_peer: ret =fwnet_add_peer (dev, unit, device);if (ret && allocated_netdev) {unregister_netdev (net);list_del (&dev->dev_link); - out: + stop_fifo:fwnet_fifo_stop (dev);free_netdev (net); }
Signature · 1 line
2.10.0
PATCH 5/10 firewire-net: Rename a jump label in fwnet_tx()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:22:58 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/firewire/net.c +5 -6
@@ -1233,11 +1233,11 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net) ptask =kmem_cache_alloc (fwnet_packet_task_cache,GFP_ATOMIC );if (ptask =NULL ) - goto fail; + goto unlock; skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) - goto fail; + goto unlock;/* * Make a copy of the driver-specific header.
@@ -1254,7 +1254,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)#endif break ;default : - goto fail; + goto unlock; }skb_pull (skb,sizeof (hdr_buf));
@@ -1279,7 +1279,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net) peer =fwnet_peer_find_by_guid (dev,be64_to_cpu (guid));if (!peer) - goto fail; + goto unlock; generation = peer->generation; dest_node = peer->node_id;
@@ -1324,8 +1324,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)fwnet_send_packet (ptask);return NETDEV_TX_OK ; - - fail: + unlock:spin_unlock_irqrestore (&dev->lock, flags);if (ptask)
Signature · 1 line
2.10.0
PATCH 6/10 firewire-net: Rename a jump label in fwnet_send_packet()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:27:52 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/firewire/net.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/firewire/net.c +2 -3
@@ -1003,8 +1003,7 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)dec_queued_datagrams (dev);spin_unlock_irqrestore (&dev->lock, flags); - - goto out; + goto check_free; } fw_send_request(dev->card, &ptask->transaction,
@@ -1024,7 +1023,7 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)spin_unlock_irqrestore (&dev->lock, flags);netif_trans_update (dev->netdev); - out: + check_free:if (free)fwnet_free_ptask (ptask);
Signature · 1 line
2.10.0
PATCH 7/10 firewire-net: Rename a jump label in fwnet_incoming_packet()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:32:14 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/firewire/net.c +5 -5
@@ -621,7 +621,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, peer =fwnet_peer_find_by_node_id (dev, source_node_id, generation);if (!peer) { retval = -ENOENT ; - goto fail; + goto unlock; } pd =fwnet_pd_find (peer, datagram_label);
@@ -636,7 +636,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, dg_size, buf, fg_off, len);if (pd =NULL ) { retval = -ENOMEM ; - goto fail; + goto unlock; } peer->pdg_size++; }else {
@@ -652,7 +652,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,if (pd =NULL ) { peer->pdg_size--; retval = -ENOMEM ; - goto fail; + goto unlock; } }else {if (!fwnet_pd_update (peer, pd, buf, fg_off, len)) {
@@ -664,7 +664,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,fwnet_pd_delete (pd); peer->pdg_size--; retval = -ENOMEM ; - goto fail; + goto unlock; } } }/* new datagram or add to existing one */
@@ -688,7 +688,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,* moment. */ retval =0 ; - fail: + unlock:spin_unlock_irqrestore (&dev->lock, flags);return retval;
Signature · 1 line
2.10.0
PATCH 8/10 firewire-net: Rename a jump label in fwnet_finish_incoming_packet()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:40:05 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/firewire/net.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/firewire/net.c +2 -3
@@ -495,7 +495,7 @@ static int fwnet_finish_incoming_packet(struct net_device *net,#endif break ;default : - goto err; + goto increment_counter; } dev =netdev_priv (net);
@@ -551,8 +551,7 @@ static int fwnet_finish_incoming_packet(struct net_device *net, }return 0 ; - - err: + increment_counter: net->stats.rx_errors++; net->stats.rx_dropped++;
Signature · 1 line
2.10.0
PATCH 9/10 firewire-net: Rename jump labels in fwnet_pd_new()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 17 Sep 2016 22:48:46 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firewire/net.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/firewire/net.c +6 -7
@@ -362,18 +362,18 @@ static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net, new =kmalloc (sizeof (*new),GFP_ATOMIC );if (!new) - goto fail; + goto exit;INIT_LIST_HEAD (&new->fi_list); fi =fwnet_frag_new (new, frag_off, frag_len);if (fi =NULL ) - goto fail_w_new; + goto free_new; new->datagram_label = datagram_label; new->datagram_size = dg_size; new->skb =dev_alloc_skb (dg_size +LL_RESERVED_SPACE (net));if (new->skb =NULL ) - goto fail_w_fi; + goto free_fragment_info;skb_reserve (new->skb,LL_RESERVED_SPACE (net)); new->pbuf =skb_put (new->skb, dg_size);
@@ -381,12 +381,11 @@ static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net,list_add_tail (&new->pd_link, &peer->pd_list);return new; - -fail_w_fi: + free_fragment_info:kfree (fi); -fail_w_new: + free_new:kfree (new); -fail: + exit:return NULL ; }
Signature · 1 line
2.10.0
PATCH 10/10 firewire-net: Adjust checks for null pointers in five functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 07:48:56 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/firewire/net.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/firewire/net.c +8 -8
@@ -366,13 +366,13 @@ static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net,INIT_LIST_HEAD (&new->fi_list); fi =fwnet_frag_new (new, frag_off, frag_len); -if (fi =NULL ) +if (!fi) goto free_new; new->datagram_label = datagram_label; new->datagram_size = dg_size; new->skb =dev_alloc_skb (dg_size +LL_RESERVED_SPACE (net)); -if (new->skb =NULL ) +if (!new->skb) goto free_fragment_info;skb_reserve (new->skb,LL_RESERVED_SPACE (net));
@@ -418,7 +418,7 @@ static bool fwnet_pd_update(struct fwnet_peer *peer, struct fwnet_partial_datagram *pd, void *frag_buf, unsigned frag_off, unsigned frag_len) { - if (fwnet_frag_new(pd, frag_off, frag_len) = NULL) + if (!fwnet_frag_new(pd, frag_off, frag_len)) return false;memcpy (pd->pbuf + frag_off, frag_buf, frag_len);
@@ -623,7 +623,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, } pd =fwnet_pd_find (peer, datagram_label); -if (pd =NULL ) { +if (!pd) {while (peer->pdg_size >=FWNET_MAX_FRAGMENTS ) {/* remove the oldest */ fwnet_pd_delete(list_first_entry(&peer->pd_list,
@@ -632,7 +632,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, } pd =fwnet_pd_new (net, peer, datagram_label, dg_size, buf, fg_off, len); -if (pd =NULL ) { +if (!pd) { retval = -ENOMEM ; goto unlock; }
@@ -647,7 +647,7 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,fwnet_pd_delete (pd); pd =fwnet_pd_new (net, peer, datagram_label, dg_size, buf, fg_off, len); -if (pd =NULL ) { +if (!pd) { peer->pdg_size--; retval = -ENOMEM ; goto unlock;
@@ -1229,7 +1229,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net) } ptask =kmem_cache_alloc (fwnet_packet_task_cache,GFP_ATOMIC ); -if (ptask =NULL ) +if (!ptask) goto unlock; skb =skb_share_check (skb,GFP_ATOMIC );
@@ -1443,7 +1443,7 @@ static int fwnet_probe(struct fw_unit *unit, net =alloc_netdev (sizeof (*dev),"firewire%d" ,NET_NAME_UNKNOWN , fwnet_init_dev); -if (net =NULL ) { +if (!net) {mutex_unlock (&fwnet_device_mutex);return -ENOMEM ; }
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 10/10] firewire-net: Adjust checks for null pointers in five functions
Quoted 1 line · On Sep 18 SF Markus Elfring wrote:
The script "checkpatch.pl" can point information out like the following.
A side note: checkpatch.pl is for authors to help prepare their submissions of new code (or their refactoring of existing code if for some reason a refactoring is undertaken).
Quoted 1 line
Comparison to NULL could be written !…
Yes it could, or it could remain as is. Both styles are used in drivers/firewire/net.c, so it is indeed preferable to normalize it to one of them. I keep your patch for the next occasion when related work is being done on drivers/firewire/net.c or drivers/firewire.
Quoted 1 line
Thus fix the affected source code places.
It is not a "fix", it is a stylistic change.
Quoted 16 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/firewire/net.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/firewire/net.c +1
-1@@ -366,13 +366,13 @@ static struct fwnet_partial_datagram *fwnet_pd_new(struct net_device *net,INIT_LIST_HEAD (&new->fi_list); fi =fwnet_frag_new (new, frag_off, frag_len); -if (fi =NULL ) +if (!fi) goto free_new;
[...]
Signature · 7 lines
Stefan Richter -===----- =--= =--- http://arcgraph.de/sr/ -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
cover firmware-qemu_fw_cfg: Fine-tuning for four function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 14:43:21 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (6):
Use kmalloc_array() in fw_cfg_register_dir_entries() Improve a size determination in fw_cfg_register_file() Rename jump labels in fw_cfg_register_file() Improve a size determination in fw_cfg_build_symlink() Rename jump labels in fw_cfg_sysfs_probe() Move a variable assignment in fw_cfg_sysfs_probe()
drivers/firmware/qemu_fw_cfg.c | 53 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/6 firmware-qemu_fw_cfg: Use kmalloc_array() in fw_cfg_register_dir_entries()
From: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 09:39:31 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
* Delete the local variable "dir_size" which became unnecessary with this refactoring.
--- drivers/firmware/qemu_fw_cfg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/firmware/qemu_fw_cfg.c +5 -5
@@ -491,17 +491,17 @@ static int fw_cfg_register_dir_entries(void)int ret =0 ;u32 count, i;struct fw_cfg_file *dir; -size_t dir_size;fw_cfg_read_blob (FW_CFG_FILE_DIR , &count,0 ,sizeof (count)); count =be32_to_cpu (count); - dir_size = count *sizeof (struct fw_cfg_file ); - - dir =kmalloc (dir_size,GFP_KERNEL ); + dir =kmalloc_array (count,sizeof (*dir),GFP_KERNEL );if (!dir)return -ENOMEM ; -fw_cfg_read_blob (FW_CFG_FILE_DIR , dir,sizeof (count), dir_size); +fw_cfg_read_blob (FW_CFG_FILE_DIR , + dir, +sizeof (count), +sizeof (*dir) * count);for (i =0 ; i < count; i++) { dir[i].size =be32_to_cpu (dir[i].size);
Signature · 1 line
2.10.0
PATCH 2/6 firmware-qemu_fw_cfg: Improve a size determination in fw_cfg_register_file()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 10:43:27 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/firmware/qemu_fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/qemu_fw_cfg.c +1 -1
@@ -458,7 +458,7 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)return -ENOMEM ;/* set file entry information */ -memcpy (&entry->f, f,sizeof (struct fw_cfg_file )); +memcpy (&entry->f, f,sizeof (*f));/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */ err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
Signature · 1 line
2.10.0
PATCH 3/6 firmware-qemu_fw_cfg: Rename jump labels in fw_cfg_register_file()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 11:23:46 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firmware/qemu_fw_cfg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/firmware/qemu_fw_cfg.c +4 -5
@@ -464,12 +464,12 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f) err =kobject_init_and_add (&entry->kobj, &fw_cfg_sysfs_entry_ktype, fw_cfg_sel_ko,"%d" , entry->f.select);if (err) - goto err_register; + goto free_entry;/* add raw binary content access */ err =sysfs_create_bin_file (&entry->kobj, &fw_cfg_sysfs_attr_raw);if (err) - goto err_add_raw; + goto delete_object;/* try adding "/sys/firmware/qemu_fw_cfg/by_name/" symlink */ fw_cfg_build_symlink (fw_cfg_fname_kset, &entry->kobj, entry->f.name);
@@ -477,10 +477,9 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)/* success, add entry to global cache */ fw_cfg_sysfs_cache_enlist (entry);return 0 ; - -err_add_raw: + delete_object:kobject_del (&entry->kobj); -err_register: + free_entry:kfree (entry);return err; }
Signature · 1 line
2.10.0
PATCH 4/6 firmware-qemu_fw_cfg: Improve a size determination in fw_cfg_build_symlink()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 14:02:02 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/firmware/qemu_fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/qemu_fw_cfg.c +1 -1
@@ -399,7 +399,7 @@ static int fw_cfg_build_symlink(struct kset *dir, dir =to_kset (ko); }else {/* create new subdirectory kset */ - subdir =kzalloc (sizeof (struct kset ),GFP_KERNEL ); + subdir =kzalloc (sizeof (*subdir),GFP_KERNEL );if (!subdir) { ret = -ENOMEM ;break ;
Signature · 1 line
2.10.0
PATCH 5/6 firmware-qemu_fw_cfg: Rename jump labels in fw_cfg_sysfs_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 14:04:48 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/firmware/qemu_fw_cfg.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/firmware/qemu_fw_cfg.c +10 -11
@@ -538,42 +538,41 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev) err = -ENOMEM ; fw_cfg_sel_ko =kobject_create_and_add ("by_key" , fw_cfg_top_ko);if (!fw_cfg_sel_ko) - goto err_sel; + goto exit; fw_cfg_fname_kset =kset_create_and_add ("by_name" ,NULL , fw_cfg_top_ko);if (!fw_cfg_fname_kset) - goto err_name; + goto cleanup_object;/* initialize fw_cfg device i/o from platform data */ err =fw_cfg_do_platform_probe (pdev);if (err) - goto err_probe; + goto unregister;/* get revision number, add matching top-level attribute */ fw_cfg_read_blob (FW_CFG_ID , &fw_cfg_rev,0 ,sizeof (fw_cfg_rev)); fw_cfg_rev =le32_to_cpu (fw_cfg_rev); err =sysfs_create_file (fw_cfg_top_ko, &fw_cfg_rev_attr.attr);if (err) - goto err_rev; + goto cleanup_io;/* process fw_cfg file directory entry, registering each file */ err =fw_cfg_register_dir_entries ();if (err) - goto err_dir; + goto cleanup_cache;/* success */ pr_debug ("fw_cfg: loaded.\n" );return 0 ; - -err_dir: + cleanup_cache:fw_cfg_sysfs_cache_cleanup ();sysfs_remove_file (fw_cfg_top_ko, &fw_cfg_rev_attr.attr); -err_rev: + cleanup_io:fw_cfg_io_cleanup (); -err_probe: + unregister:fw_cfg_kset_unregister_recursive (fw_cfg_fname_kset); -err_name: + cleanup_object:fw_cfg_kobj_cleanup (fw_cfg_sel_ko); -err_sel: + exit:return err; }
Signature · 1 line
2.10.0
PATCH 6/6 firmware-qemu_fw_cfg: Move a variable assignment in fw_cfg_sysfs_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 14:25:55 +0200
One local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into two if branches to indicate a software failure there.
--- drivers/firmware/qemu_fw_cfg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/firmware/qemu_fw_cfg.c +6 -3
@@ -535,13 +535,16 @@ static int fw_cfg_sysfs_probe(struct platform_device *pdev)return -EBUSY ;/* create by_key and by_name subdirs of /sys/firmware/qemu_fw_cfg/ */ - err = -ENOMEM ; fw_cfg_sel_ko =kobject_create_and_add ("by_key" , fw_cfg_top_ko); -if (!fw_cfg_sel_ko) +if (!fw_cfg_sel_ko) { + err = -ENOMEM ; goto exit; + } fw_cfg_fname_kset =kset_create_and_add ("by_name" ,NULL , fw_cfg_top_ko); -if (!fw_cfg_fname_kset) +if (!fw_cfg_fname_kset) { + err = -ENOMEM ; goto cleanup_object; + }/* initialize fw_cfg device i/o from platform data */ err =fw_cfg_do_platform_probe (pdev);
Signature · 1 line
2.10.0
Re: [PATCH 0/6] firmware-qemu_fw_cfg: Fine-tuning for four function implementations
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 18 Sep 2016 14:43:21 +0200Some update suggestions were taken into account
from static source code analysis.
Quoted 7 lines
Markus Elfring (6):
Usekmalloc_array()infw_cfg_register_dir_entries()Improve a size determination infw_cfg_register_file()Rename jump labels infw_cfg_register_file()Improve a size determination infw_cfg_build_symlink()Rename jump labels infw_cfg_sysfs_probe()Move a variable assignment infw_cfg_sysfs_probe()
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c | 53 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-)Signature · 1 line
2.10.0