Source code review around jump label usage
Subsystems (101)
PATCH 14/15 md-cluster: Less function calls in lockres_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:01:05 +0200
The kfree() function was called in up to three cases
by the lockres_init() function during error handling even if the passed data structure member (or variable) contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/md-cluster.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/md/md-cluster.c +6 -4
@@ -201,12 +201,12 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, namelen =strlen (name); res->name =kzalloc (namelen +1 ,GFP_KERNEL );if (!res->name) - goto out_err; + goto free_resource;strlcpy (res->name, name, namelen +1 );if (with_lvb) { res->lksb.sb_lvbptr =kzalloc (LVB_SIZE ,GFP_KERNEL );if (!res->lksb.sb_lvbptr) - goto out_err; + goto free_name; res->flags =DLM_LKF_VALBLK ; }
@@ -218,15 +218,17 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, ret =dlm_lock_sync (res,DLM_LOCK_NL );if (ret) {pr_err ("md-cluster: Unable to lock NL on new lock resource %s\n" , name); - goto out_err; + goto free_lvb; } res->flags &= ~DLM_LKF_EXPEDITE ; res->flags |=DLM_LKF_CONVERT ;return res; -out_err: +free_lvb:kfree (res->lksb.sb_lvbptr); +free_name:kfree (res->name); +free_resource:kfree (res);return NULL ; }
Signature · 1 line
2.10.0
PATCH 15/15 md-cluster: Delete unnecessary braces in unlock_all_bitmaps()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:15:55 +0200
Do not use curly brackets at one source code place where a single statement should be sufficient.
--- drivers/md/md-cluster.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/md/md-cluster.c +3 -4
@@ -1223,11 +1223,10 @@ static void unlock_all_bitmaps(struct mddev *mddev)/* release other node's bitmap lock if they are existed */ if (cinfo->other_bitmap_lockres) { -for (i =0 ; i < mddev->bitmap_info.nodes -1 ; i++) { -if (cinfo->other_bitmap_lockres[i]) { +for (i =0 ; i < mddev->bitmap_info.nodes -1 ; i++) +if (cinfo->other_bitmap_lockres[i])lockres_free (cinfo->other_bitmap_lockres[i]); - } - } +kfree (cinfo->other_bitmap_lockres); } }
Signature · 1 line
2.10.0
Re: [PATCH 15/15] md-cluster: Delete unnecessary braces in unlock_all_bitmaps()
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:15:55 +0200Do not use curly brackets at one source code place where a single statement should be sufficient.
The original style was correct and this is wrong. I have explained this before.
regards,
dan carpenter
Re: md-cluster: Delete unnecessary braces in unlock_all_bitmaps()
Quoted 4 lines
Quoted 2 lines
Do not use curly brackets at one source code place where a single statement should be sufficient.
The original style was correct and this is wrong. I have explained this before.
Did I change a bit too much in the proposed step according to the following update suggestion?
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout d6385db94196b253ae5eb3678fa95cdf1f839fcc && scripts/checkpatch.pl --types BRACES -f drivers/md/md-cluster.c …
WARNING: braces {} are not necessary for single statement blocks
#1228: FILE: drivers/md/md-cluster.c:1228:
+ if (cinfo->other_bitmap_lockres[i]) {
+ lockres_free(cinfo->other_bitmap_lockres[i]);
+ }
…
How do you think about to adjust this source code place a bit?
Regards,
Markus
Re: md-cluster: Delete unnecessary braces in unlock_all_bitmaps()
Am 07.10.2016 10:37, schrieb SF Markus Elfring:
Quoted 18 lines
Quoted 4 lines
Quoted 2 lines
Do not use curly brackets at one source code place where a single statement should be sufficient.
The original style was correct and this is wrong. I have explained this before.
Did I change a bit too much in the proposed step according to the following update suggestion?
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout
d6385db94196b253ae5eb3678fa95cdf1f839fcc&&scripts/checkpatch.pl--types BRACES -fdrivers/md/md-cluster.c…
WARNING: braces {} are not necessary for single statement blocks
#1228: FILE:drivers/md/md-cluster.c:1228:(quoted diff) +3
-0+ if (cinfo->other_bitmap_lockres[i]) { + lockres_free(cinfo->other_bitmap_lockres[i]); + }
Quoted 2 lines
How do you think about to adjust this source code place a bit?
perhaps we can agree to delete the if() block ?
static void lockres_free(struct dlm_lock_resource *res)
{
int ret;
if (!res)
return;....
@marcus: is can not send mail to you sf.net adresse because sf.net
mark my domain als spam (note: nobody else does)
re,
wh
cover md/multipath: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 13:45:35 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (13):
Use kcalloc() in multipath_run()
Improve another size determination in multipath_run() Delete four error messages for a failed memory allocation Reduce indentation for four lines in multipath_run() Less function calls in multipath_run() after error detection Delete 13 unwanted spaces behind function names
Delete two unwanted spaces behind asterisks
Replace a seq_printf() call by seq_puts() in multipath_status() Adjust two function calls together with a variable assignment Add some spaces for better code readability
Move a brace for a designated initialiser
Delete an unnecessary return statement in multipath_make_request() Replace printk() calls by the usage of higher level interfaces
drivers/md/multipath.c | 192 +++++++++++++++++++++++-------------------------- 1 file changed, 88 insertions(+), 104 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/13 md/multipath: Use kcalloc() in multipath_run()
From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:40:42 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/multipath.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/multipath.c +2 -1
@@ -408,7 +408,8 @@ static int multipath_run (struct mddev *mddev) goto out; } - conf->multipaths =kzalloc (sizeof (struct multipath_info )*mddev->raid_disks, + conf->multipaths =kcalloc (mddev->raid_disks, +sizeof (*conf->multipaths),GFP_KERNEL );if (!conf->multipaths) { printk(KERN_ERR
Signature · 1 line
2.10.0
PATCH 2/13 md/multipath: Improve another size determination in multipath_run()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:52:57 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/multipath.c +1 -1
@@ -399,7 +399,7 @@ static int multipath_run (struct mddev *mddev)* should be freed in multipath_free()] */ - conf =kzalloc (sizeof (struct mpconf ),GFP_KERNEL ); + conf =kzalloc (sizeof (*conf),GFP_KERNEL ); mddev->private = conf;if (!conf) { printk(KERN_ERR
Signature · 1 line
2.10.0
PATCH 3/13 md/multipath: Delete four error messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:15:45 +0200
Omit extra messages for a memory allocation failure in this function.
--- drivers/md/multipath.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/md/multipath.c +4 -19
@@ -401,22 +401,14 @@ static int multipath_run (struct mddev *mddev) conf =kzalloc (sizeof (*conf),GFP_KERNEL ); mddev->private = conf; -if (!conf) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf) goto out; - } conf->multipaths =kcalloc (mddev->raid_disks,sizeof (*conf->multipaths),GFP_KERNEL ); -if (!conf->multipaths) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf->multipaths) goto out_free_conf; - } working_disks =0 ;rdev_for_each (rdev, mddev) {
@@ -448,21 +440,14 @@ static int multipath_run (struct mddev *mddev) conf->pool =mempool_create_kmalloc_pool (NR_RESERVED_BUFS ,sizeof (struct multipath_bh )); -if (conf->pool =NULL ) { -printk (KERN_ERR -"multipath: couldn't allocate memory for %s\n" , -mdname (mddev)); +if (!conf->pool) goto out_free_conf; - } { mddev->thread =md_register_thread (multipathd, mddev,"multipath" ); -if (!mddev->thread) { -printk (KERN_ERR "multipath: couldn't allocate thread" -" for %s\n" ,mdname (mddev)); +if (!mddev->thread) goto out_free_conf; - } } printk(KERN_INFO
Signature · 1 line
2.10.0
PATCH 4/13 md/multipath: Reduce indentation for four lines in multipath_run()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:26:00 +0200
* Delete a pair of extra curly brackets.
* Reduce indentation one level for a few lines in this function.
--- drivers/md/multipath.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/md/multipath.c +3 -6
@@ -443,12 +443,9 @@ static int multipath_run (struct mddev *mddev)if (!conf->pool) goto out_free_conf; - { - mddev->thread =md_register_thread (multipathd, mddev, -"multipath" ); -if (!mddev->thread) - goto out_free_conf; - } + mddev->thread =md_register_thread (multipathd, mddev,"multipath" ); +if (!mddev->thread) + goto out_free_conf; printk(KERN_INFO "multipath: array %s active with %d out of %d IO paths\n",
Signature · 1 line
2.10.0
PATCH 5/13 md/multipath: Less function calls in multipath_run() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:48:59 +0200
The functions "kfree" and "mempool_destroy" were called in a few cases by the function "multipath_run" during error handling even if the passed data structure member contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/multipath.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/md/multipath.c +8 -7
@@ -408,7 +408,7 @@ static int multipath_run (struct mddev *mddev)sizeof (*conf->multipaths), GFP_KERNEL);if (!conf->multipaths) - goto out_free_conf; + goto free_conf; working_disks =0 ;rdev_for_each (rdev, mddev) {
@@ -434,18 +434,18 @@ static int multipath_run (struct mddev *mddev)if (!working_disks) {printk (KERN_ERR "multipath: no operational IO paths for %s\n" ,mdname (mddev)); - goto out_free_conf; + goto free_multipaths; } mddev->degraded = conf->raid_disks - working_disks; conf->pool =mempool_create_kmalloc_pool (NR_RESERVED_BUFS ,sizeof (struct multipath_bh ));if (!conf->pool) - goto out_free_conf; + goto free_multipaths; mddev->thread =md_register_thread (multipathd, mddev,"multipath" );if (!mddev->thread) - goto out_free_conf; + goto destroy_pool; printk(KERN_INFO "multipath: array %s active with %d out of %d IO paths\n",
@@ -457,13 +457,14 @@ static int multipath_run (struct mddev *mddev)md_set_array_sectors (mddev,multipath_size (mddev,0 ,0 ));if (md_integrity_register (mddev)) - goto out_free_conf; + goto destroy_pool;return 0 ; - -out_free_conf: +destroy_pool:mempool_destroy (conf->pool); +free_multipaths:kfree (conf->multipaths); +free_conf:kfree (conf); mddev->private =NULL ; out:
Signature · 1 line
2.10.0
PATCH 6/13 md/multipath: Delete 13 unwanted spaces behind function names
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 08:14:48 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: space prohibited between function name and open parenthesis '('
Thus fix the affected source code places.
--- drivers/md/multipath.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/md/multipath.c +16 -14
@@ -31,7 +31,7 @@#define NR_RESERVED_BUFS 32 -static int multipath_map (struct mpconf *conf) +static int multipath_map (struct mpconf *conf) {int i, disks = conf->raid_disks;
@@ -56,7 +56,7 @@ static int multipath_map (struct mpconf *conf)return (-1 ); } -static void multipath_reschedule_retry (struct multipath_bh *mp_bh) +static void multipath_reschedule_retry (struct multipath_bh *mp_bh) {unsigned long flags;struct mddev *mddev = mp_bh->mddev;
@@ -73,7 +73,7 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh)* operation and are ready to return a success/failure code to the buffer * cache layer. */ -static void multipath_end_bh_io (struct multipath_bh *mp_bh,int err) +static void multipath_end_bh_io (struct multipath_bh *mp_bh,int err) {struct bio *bio = mp_bh->master_bio;struct mpconf *conf = mp_bh->mddev->private;
@@ -96,7 +96,7 @@ static void multipath_end_request(struct bio *bio)* oops, IO error: */ char b[BDEVNAME_SIZE ]; -md_error (mp_bh->mddev, rdev); +md_error (mp_bh->mddev, rdev);printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" ,bdevname (rdev->bdev,b), (unsigned long long )bio->bi_iter.bi_sector);
@@ -147,12 +147,14 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)struct mpconf *conf = mddev->private;int i; -seq_printf (seq," [%d/%d] [" , conf->raid_disks, - conf->raid_disks - mddev->degraded); +seq_printf (seq," [%d/%d] [" , conf->raid_disks, + conf->raid_disks - mddev->degraded);rcu_read_lock ();for (i =0 ; i < conf->raid_disks; i++) {struct md_rdev *rdev =rcu_dereference (conf->multipaths[i].rdev); -seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); +seq_printf (seq, +"%s" , + rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock ();seq_printf (seq,"]" );
@@ -183,7 +185,7 @@ static int multipath_congested(struct mddev *mddev, int bits)/* * Careful, this can execute in IRQ contexts as well! */ -static void multipath_error (struct mddev *mddev,struct md_rdev *rdev) +static void multipath_error (struct mddev *mddev,struct md_rdev *rdev) {struct mpconf *conf = mddev->private;char b[BDEVNAME_SIZE ];
@@ -218,7 +220,7 @@ static void multipath_error (struct mddev *mddev, struct md_rdev *rdev) conf->raid_disks - mddev->degraded); } -static void print_multipath_conf (struct mpconf *conf) +static void print_multipath_conf (struct mpconf *conf) {int i;struct multipath_info *tmp;
@@ -377,7 +379,7 @@ static sector_t multipath_size(struct mddev *mddev, sector_t sectors, int raid_dreturn mddev->dev_sectors; } -static int multipath_run (struct mddev *mddev) +static int multipath_run (struct mddev *mddev) {struct mpconf *conf;int disk_idx;
@@ -496,14 +498,14 @@ static struct md_personality multipath_personality .congested = multipath_congested, }; -static int __init multipath_init (void ) +static int __init multipath_init (void ) { -return register_md_personality (&multipath_personality); +return register_md_personality (&multipath_personality); } -static void __exit multipath_exit (void) +static void __exit multipath_exit(void) { -unregister_md_personality (&multipath_personality); +unregister_md_personality (&multipath_personality); }module_init (multipath_init);
Signature · 1 line
2.10.0
PATCH 7/13 md/multipath: Delete two unwanted spaces behind asterisks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 09:39:39 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: "foo * bar" should be "foo *bar"
--- drivers/md/multipath.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/multipath.c +2 -2
@@ -106,10 +106,10 @@ static void multipath_end_request(struct bio *bio)rdev_dec_pending (rdev, conf->mddev); } -static void multipath_make_request (struct mddev *mddev,struct bio * bio) +static void multipath_make_request (struct mddev *mddev,struct bio *bio) {struct mpconf *conf = mddev->private; -struct multipath_bh * mp_bh; +struct multipath_bh *mp_bh;struct multipath_info *multipath;if (unlikely (bio->bi_opf &REQ_PREFLUSH )) {
Signature · 1 line
2.10.0
PATCH 8/13 md/multipath: Replace a seq_printf() call by seq_puts() in multipath_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:00:15 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Prefer seq_puts to seq_printf
--- drivers/md/multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/multipath.c +1 -1
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" ); }static int multipath_congested (struct mddev *mddev,int bits)
Signature · 1 line
2.10.0
PATCH v2 1/1 md-multipath: Use seq_putc() in multipath_status()
From: Markus Elfring <[email protected]>
Date: Sat, 13 Jan 2018 09:49:03 +0100
A single character (closing square bracket) should be put into a sequence. Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- drivers/md/md-multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-multipath.c +1 -1
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static int multipath_congested (struct mddev *mddev,int bits)
Signature · 1 line
2.15.1
Shaohua Li
AppliedRe: [PATCH v2] md-multipath: Use seq_putc() in multipath_status()
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 13 Jan 2018 09:49:03 +0100A single character (closing square bracket) should be put into a sequence. Thus use the corresponding function "
seq_putc".This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
applied, thanks
Quoted 20 lines
--- drivers/md/md-multipath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/md-multipath.c +1
-1@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static int multipath_congested (struct mddev *mddev,int bits)Signature · 1 line
2.15.1
PATCH 9/13 md/multipath: Adjust two function calls together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:05:43 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
--- drivers/md/multipath.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/md/multipath.c +6 -3
@@ -258,8 +258,9 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)print_multipath_conf (conf); -for (path = first; path <= last; path++) -if ((p=conf->multipaths+path)->rdev =NULL ) { +for (path = first; path <= last; path++) { + p = conf->multipaths + path; +if (!p->rdev) { q = rdev->bdev->bd_disk->queue;disk_stack_limits (mddev->gendisk, rdev->bdev, rdev->data_offset <<9 );
@@ -276,6 +277,7 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev) err =0 ;break ; } + }print_multipath_conf (conf);
@@ -347,7 +349,8 @@ static void multipathd(struct md_thread *thread) bio = &mp_bh->bio; bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector; -if ((mp_bh->path =multipath_map (conf))<0 ) { + mp_bh->path =multipath_map (conf); +if (mp_bh->path <0 ) { printk(KERN_ALERT "multipath: %s: unrecoverable IO read" " error for block %llu\n", bdevname(bio->bi_bdev,b),
Signature · 1 line
2.10.0
PATCH 10/13 md/multipath: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:20:52 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/multipath.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/md/multipath.c +5 -5
@@ -98,7 +98,7 @@ static void multipath_end_request(struct bio *bio)char b[BDEVNAME_SIZE ];md_error (mp_bh->mddev, rdev);printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" , -bdevname (rdev->bdev,b), +bdevname (rdev->bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_reschedule_retry (mp_bh); }else
@@ -238,8 +238,8 @@ static void print_multipath_conf(struct mpconf *conf) tmp = conf->multipaths + i;if (tmp->rdev)printk (" disk%d, o:%d, dev:%s\n" , - i,!test_bit (Faulty, &tmp->rdev->flags), -bdevname (tmp->rdev->bdev,b)); + i, !test_bit (Faulty, &tmp->rdev->flags), +bdevname (tmp->rdev->bdev, b)); } }
@@ -353,13 +353,13 @@ static void multipathd(struct md_thread *thread)if (mp_bh->path <0 ) {printk (KERN_ALERT "multipath: %s: unrecoverable IO read" " error for block %llu\n" , -bdevname (bio->bi_bdev,b), +bdevname (bio->bi_bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_end_bh_io (mp_bh, -EIO ); }else {printk (KERN_ERR "multipath: %s: redirecting sector %llu" " to another IO path\n" , -bdevname (bio->bi_bdev,b), +bdevname (bio->bi_bdev, b), (unsigned long long )bio->bi_iter.bi_sector); *bio = *(mp_bh->master_bio); bio->bi_iter.bi_sector +@@ -487,18 +487,18 @@ static void multipath_free(struct mddev *mddev, void *priv)
static struct md_personality multipath_personality {
- .name = "multipath",
- .level = LEVEL_MULTIPATH,
- .owner = THIS_MODULE,
- .make_request = multipath_make_request,
- .run = multipath_run,
- .free = multipath_free,
- .status = multipath_status,
- .error_handler = multipath_error,
- .hot_add_disk = multipath_add_disk,
- .hot_remove_disk= multipath_remove_disk,
- .size = multipath_size,
- .congested = multipath_congested,
+ .name = "multipath", + .level = LEVEL_MULTIPATH, + .owner = THIS_MODULE, + .make_request = multipath_make_request, + .run = multipath_run, + .free = multipath_free, + .status = multipath_status, + .error_handler = multipath_error, + .hot_add_disk = multipath_add_disk,
+ .hot_remove_disk = multipath_remove_disk,
+ .size = multipath_size,
+ .congested = multipath_congested,
};
static int __init multipath_init(void)
Signature · 1 line
2.10.0
PATCH 11/13 md/multipath: Move a brace for a designated initialiser
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:43:28 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/multipath.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/multipath.c +1 -1
@@ -485,8 +485,7 @@ static void multipath_free(struct mddev *mddev, void *priv)kfree (conf); } -static struct md_personality multipath_personality -{ +static struct md_personality multipath_personality = { .name ="multipath" , .level =LEVEL_MULTIPATH , .owner =THIS_MODULE ,
Signature · 1 line
2.10.0
PATCH 12/13 md/multipath: Delete an unnecessary return statement in multipath_make_request()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:55:06 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: void function return statements are not generally useful
Thus remove such a statement here.
--- drivers/md/multipath.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/multipath.c +0 -1
@@ -139,7 +139,6 @@ static void multipath_make_request(struct mddev *mddev, struct bio *bio) mp_bh->bio.bi_end_io = multipath_end_request; mp_bh->bio.bi_private = mp_bh;generic_make_request (&mp_bh->bio); -return ; }static void multipath_status (struct seq_file *seq,struct mddev *mddev)
Signature · 1 line
2.10.0
PATCH 13/13 md/multipath: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 12:42:46 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
--- drivers/md/multipath.c | 69 ++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 36 deletions(-)
drivers/md/multipath.c +33 -36
@@ -19,6 +19,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/blkdev.h> #include <linux/module.h> #include <linux/raid/md_u.h>
@@ -51,8 +53,7 @@ static int multipath_map(struct mpconf *conf) } }rcu_read_unlock (); - -printk (KERN_ERR "multipath_map(): no more operational IO paths?\n" ); +pr_err ("map: no more operational IO paths?\n" );return (-1 ); }
@@ -97,7 +98,8 @@ static void multipath_end_request(struct bio *bio)*/ char b[BDEVNAME_SIZE ];md_error (mp_bh->mddev, rdev); -printk (KERN_ERR "multipath: %s: rescheduling sector %llu\n" , + +pr_err ("%s: rescheduling sector %llu\n" ,bdevname (rdev->bdev, b), (unsigned long long )bio->bi_iter.bi_sector);multipath_reschedule_retry (mp_bh);
@@ -195,8 +197,7 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev)* first check if this is a queued request for a device * which has just failed. */ -printk (KERN_ALERT -"multipath: only one IO path left and IO error.\n" ); +pr_alert ("only one IO path left and IO error.\n" );/* leave it active... it's all we have */ return ; }
@@ -211,12 +212,10 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev) }set_bit (Faulty, &rdev->flags);set_bit (MD_CHANGE_DEVS , &mddev->flags); -printk (KERN_ALERT "multipath: IO failure on %s," -" disabling IO path.\n" -"multipath: Operation continuing" -" on %d IO paths.\n" , -bdevname (rdev->bdev, b), - conf->raid_disks - mddev->degraded); +pr_alert ("IO failure on %s, disabling IO path.\n" +MY_LOG_PREFIX "Operation continuing on %d IO paths.\n" , +bdevname (rdev->bdev, b), + conf->raid_disks - mddev->degraded); }static void print_multipath_conf (struct mpconf *conf)
@@ -224,21 +223,22 @@ static void print_multipath_conf(struct mpconf *conf)int i;struct multipath_info *tmp; -printk ("MULTIPATH conf printout:\n" ); +pr_info ("conf printout:\n" );if (!conf) { -printk ("(conf=NULL)\n" ); +pr_info ("(conf=NULL)\n" );return ; } -printk (" --- wd:%d rd:%d\n" , conf->raid_disks - conf->mddev->degraded, - conf->raid_disks); +pr_info ("--- wd:%d rd:%d\n" , + conf->raid_disks - conf->mddev->degraded, + conf->raid_disks);for (i =0 ; i < conf->raid_disks; i++) {char b[BDEVNAME_SIZE ]; tmp = conf->multipaths + i;if (tmp->rdev) -printk (" disk%d, o:%d, dev:%s\n" , - i, !test_bit (Faulty, &tmp->rdev->flags), -bdevname (tmp->rdev->bdev, b)); +pr_info ("disk%d, o:%d, dev:%s\n" , + i, !test_bit (Faulty, &tmp->rdev->flags), +bdevname (tmp->rdev->bdev, b)); } }
@@ -295,8 +295,8 @@ static int multipath_remove_disk(struct mddev *mddev, struct md_rdev *rdev)if (rdev = p->rdev) {if (test_bit (In_sync, &rdev->flags) ||atomic_read (&rdev->nr_pending)) { -printk (KERN_ERR "hot-remove-disk, slot %d is identified" -" but is still operational!\n" , number); +pr_err ("hot-remove-disk, slot %d is identified but is still operational!\n" , + number); err = -EBUSY ; goto abort; }
@@ -350,16 +350,14 @@ static void multipathd(struct md_thread *thread) mp_bh->path =multipath_map (conf);if (mp_bh->path <0 ) { -printk (KERN_ALERT "multipath: %s: unrecoverable IO read" -" error for block %llu\n" , -bdevname (bio->bi_bdev, b), - (unsigned long long )bio->bi_iter.bi_sector); +pr_alert ("%s: unrecoverable IO read error for block %llu\n" , +bdevname (bio->bi_bdev, b), + (unsigned long long )bio->bi_iter.bi_sector);multipath_end_bh_io (mp_bh, -EIO ); }else { -printk (KERN_ERR "multipath: %s: redirecting sector %llu" -" to another IO path\n" , -bdevname (bio->bi_bdev, b), - (unsigned long long )bio->bi_iter.bi_sector); +pr_err ("%s: redirecting sector %llu to another IO path\n" , +bdevname (bio->bi_bdev, b), + (unsigned long long )bio->bi_iter.bi_sector); *bio = *(mp_bh->master_bio); bio->bi_iter.bi_sector + conf->multipaths[mp_bh->path].rdev->data_offset;
@@ -393,8 +391,8 @@ static int multipath_run(struct mddev *mddev)return -EINVAL ;if (mddev->level !=LEVEL_MULTIPATH ) { -printk ("multipath: %s: raid level not set to multipath IO (%d)\n" , -mdname (mddev), mddev->level); +pr_notice ("%s: raid level not set to multipath IO (%d)\n" , +mdname (mddev), mddev->level); goto out; }/*
@@ -436,8 +434,7 @@ static int multipath_run(struct mddev *mddev)INIT_LIST_HEAD (&conf->retry_list);if (!working_disks) { -printk (KERN_ERR "multipath: no operational IO paths for %s\n" , -mdname (mddev)); +pr_err ("no operational IO paths for %s\n" ,mdname (mddev)); goto free_multipaths; } mddev->degraded = conf->raid_disks - working_disks;
@@ -451,10 +448,10 @@ static int multipath_run(struct mddev *mddev)if (!mddev->thread) goto destroy_pool; -printk (KERN_INFO -"multipath: array %s active with %d out of %d IO paths\n" , -mdname (mddev), conf->raid_disks - mddev->degraded, - mddev->raid_disks); +pr_info ("array %s active with %d out of %d IO paths\n" , +mdname (mddev), + conf->raid_disks - mddev->degraded, + mddev->raid_disks);/* * Ok, everything is just fine now */
Signature · 1 line
2.10.0
MD-RAID: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 6 Oct 2016 10:10:01 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (54):
raid0: Use kcalloc() in create_strip_zones()
raid0: Less function calls in create_strip_zones() after error detection
raid0: Move a variable assignment in create_strip_zones()
raid0: Replace printk() calls by the usage of higher level interfaces
raid0: Move another variable assignment in create_strip_zones()
raid0: Delete four unwanted spaces behind function names
raid0: Move two misplaced braces
raid0: Delete an unnecessary return statement in raid0_status()
raid0: Add some spaces for better code readability
raid1: Use kcalloc() in alloc_behind_pages()
raid1: Use kcalloc() in raid1_reshape()
raid1: Use kcalloc() in setup_conf()
raid1: Return directly after a failed kzalloc() in setup_conf()
raid1: Move assignments for the variable "err" in setup_conf()
raid1: Less function calls in setup_conf() after error detection
raid1: Delete an error message for a failed memory allocation
raid1: Move a brace for a designated initialiser
raid1: Adjust 12 checks for null pointers
raid1: Replace printk() calls by the usage of higher level interfaces
raid1: Add some spaces for better code readability
raid1: Delete three unwanted spaces behind asterisks
raid1: Delete three unwanted spaces before increment operators
raid1: Replace a seq_printf() call by seq_puts() in raid1_status()
raid1: Improve another size determination in setup_conf()
raid5: Use kcalloc() in three functions
raid5: Improve another size determination in setup_conf()
raid5: Return directly after a failed kzalloc() in setup_conf()
raid5: Rename a jump label in setup_conf()
raid5: Return directly after a failed kcalloc() in alloc_thread_groups()
raid5: Delete two error messages for a failed memory allocation
raid5: Adjust two function calls together with a variable assignment
raid5: Move a brace for three designated initialisers
raid5: Replace printk() calls by the usage of higher level interfaces
raid5: Delete indentation for two jump labels
raid5: Adjust 13 checks for null pointers
raid5: Delete four unwanted spaces behind function names
raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
raid5: Move four asterisks
raid5: Add some spaces for better code readability
raid10: Use kcalloc() in two functions
raid10: Improve another size determination in setup_conf()
raid10: Delete an error message for a failed memory allocation
raid10: Return directly after detection of unsupported settings in setup_conf()
raid10: Return directly after a failed kzalloc() in setup_conf()
raid10: Move assignments for the variable "err" in setup_conf()
raid10: Less function calls in setup_conf() after error detection
raid10: Improve another size determination in raid10_start_reshape()
raid10: Move a brace for a designated initialiser
raid10: Replace printk() calls by the usage of higher level interfaces
raid10: Delete indentation for one jump label
raid10: Adjust 22 checks for null pointers
raid10: Replace a seq_printf() call by seq_puts() in raid10_status()
raid10: Delete two unwanted spaces behind asterisks
raid10: Add some spaces for better code readability
drivers/md/raid0.c | 170 ++++++++--------- drivers/md/raid1.c | 285 ++++++++++++++-------------- drivers/md/raid10.c | 366 ++++++++++++++++++------------------ drivers/md/raid5.c | 523 ++++++++++++++++++++++++---------------------------- 4 files changed, 649 insertions(+), 695 deletions(-)
Signature · 1 line
2.10.1
Re: MD-RAID: Fine-tuning for several function implementations
Please stop it NOW. This is not fine tuning but a waste of everyones time.
Re: MD-RAID: Fine-tuning for several function implementations
Quoted 1 line
This is not fine tuning but a waste of everyones time.
Does any of the published 54 update steps contain changes which you might find also worthwhile for the affected source files so that the shown software situation can be improved further?
Regards,
Markus
PATCH 1/54 md/raid0: Use kcalloc() in create_strip_zones()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 10:10:52 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/raid0.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/md/raid0.c +5 -4
@@ -150,12 +150,13 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) } err = -ENOMEM ; - conf->strip_zone =kzalloc (sizeof (struct strip_zone )* - conf->nr_strip_zones,GFP_KERNEL ); + conf->strip_zone =kcalloc (conf->nr_strip_zones, +sizeof (*conf->strip_zone), +GFP_KERNEL );if (!conf->strip_zone) goto abort; - conf->devlist =kzalloc (sizeof (struct md_rdev *)* - conf->nr_strip_zones*mddev->raid_disks, + conf->devlist =kcalloc (conf->nr_strip_zones * mddev->raid_disks, +sizeof (*conf->devlist),GFP_KERNEL );if (!conf->devlist) goto abort;
Signature · 1 line
2.10.1
PATCH 2/54 md/raid0: Less function calls in create_strip_zones() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 10:43:33 +0200
The kfree() function was called in up to two cases
by the create_strip_zones() function during error handling even if the passed data structure member (or variable) contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/raid0.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/md/raid0.c +11 -9
@@ -146,7 +146,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)mdname (mddev), mddev->chunk_sectors << 9, blksize); err = -EINVAL ; - goto abort; + goto free_conf; } err = -ENOMEM ;
@@ -154,12 +154,12 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)sizeof (*conf->strip_zone), GFP_KERNEL);if (!conf->strip_zone) - goto abort; + goto free_conf; conf->devlist =kcalloc (conf->nr_strip_zones * mddev->raid_disks,sizeof (*conf->devlist),GFP_KERNEL );if (!conf->devlist) - goto abort; + goto free_zone;/* The first zone must contain all devices, so here we check that * there is a proper alignment of slots to devices and find them all
@@ -190,17 +190,17 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)printk (KERN_ERR "md/raid0:%s: remove inactive devices before converting to RAID0\n" ,mdname (mddev)); - goto abort; + goto free_device_list; }if (j >= mddev->raid_disks) {printk (KERN_ERR "md/raid0:%s: bad disk number %d - " "aborting!\n" ,mdname (mddev), j); - goto abort; + goto free_device_list; }if (dev[j]) {printk (KERN_ERR "md/raid0:%s: multiple devices for %d - " "aborting!\n" ,mdname (mddev), j); - goto abort; + goto free_device_list; } dev[j] = rdev1;
@@ -211,7 +211,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)if (cnt != mddev->raid_disks) {printk (KERN_ERR "md/raid0:%s: too few disks (%d of %d) - " "aborting!\n" ,mdname (mddev), cnt, mddev->raid_disks); - goto abort; + goto free_device_list; } zone->nb_dev = cnt; zone->zone_end = smallest->sectors * cnt;
@@ -271,9 +271,11 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) *private_conf = conf;return 0 ; -abort: -kfree (conf->strip_zone); +free_device_list:kfree (conf->devlist); +free_zone: +kfree (conf->strip_zone); +free_conf:kfree (conf); *private_conf =ERR_PTR (err);return err;
Signature · 1 line
2.10.1
PATCH 3/54 md/raid0: Move a variable assignment in create_strip_zones()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 12:02:29 +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 memory allocation failure there.
--- drivers/md/raid0.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/md/raid0.c +7 -3
@@ -149,17 +149,21 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) goto free_conf; } - err = -ENOMEM ; conf->strip_zone =kcalloc (conf->nr_strip_zones,sizeof (*conf->strip_zone),GFP_KERNEL ); -if (!conf->strip_zone) +if (!conf->strip_zone) { + err = -ENOMEM ; goto free_conf; + } + conf->devlist =kcalloc (conf->nr_strip_zones * mddev->raid_disks,sizeof (*conf->devlist),GFP_KERNEL ); -if (!conf->devlist) +if (!conf->devlist) { + err = -ENOMEM ; goto free_zone; + }/* The first zone must contain all devices, so here we check that * there is a proper alignment of slots to devices and find them all
Signature · 1 line
2.10.1
PATCH 4/54 md/raid0: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 13:30:39 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
3. Remove prefixes from strings which were passed to some function and macro calls.
--- drivers/md/raid0.c | 100 +++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 53 deletions(-)
drivers/md/raid0.c +47 -53
@@ -17,6 +17,8 @@Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/blkdev.h> #include <linux/seq_file.h> #include <linux/module.h>
@@ -51,20 +53,20 @@ static void dump_zones(struct mddev *mddev)char b[BDEVNAME_SIZE ];struct r0conf *conf = mddev->private;int raid_disks = conf->strip_zone[0 ].nb_dev; -printk (KERN_INFO "md: RAID0 configuration for %s - %d zone%s\n" , +pr_info ("configuration for %s - %d zone%s\n" ,mdname (mddev), conf->nr_strip_zones, conf->nr_strip_zones=1 ?"" :"s" );for (j =0 ; j < conf->nr_strip_zones; j++) { -printk (KERN_INFO "md: zone%d=[" , j); +pr_info ("zone%d=[" , j);for (k =0 ; k < conf->strip_zone[j].nb_dev; k++) -printk (KERN_CONT "%s%s" , k?"/" :"" , -bdevname (conf->devlist[j*raid_disks - + k]->bdev, b)); -printk (KERN_CONT "]\n" ); - +pr_cont ("%s%s" , + k ?"/" :"" , +bdevname (conf->devlist[j * raid_disks + k] + ->bdev, + b)); +pr_cont ("]\n" ); zone_size = conf->strip_zone[j].zone_end - zone_start; -printk (KERN_INFO " zone-offset=%10lluKB, " -"device-offset=%10lluKB, size=%10lluKB\n" , +pr_info (" zone-offset=%10lluKB, device-offset=%10lluKB, size=%10lluKB\n" , (unsigned long long )zone_start>>1 , (unsigned long long )conf->strip_zone[j].dev_start>>1 , (unsigned long long )zone_size>>1 );
@@ -88,7 +90,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)if (!conf)return -ENOMEM ;rdev_for_each (rdev1, mddev) { -pr_debug ("md/raid0:%s: looking at %s\n" , +pr_debug ("%s: looking at %s\n" ,mdname (mddev),bdevname (rdev1->bdev, b)); c =0 ;
@@ -102,15 +104,14 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) rdev1->bdev->bd_disk->queue));rdev_for_each (rdev2, mddev) { -pr_debug ("md/raid0:%s: comparing %s(%llu)" -" with %s(%llu)\n" , +pr_debug ("%s: comparing %s(%llu) with %s(%llu)\n" ,mdname (mddev),bdevname (rdev1->bdev,b), (unsigned long long )rdev1->sectors,bdevname (rdev2->bdev,b2), (unsigned long long )rdev2->sectors);if (rdev2 = rdev1) { -pr_debug ("md/raid0:%s: END\n" , +pr_debug ("%s: END\n" ,mdname (mddev));break ; }
@@ -119,30 +120,30 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)* Not unique, don't count it as a new * group */ -pr_debug ("md/raid0:%s: EQUAL\n" , +pr_debug ("%s: EQUAL\n" ,mdname (mddev)); c =1 ;break ; } -pr_debug ("md/raid0:%s: NOT EQUAL\n" , +pr_debug ("%s: NOT EQUAL\n" ,mdname (mddev)); }if (!c) { -pr_debug ("md/raid0:%s: => UNIQUE\n" , +pr_debug ("%s: => UNIQUE\n" ,mdname (mddev)); conf->nr_strip_zones++; -pr_debug ("md/raid0:%s: %d zones\n" , +pr_debug ("%s: %d zones\n" ,mdname (mddev), conf->nr_strip_zones); } } -pr_debug ("md/raid0:%s: FINAL %d zones\n" , +pr_debug ("%s: FINAL %d zones\n" ,mdname (mddev), conf->nr_strip_zones);/* * now since we have the hard sector sizes, we can make sure * chunk size is a multiple of that sector size */ if ((mddev->chunk_sectors <<9 ) % blksize) { -printk (KERN_ERR "md/raid0:%s: chunk_size of %d not multiple of block size %d\n" , +pr_err ("%s: chunk_size of %d not multiple of block size %d\n" ,mdname (mddev), mddev->chunk_sectors <<9 , blksize); err = -EINVAL ;
@@ -191,19 +192,18 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) }if (j <0 ) { -printk (KERN_ERR -"md/raid0:%s: remove inactive devices before converting to RAID0\n" , +pr_err ("%s: remove inactive devices before converting to RAID0\n" ,mdname (mddev)); goto free_device_list; }if (j >= mddev->raid_disks) { -printk (KERN_ERR "md/raid0:%s: bad disk number %d - " -"aborting!\n" ,mdname (mddev), j); +pr_err ("%s: bad disk number %d%s" , +mdname (mddev), j," - aborting!\n" ); goto free_device_list; }if (dev[j]) { -printk (KERN_ERR "md/raid0:%s: multiple devices for %d - " -"aborting!\n" ,mdname (mddev), j); +pr_err ("%s: multiple devices for %d%s" , +mdname (mddev), j," - aborting!\n" ); goto free_device_list; } dev[j] = rdev1;
@@ -213,8 +213,8 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) cnt++; }if (cnt != mddev->raid_disks) { -printk (KERN_ERR "md/raid0:%s: too few disks (%d of %d) - " -"aborting!\n" ,mdname (mddev), cnt, mddev->raid_disks); +pr_err ("%s: too few disks (%d of %d)%s" , +mdname (mddev), cnt, mddev->raid_disks," - aborting!\n" ); goto free_device_list; } zone->nb_dev = cnt;
@@ -229,8 +229,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) zone = conf->strip_zone + i; dev = conf->devlist + i * mddev->raid_disks; - -pr_debug ("md/raid0:%s: zone %d\n" ,mdname (mddev), i); +pr_debug ("%s: zone %d\n" ,mdname (mddev), i); zone->dev_start = smallest->sectors; smallest =NULL ; c =0 ;
@@ -238,20 +237,19 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)for (j=0 ; j<cnt; j++) { rdev = conf->devlist[j];if (rdev->sectors <= zone->dev_start) { -pr_debug ("md/raid0:%s: checking %s ... nope\n" , +pr_debug ("%s: checking %s ... nope\n" ,mdname (mddev),bdevname (rdev->bdev, b));continue ; } -pr_debug ("md/raid0:%s: checking %s ..." -" contained as device %d\n" , +pr_debug ("%s: checking %s ... contained as device %d\n" ,mdname (mddev),bdevname (rdev->bdev, b), c); dev[c] = rdev; c++;if (!smallest || rdev->sectors < smallest->sectors) { smallest = rdev; -pr_debug ("md/raid0:%s: (%llu) is smallest!.\n" , +pr_debug ("%s: (%llu) is smallest!.\n" ,mdname (mddev), (unsigned long long )rdev->sectors); }
@@ -259,19 +257,18 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) zone->nb_dev = c; sectors = (smallest->sectors - zone->dev_start) * c; -pr_debug ("md/raid0:%s: zone->nb_dev: %d, sectors: %llu\n" , +pr_debug ("%s: zone->nb_dev: %d, sectors: %llu\n" ,mdname (mddev), zone->nb_dev, (unsigned long long )sectors); curr_zone_end += sectors; zone->zone_end = curr_zone_end; - -pr_debug ("md/raid0:%s: current zone start: %llu\n" , +pr_debug ("%s: current zone start: %llu\n" ,mdname (mddev), (unsigned long long )smallest->sectors); } -pr_debug ("md/raid0:%s: done.\n" ,mdname (mddev)); +pr_debug ("%s: done.\n" ,mdname (mddev)); *private_conf = conf;return 0 ;
@@ -364,8 +361,7 @@ static int raid0_run(struct mddev *mddev)int ret;if (mddev->chunk_sectors =0 ) { -printk (KERN_ERR "md/raid0:%s: chunk size must be set.\n" , -mdname (mddev)); +pr_err ("%s: chunk size must be set.\n" ,mdname (mddev));return -EINVAL ; }if (md_check_no_bitmap (mddev))
@@ -405,10 +401,9 @@ static int raid0_run(struct mddev *mddev)/* calculate array device size */ md_set_array_sectors (mddev,raid0_size (mddev,0 ,0 )); - -printk (KERN_INFO "md/raid0:%s: md_size is %llu sectors.\n" , -mdname (mddev), - (unsigned long long )mddev->array_sectors); +pr_info ("%s: md_size is %llu sectors.\n" , +mdname (mddev), + (unsigned long long )mddev->array_sectors);if (mddev->queue) {/* calculate the max read-ahead size.
@@ -516,7 +511,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)struct r0conf *priv_conf;if (mddev->degraded !=1 ) { -printk (KERN_ERR "md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n" , +pr_err ("%s: raid5 must be degraded! Degraded disks: %d\n" ,mdname (mddev), mddev->degraded);return ERR_PTR (-EINVAL );
@@ -525,7 +520,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)rdev_for_each (rdev, mddev) {/* check slot number for a disk */ if (rdev->raid_disk = mddev->raid_disks-1 ) { -printk (KERN_ERR "md/raid0:%s: raid5 must have missing parity disk!\n" , +pr_err ("%s: raid5 must have missing parity disk!\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }
@@ -556,18 +551,18 @@ static void *raid0_takeover_raid10(struct mddev *mddev)* - all mirrors must be already degraded */ if (mddev->layout != ((1 <<8 ) +2 )) { -printk (KERN_ERR "md/raid0:%s:: Raid0 cannot takeover layout: 0x%x\n" , +pr_err ("%s: Raid0 cannot takeover layout: 0x%x\n" ,mdname (mddev), mddev->layout);return ERR_PTR (-EINVAL ); }if (mddev->raid_disks &1 ) { -printk (KERN_ERR "md/raid0:%s: Raid0 cannot takeover Raid10 with odd disk number.\n" , +pr_err ("%s: Raid0 cannot takeover Raid10 with odd disk number.\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }if (mddev->degraded != (mddev->raid_disks>>1 )) { -printk (KERN_ERR "md/raid0:%s: All mirrors must be already degraded!\n" , +pr_err ("%s: All mirrors must be already degraded!\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }
@@ -595,7 +590,7 @@ static void *raid0_takeover_raid1(struct mddev *mddev)* - (N - 1) mirror drives must be already faulty */ if ((mddev->raid_disks -1 ) != mddev->degraded) { -printk (KERN_ERR "md/raid0:%s: (N - 1) mirrors drives must be already faulty!\n" , +pr_err ("%s: (N - 1) mirrors drives must be already faulty!\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }
@@ -638,7 +633,7 @@ static void *raid0_takeover(struct mddev *mddev)*/ if (mddev->bitmap) { -printk (KERN_ERR "md/raid0: %s: cannot takeover array with bitmap\n" , +pr_err ("%s: cannot takeover array with bitmap\n" ,mdname (mddev));return ERR_PTR (-EBUSY ); }
@@ -649,7 +644,7 @@ static void *raid0_takeover(struct mddev *mddev)if (mddev->layout =ALGORITHM_PARITY_N )return raid0_takeover_raid45 (mddev); -printk (KERN_ERR "md/raid0:%s: Raid can only takeover Raid5 with layout: %d\n" , +pr_err ("%s: Raid can only takeover Raid5 with layout: %d\n" ,mdname (mddev),ALGORITHM_PARITY_N ); }
@@ -659,9 +654,8 @@ static void *raid0_takeover(struct mddev *mddev)if (mddev->level =1 )return raid0_takeover_raid1 (mddev); -printk (KERN_ERR "Takeover from raid%i to raid0 not supported\n" , +pr_err ("Takeover from raid%i to raid0 not supported\n" , mddev->level); -return ERR_PTR (-EINVAL ); }
Signature · 1 line
2.10.1
PATCH 5/54 md/raid0: Move another variable assignment in create_strip_zones()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 13:54:36 +0200
One local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment to the end to indicate a software failure there.
Use it finally in four if branches for exception handling.
--- drivers/md/raid0.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/raid0.c +7 -5
@@ -173,7 +173,6 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) cnt =0 ; smallest =NULL ; dev = conf->devlist; - err = -EINVAL ;rdev_for_each (rdev1, mddev) {int j = rdev1->raid_disk;
@@ -194,17 +193,17 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)if (j <0 ) {pr_err ("%s: remove inactive devices before converting to RAID0\n" ,mdname (mddev)); - goto free_device_list; + goto e_inval; }if (j >= mddev->raid_disks) {pr_err ("%s: bad disk number %d%s" ,mdname (mddev), j," - aborting!\n" ); - goto free_device_list; + goto e_inval; }if (dev[j]) {pr_err ("%s: multiple devices for %d%s" ,mdname (mddev), j," - aborting!\n" ); - goto free_device_list; + goto e_inval; } dev[j] = rdev1;
@@ -215,7 +214,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)if (cnt != mddev->raid_disks) {pr_err ("%s: too few disks (%d of %d)%s" ,mdname (mddev), cnt, mddev->raid_disks," - aborting!\n" ); - goto free_device_list; + goto e_inval; } zone->nb_dev = cnt; zone->zone_end = smallest->sectors * cnt;
@@ -280,6 +279,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)kfree (conf); *private_conf =ERR_PTR (err);return err; +e_inval: + err = -EINVAL ; + goto free_device_list; }/* Find the zone which holds a particular offset
Signature · 1 line
2.10.1
PATCH 6/54 md/raid0: Delete four unwanted spaces behind function names
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:21:21 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: space prohibited between function name and open parenthesis '('
Thus fix the affected source code places.
--- drivers/md/raid0.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/raid0.c +4 -4
@@ -680,14 +680,14 @@ static struct md_personality raid0_personality .congested = raid0_congested, }; -static int __init raid0_init (void ) +static int __init raid0_init (void ) { -return register_md_personality (&raid0_personality); +return register_md_personality (&raid0_personality); } -static void raid0_exit (void ) +static void raid0_exit (void ) { -unregister_md_personality (&raid0_personality); +unregister_md_personality (&raid0_personality); }module_init (raid0_init);
Signature · 1 line
2.10.1
PATCH 7/54 md/raid0: Move two misplaced braces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:25:01 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/raid0.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/md/raid0.c +2 -3
@@ -222,8 +222,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) curr_zone_end = zone->zone_end;/* now do the other zones */ -for (i =1 ; i < conf->nr_strip_zones; i++) - { +for (i =1 ; i < conf->nr_strip_zones; i++) {int j; zone = conf->strip_zone + i;
@@ -665,8 +664,7 @@ static void raid0_quiesce(struct mddev *mddev, int state) { } -static struct md_personality raid0_personality-{ +static struct md_personality raid0_personality = { .name ="raid0" , .level =0 , .owner =THIS_MODULE ,
Signature · 1 line
2.10.1
PATCH 8/54 md/raid0: Delete an unnecessary return statement in raid0_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:34:33 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: void function return statements are not generally useful
Thus remove such a statement here.
--- drivers/md/raid0.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/raid0.c +0 -1
@@ -503,7 +503,6 @@ static void raid0_make_request(struct mddev *mddev, struct bio *bio)static void raid0_status (struct seq_file *seq,struct mddev *mddev) {seq_printf (seq," %dk chunks" , mddev->chunk_sectors /2 ); -return ; }static void *raid0_takeover_raid45 (struct mddev *mddev)
Signature · 1 line
2.10.1
PATCH 9/54 md/raid0: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:48:34 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/raid0.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/md/raid0.c +6 -6
@@ -55,7 +55,7 @@ static void dump_zones(struct mddev *mddev)int raid_disks = conf->strip_zone[0 ].nb_dev;pr_info ("configuration for %s - %d zone%s\n" ,mdname (mddev), - conf->nr_strip_zones, conf->nr_strip_zones=1 ?"" :"s" ); + conf->nr_strip_zones, conf->nr_strip_zones =1 ?"" :"s" );for (j =0 ; j < conf->nr_strip_zones; j++) {pr_info ("zone%d=[" , j);for (k =0 ; k < conf->strip_zone[j].nb_dev; k++)
@@ -106,9 +106,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)rdev_for_each (rdev2, mddev) {pr_debug ("%s: comparing %s(%llu) with %s(%llu)\n" ,mdname (mddev), -bdevname (rdev1->bdev,b), +bdevname (rdev1->bdev, b), (unsigned long long )rdev1->sectors, -bdevname (rdev2->bdev,b2), +bdevname (rdev2->bdev, b2), (unsigned long long )rdev2->sectors);if (rdev2 = rdev1) { pr_debug("%s: END\n",
@@ -232,7 +232,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf) smallest =NULL ; c =0 ; -for (j=0 ; j<cnt; j++) { +for (j =0 ; j < cnt; j++) { rdev = conf->devlist[j];if (rdev->sectors <= zone->dev_start) { pr_debug("%s: checking %s ... nope\n",
@@ -418,8 +418,8 @@ static int raid0_run(struct mddev *mddev)*/ int stripe = mddev->raid_disks * (mddev->chunk_sectors <<9 ) /PAGE_SIZE ; -if (mddev->queue->backing_dev_info.ra_pages <2 * stripe) - mddev->queue->backing_dev_info.ra_pages =2 * stripe; +if (mddev->queue->backing_dev_info.ra_pages <2 * stripe) + mddev->queue->backing_dev_info.ra_pages =2 * stripe; }dump_zones (mddev);
Signature · 1 line
2.10.1
PATCH 10/54 md/raid1: Use kcalloc() in alloc_behind_pages()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:01:04 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/raid1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/raid1.c +1 -2
@@ -955,8 +955,7 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) {int i;struct bio_vec *bvec; -struct bio_vec *bvecs =kzalloc (bio->bi_vcnt *sizeof (struct bio_vec ), -GFP_NOIO ); +struct bio_vec *bvecs =kcalloc (bio->bi_vcnt,sizeof (*bvecs),GFP_NOIO );if (unlikely (!bvecs))return ;
Signature · 1 line
2.10.1
PATCH 11/54 md/raid1: Use kcalloc() in raid1_reshape()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:17:13 +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 "kcalloc".
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/raid1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid1.c +2 -2
@@ -3081,8 +3081,8 @@ static int raid1_reshape(struct mddev *mddev)kfree (newpoolinfo);return -ENOMEM ; } - newmirrors =kzalloc (sizeof (struct raid1_info ) * raid_disks *2 , -GFP_KERNEL ); + + newmirrors =kcalloc (raid_disks *2 ,sizeof (*newmirrors),GFP_KERNEL );if (!newmirrors) {kfree (newpoolinfo);mempool_destroy (newpool);
Signature · 1 line
2.10.1
PATCH 12/54 md/raid1: Use kcalloc() in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:30:28 +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 "kcalloc".
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/raid1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/raid1.c +3 -3
@@ -2781,9 +2781,9 @@ static struct r1conf *setup_conf(struct mddev *mddev)if (!conf) goto abort; - conf->mirrors =kzalloc (sizeof (struct raid1_info ) - * mddev->raid_disks *2 , -GFP_KERNEL ); + conf->mirrors =kcalloc (mddev->raid_disks *2 , +sizeof (*conf->mirrors), +GFP_KERNEL );if (!conf->mirrors) goto abort;
Signature · 1 line
2.10.1
PATCH 13/54 md/raid1: Return directly after a failed kzalloc() in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:56:41 +0200
* Return directly after a call of the function "kzalloc" failed at the beginning.
* Delete a repeated check for the local variable "conf" which became unnecessary with this refactoring.
* Reorder two calls for the function "kfree" at the end.
--- drivers/md/raid1.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/md/raid1.c +6 -8
@@ -2779,7 +2779,7 @@ static struct r1conf *setup_conf(struct mddev *mddev) conf =kzalloc (sizeof (struct r1conf ),GFP_KERNEL );if (!conf) - goto abort; +return ERR_PTR (-ENOMEM ); conf->mirrors = kcalloc(mddev->raid_disks * 2, sizeof(*conf->mirrors),
@@ -2880,13 +2880,11 @@ static struct r1conf *setup_conf(struct mddev *mddev)return conf; abort: -if (conf) { -mempool_destroy (conf->r1bio_pool); -kfree (conf->mirrors); -safe_put_page (conf->tmppage); -kfree (conf->poolinfo); -kfree (conf); - } +mempool_destroy (conf->r1bio_pool); +kfree (conf->poolinfo); +safe_put_page (conf->tmppage); +kfree (conf->mirrors); +kfree (conf);return ERR_PTR (err); }
Signature · 1 line
2.10.1
PATCH 14/54 md/raid1: Move assignments for the variable "err" in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 17:34:10 +0200
One local variable was set to an error code in a few cases before a concrete error situation was detected. Thus move the corresponding assignments into if branches to indicate a software failure there.
--- drivers/md/raid1.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-)
drivers/md/raid1.c +26 -14
@@ -2775,7 +2775,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)int i;struct raid1_info *disk;struct md_rdev *rdev; -int err = -ENOMEM ; +int err; conf =kzalloc (sizeof (struct r1conf ),GFP_KERNEL );if (!conf)
@@ -2784,26 +2784,33 @@ static struct r1conf *setup_conf(struct mddev *mddev) conf->mirrors =kcalloc (mddev->raid_disks *2 ,sizeof (*conf->mirrors),GFP_KERNEL ); -if (!conf->mirrors) +if (!conf->mirrors) { + err = -ENOMEM ; goto abort; + } conf->tmppage =alloc_page (GFP_KERNEL ); -if (!conf->tmppage) +if (!conf->tmppage) { + err = -ENOMEM ; goto abort; + } conf->poolinfo =kzalloc (sizeof (*conf->poolinfo),GFP_KERNEL ); -if (!conf->poolinfo) +if (!conf->poolinfo) { + err = -ENOMEM ; goto abort; + } + conf->poolinfo->raid_disks = mddev->raid_disks *2 ; conf->r1bio_pool =mempool_create (NR_RAID1_BIOS , r1bio_pool_alloc, r1bio_pool_free, conf->poolinfo); -if (!conf->r1bio_pool) +if (!conf->r1bio_pool) { + err = -ENOMEM ; goto abort; + } conf->poolinfo->mddev = mddev; - - err = -EINVAL ;spin_lock_init (&conf->device_lock);rdev_for_each (rdev, mddev) {struct request_queue *q;
@@ -2816,8 +2823,11 @@ static struct r1conf *setup_conf(struct mddev *mddev)else disk = conf->mirrors + disk_idx; -if (disk->rdev) +if (disk->rdev) { + err = -EINVAL ; goto abort; + } + disk->rdev = rdev; q =bdev_get_queue (rdev->bdev);
@@ -2838,8 +2848,6 @@ static struct r1conf *setup_conf(struct mddev *mddev) conf->start_next_window = MaxSector; conf->current_window_requests = conf->next_window_requests =0 ; - - err = -EIO ;for (i =0 ; i < conf->raid_disks *2 ; i++) { disk = conf->mirrors + i;
@@ -2854,9 +2862,13 @@ static struct r1conf *setup_conf(struct mddev *mddev) disk->rdev disk[conf->raid_disks].rdev; disk[conf->raid_disks].rdev =NULL ; - }else if (!test_bit (In_sync, &disk->rdev->flags)) -/* Original is not in_sync - bad */ - goto abort; + }else { +if (!test_bit (In_sync, &disk->rdev->flags)) { +/* Original is not in_sync - bad */ + err = -EIO ; + goto abort; + } + } } if (!disk->rdev ||
@@ -2868,12 +2880,12 @@ static struct r1conf *setup_conf(struct mddev *mddev) } } - err = -ENOMEM ; conf->thread =md_register_thread (raid1d, mddev,"raid1" );if (!conf->thread) {printk (KERN_ERR "md/raid1:%s: couldn't allocate thread\n" ,mdname (mddev)); + err = -ENOMEM ; goto abort; }
Signature · 1 line
2.10.1
PATCH 15/54 md/raid1: Less function calls in setup_conf() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:01:02 +0200
Resource release functions were called in up to four cases by the setup_conf() function during error handling even if the passed data structure members contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/raid1.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/md/raid1.c +12 -9
@@ -2786,19 +2786,19 @@ static struct r1conf *setup_conf(struct mddev *mddev) GFP_KERNEL);if (!conf->mirrors) { err = -ENOMEM ; - goto abort; + goto free_conf; } conf->tmppage =alloc_page (GFP_KERNEL );if (!conf->tmppage) { err = -ENOMEM ; - goto abort; + goto free_mirrors; } conf->poolinfo =kzalloc (sizeof (*conf->poolinfo),GFP_KERNEL );if (!conf->poolinfo) { err = -ENOMEM ; - goto abort; + goto put_page; } conf->poolinfo->raid_disks = mddev->raid_disks *2 ;
@@ -2807,7 +2807,7 @@ static struct r1conf *setup_conf(struct mddev *mddev) conf->poolinfo);if (!conf->r1bio_pool) { err = -ENOMEM ; - goto abort; + goto free_poolinfo; } conf->poolinfo->mddev = mddev;
@@ -2825,7 +2825,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)if (disk->rdev) { err = -EINVAL ; - goto abort; + goto destroy_pool; } disk->rdev = rdev;
@@ -2866,7 +2866,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)if (!test_bit (In_sync, &disk->rdev->flags)) {/* Original is not in_sync - bad */ err = -EIO ; - goto abort; + goto destroy_pool; } } }
@@ -2886,16 +2886,19 @@ static struct r1conf *setup_conf(struct mddev *mddev)"md/raid1:%s: couldn't allocate thread\n" , mdname(mddev)); err = -ENOMEM ; - goto abort; + goto destroy_pool; }return conf; - - abort: +destroy_pool:mempool_destroy (conf->r1bio_pool); +free_poolinfo:kfree (conf->poolinfo); +put_page:safe_put_page (conf->tmppage); +free_mirrors:kfree (conf->mirrors); +free_conf:kfree (conf);return ERR_PTR (err); }
Signature · 1 line
2.10.1
PATCH 16/54 md/raid1: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:15:20 +0200
Omit an extra message for a memory allocation failure in this function.
--- drivers/md/raid1.c | 3 --- 1 file changed, 3 deletions(-)
drivers/md/raid1.c +0 -3
@@ -2882,9 +2882,6 @@ static struct r1conf *setup_conf(struct mddev *mddev) conf->thread =md_register_thread (raid1d, mddev,"raid1" );if (!conf->thread) { -printk (KERN_ERR -"md/raid1:%s: couldn't allocate thread\n" , -mdname (mddev)); err = -ENOMEM ; goto destroy_pool; }
Signature · 1 line
2.10.1
PATCH 17/54 md/raid1: Move a brace for a designated initialiser
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:25:05 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/raid1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/raid1.c +1 -1
@@ -3176,8 +3176,7 @@ static void *raid1_takeover(struct mddev *mddev)return ERR_PTR (-EINVAL ); } -static struct md_personality raid1_personality -{ +static struct md_personality raid1_personality = { .name ="raid1" , .level =1 , .owner =THIS_MODULE ,
Signature · 1 line
2.10.1
PATCH 18/54 md/raid1: Adjust 12 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:55:42 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/md/raid1.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/md/raid1.c +12 -12
@@ -474,7 +474,7 @@ static void raid1_end_write_request(struct bio *bio) } } } -if (r1_bio->bios[mirror] =NULL ) +if (!r1_bio->bios[mirror])rdev_dec_pending (rdev, conf->mddev);/*
@@ -549,7 +549,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect rdev =rcu_dereference (conf->mirrors[disk].rdev);if (r1_bio->bios[disk] =IO_BLOCKED - || rdev =NULL + || !rdev ||test_bit (Faulty, &rdev->flags))continue ; if (!test_bit(In_sync, &rdev->flags) &&
@@ -1582,7 +1582,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)*/ if (rdev->saved_raid_disk >=0 && rdev->saved_raid_disk >= first && - conf->mirrors[rdev->saved_raid_disk].rdev =NULL ) + !conf->mirrors[rdev->saved_raid_disk].rdev) first = last = rdev->saved_raid_disk;for (mirror = first; mirror <= last; mirror++) {
@@ -1605,7 +1605,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)break ; }if (test_bit (WantReplacement, &p->rdev->flags) && - p[conf->raid_disks].rdev =NULL ) { + !p[conf->raid_disks].rdev) {/* Add this device as a replacement */ clear_bit (In_sync, &rdev->flags);set_bit (Replacement, &rdev->flags);
@@ -2002,7 +2002,7 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)atomic_set (&r1_bio->remaining,1 );for (i =0 ; i < disks ; i++) { wbio = r1_bio->bios[i]; -if (wbio->bi_end_io =NULL || +if (!wbio->bi_end_io || (wbio->bi_end_io = end_sync_read && (i = r1_bio->read_disk || !test_bit (MD_RECOVERY_SYNC , &mddev->recovery))))
@@ -2220,7 +2220,7 @@ static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_biofor (m =0 ; m < conf->raid_disks *2 ; m++) {struct md_rdev *rdev = conf->mirrors[m].rdev;struct bio *bio = r1_bio->bios[m]; -if (bio->bi_end_io =NULL ) +if (!bio->bi_end_io)continue ;if (!bio->bi_error &&test_bit (R1BIO_MadeGood, &r1_bio->state)) {
@@ -2247,7 +2247,7 @@ static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) r1_bio->sector, r1_bio->sectors, 0);rdev_dec_pending (rdev, conf->mddev); - }else if (r1_bio->bios[m] !=NULL ) { + }else if (r1_bio->bios[m]) {/* This drive got a write error. We need to * narrow down and record precise write * errors.
@@ -2509,7 +2509,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,return 0 ; } -if (mddev->bitmap =NULL && +if (!mddev->bitmap && mddev->recovery_cp = MaxSector && !test_bit (MD_RECOVERY_REQUESTED , &mddev->recovery) && conf->fullsync =0 ) {
@@ -2564,7 +2564,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,bio_reset (bio); rdev =rcu_dereference (conf->mirrors[i].rdev); -if (rdev =NULL || +if (!rdev ||test_bit (Faulty, &rdev->flags)) {if (i < conf->raid_disks) still_degraded =1 ;
@@ -2710,7 +2710,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,while (i >0 ) { i--; bio = r1_bio->bios[i]; -if (bio->bi_end_io=NULL ) +if (!bio->bi_end_io)continue ;/* remove last page from this bio */ bio->bi_vcnt--;
@@ -2924,7 +2924,7 @@ static int raid1_run(struct mddev *mddev)* bookkeeping area. [whatever we allocate in run(), * should be freed in raid1_free()] */ -if (mddev->private =NULL ) +if (!mddev->private) conf =setup_conf (mddev);else conf = mddev->private;
@@ -2946,7 +2946,7 @@ static int raid1_run(struct mddev *mddev) mddev->degraded =0 ;for (i=0 ; i < conf->raid_disks; i++) -if (conf->mirrors[i].rdev =NULL || +if (!conf->mirrors[i].rdev || !test_bit (In_sync, &conf->mirrors[i].rdev->flags) ||test_bit (Faulty, &conf->mirrors[i].rdev->flags)) mddev->degraded++;
Signature · 6 lines
2.10.1 -- 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 19/54 md/raid1: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 20:30:07 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
--- drivers/md/raid1.c | 91 ++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 48 deletions(-)
drivers/md/raid1.c +43 -48
@@ -31,6 +31,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/slab.h> #include <linux/delay.h> #include <linux/blkdev.h>
@@ -347,13 +349,11 @@ static void raid1_end_read_request(struct bio *bio)* oops, read error: */ char b[BDEVNAME_SIZE ]; -printk_ratelimited ( -KERN_ERR "md/raid1:%s: %s: " -"rescheduling sector %llu\n" , -mdname (conf->mddev), -bdevname (rdev->bdev, - b), - (unsigned long long )r1_bio->sector); + +pr_err_ratelimited ("%s: %s: rescheduling sector %llu\n" , +mdname (conf->mddev), +bdevname (rdev->bdev, b), + (unsigned long long )r1_bio->sector);set_bit (R1BIO_ReadError, &r1_bio->state);reschedule_retry (r1_bio);/* don't drop the reference on read_disk yet */
@@ -1457,34 +1457,34 @@ static void raid1_error(struct mddev *mddev, struct md_rdev *rdev)set_bit (MD_RECOVERY_INTR , &mddev->recovery);set_mask_bits (&mddev->flags,0 ,BIT (MD_CHANGE_DEVS ) |BIT (MD_CHANGE_PENDING )); -printk (KERN_ALERT -"md/raid1:%s: Disk failure on %s, disabling device.\n" -"md/raid1:%s: Operation continuing on %d devices.\n" , -mdname (mddev),bdevname (rdev->bdev, b), -mdname (mddev), conf->raid_disks - mddev->degraded); +pr_alert ("%s: Disk failure on %s, disabling device.\n" +MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n" , +mdname (mddev),bdevname (rdev->bdev, b), +mdname (mddev), conf->raid_disks - mddev->degraded); }static void print_conf (struct r1conf *conf) {int i; -printk (KERN_DEBUG "RAID1 conf printout:\n" ); +pr_debug ("conf printout:\n" );if (!conf) { -printk (KERN_DEBUG "(!conf)\n" ); +pr_debug ("(!conf)\n" );return ; } -printk (KERN_DEBUG " --- wd:%d rd:%d\n" , conf->raid_disks - conf->mddev->degraded, - conf->raid_disks); +pr_debug ("--- wd:%d rd:%d\n" , + conf->raid_disks - conf->mddev->degraded, + conf->raid_disks);rcu_read_lock ();for (i =0 ; i < conf->raid_disks; i++) {char b[BDEVNAME_SIZE ];struct md_rdev *rdev =rcu_dereference (conf->mirrors[i].rdev);if (rdev) -printk (KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n" , - i, !test_bit (In_sync, &rdev->flags), - !test_bit (Faulty, &rdev->flags), -bdevname (rdev->bdev,b)); +pr_debug ("disk %d, wo:%d, o:%d, dev:%s\n" , + i, !test_bit (In_sync, &rdev->flags), + !test_bit (Faulty, &rdev->flags), +bdevname (rdev->bdev, b)); }rcu_read_unlock (); }
@@ -1821,11 +1821,10 @@ static int fix_sync_read_error(struct r1bio *r1_bio)* work just disable and interrupt the recovery. * Don't fail devices as that won't really help. */ -printk (KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O read error" -" for block %llu\n" , -mdname (mddev), -bdevname (bio->bi_bdev, b), - (unsigned long long )r1_bio->sector); +pr_alert ("%s: %s: unrecoverable I/O read error for block %llu\n" , +mdname (mddev), +bdevname (bio->bi_bdev, b), + (unsigned long long )r1_bio->sector);for (d =0 ; d < conf->raid_disks *2 ; d++) { rdev = conf->mirrors[d].rdev;if (!rdev ||test_bit (Faulty, &rdev->flags))
@@ -2118,13 +2117,13 @@ static void fix_read_error(struct r1conf *conf, int read_disk,if (r1_sync_page_io (rdev, sect, s, conf->tmppage,READ )) {atomic_add (s, &rdev->corrected_errors); -printk (KERN_INFO -"md/raid1:%s: read error corrected " -"(%d sectors at %llu on %s)\n" , -mdname (mddev), s, - (unsigned long long )(sect + - rdev->data_offset), -bdevname (rdev->bdev, b)); +pr_info ("%s: read error corrected " +"(%d sectors at %llu on %s)\n" , +mdname (mddev), + s, + (unsigned long long )(sect + + rdev->data_offset), +bdevname (rdev->bdev, b)); }rdev_dec_pending (rdev, mddev); }else
@@ -2307,9 +2306,8 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) read_more: disk =read_balance (conf, r1_bio, &max_sectors);if (disk =-1 ) { -printk (KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O" -" read error for block %llu\n" , -mdname (mddev), b, (unsigned long long )r1_bio->sector); +pr_alert ("%s: %s: unrecoverable I/O read error for block %llu\n" , +mdname (mddev), b, (unsigned long long )r1_bio->sector);raid_end_bio_io (r1_bio); }else {const unsigned long do_sync
@@ -2325,8 +2323,7 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) max_sectors); r1_bio->bios[r1_bio->read_disk] = bio; rdev = conf->mirrors[disk].rdev; - printk_ratelimited(KERN_ERR - "md/raid1:%s: redirecting sector %llu" + pr_err_ratelimited("%s: redirecting sector %llu" " to other mirror: %s\n", mdname(mddev), (unsigned long long)r1_bio->sector,
@@ -2910,12 +2907,12 @@ static int raid1_run(struct mddev *mddev)bool discard_supported = false;if (mddev->level !=1 ) { -printk (KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n" , +pr_err ("%s: raid level not set to mirroring (%d)\n" ,mdname (mddev), mddev->level);return -EIO ; }if (mddev->reshape_position != MaxSector) { -printk (KERN_ERR "md/raid1:%s: reshape_position set but not supported\n" , +pr_err ("%s: reshape_position set but not supported\n" ,mdname (mddev));return -EIO ; }
@@ -2955,12 +2952,11 @@ static int raid1_run(struct mddev *mddev) mddev->recovery_cp = MaxSector;if (mddev->recovery_cp != MaxSector) -printk (KERN_NOTICE "md/raid1:%s: not clean" -" -- starting background reconstruction\n" , -mdname (mddev)); -printk (KERN_INFO -"md/raid1:%s: active with %d out of %d mirrors\n" , -mdname (mddev), mddev->raid_disks - mddev->degraded, +pr_notice ("%s: not clean -- starting background reconstruction\n" , +mdname (mddev)); +pr_info ("%s: active with %d out of %d mirrors\n" , +mdname (mddev), + mddev->raid_disks - mddev->degraded, mddev->raid_disks);/*
@@ -3112,9 +3108,8 @@ static int raid1_reshape(struct mddev *mddev) rdev->raid_disk = d2;sysfs_unlink_rdev (mddev, rdev);if (sysfs_link_rdev (mddev, rdev)) -printk (KERN_WARNING -"md/raid1:%s: cannot register rd%d\n" , -mdname (mddev), rdev->raid_disk); +pr_warn ("%s: cannot register rd%d\n" , +mdname (mddev), rdev->raid_disk); }if (rdev) newmirrors[d2++].rdev = rdev;
Signature · 1 line
2.10.1
PATCH 20/54 md/raid1: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 20:42:25 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/raid1.c | 62 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 30 deletions(-)
drivers/md/raid1.c +32 -30
@@ -136,8 +136,8 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data) }/* If not user-requests, copy the page pointers to all bios */ if (!test_bit (MD_RECOVERY_REQUESTED , &pi->mddev->recovery)) { -for (i=0 ; i<RESYNC_PAGES ; i++) -for (j=1 ; j<pi->raid_disks; j++) +for (i =0 ; i <RESYNC_PAGES ; i++) +for (j =1 ; j < pi->raid_disks; j++) r1_bio->bios[j]->bi_io_vec[i].bv_page r1_bio->bios[0]->bi_io_vec[i].bv_page; }
@@ -160,7 +160,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)static void r1buf_pool_free (void *__r1_bio,void *data) {struct pool_info *pi = data; -int i,j; +int i, j;struct r1bio *r1bio = __r1_bio;for (i =0 ; i <RESYNC_PAGES ; i++)
@@ -170,7 +170,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data) r1bio->bios[0]->bi_io_vec[i].bv_page)safe_put_page (r1bio->bios[j]->bi_io_vec[i].bv_page); } -for (i=0 ; i < pi->raid_disks; i++) +for (i =0 ; i < pi->raid_disks; i++)bio_put (r1bio->bios[i]);r1bio_pool_free (r1bio, data);
@@ -1785,7 +1785,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)int sectors = r1_bio->sectors;int idx =0 ; -while (sectors) { +while (sectors) {int s = sectors;int d = r1_bio->read_disk;int success =0 ;
@@ -2040,7 +2040,8 @@ static void fix_read_error(struct r1conf *conf, int read_disk, sector_t sect, int sectors) {struct mddev *mddev = conf->mddev; -while (sectors) { + +while (sectors) {int s = sectors;int d = read_disk;int success =0 ;
@@ -2087,7 +2088,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,/* write it back and re-read */ start = d;while (d != read_disk) { -if (d=0 ) +if (d =0 ) d = conf->raid_disks *2 ; d--;rcu_read_lock ();
@@ -2105,7 +2106,8 @@ static void fix_read_error(struct r1conf *conf, int read_disk, d = start;while (d != read_disk) {char b[BDEVNAME_SIZE ]; -if (d=0 ) + +if (d =0 ) d = conf->raid_disks *2 ; d--;rcu_read_lock ();
@@ -2942,7 +2944,7 @@ static int raid1_run(struct mddev *mddev) } mddev->degraded =0 ; -for (i=0 ; i < conf->raid_disks; i++) +for (i =0 ; i < conf->raid_disks; i++)if (!conf->mirrors[i].rdev || !test_bit (In_sync, &conf->mirrors[i].rdev->flags) ||test_bit (Faulty, &conf->mirrors[i].rdev->flags))
@@ -3067,8 +3069,8 @@ static int raid1_reshape(struct mddev *mddev) raid_disks = mddev->raid_disks + mddev->delta_disks;if (raid_disks < conf->raid_disks) { - cnt=0 ; -for (d=0 ; d < conf->raid_disks; d++) + cnt =0 ; +for (d =0 ; d < conf->raid_disks; d++)if (conf->mirrors[d].rdev) cnt++;if (cnt > raid_disks)
@@ -3139,7 +3141,7 @@ static void raid1_quiesce(struct mddev *mddev, int state) {struct r1conf *conf = mddev->private; -switch (state) { +switch (state) {case 2 :/* wake for suspend */ wake_up (&conf->wait_barrier);break ;
@@ -3172,24 +3174,24 @@ static void *raid1_takeover(struct mddev *mddev) }static struct md_personality raid1_personality = { - .name ="raid1" , - .level =1 , - .owner =THIS_MODULE , - .make_request = raid1_make_request, - .run = raid1_run, - .free = raid1_free, - .status = raid1_status, - .error_handler = raid1_error, - .hot_add_disk = raid1_add_disk, - .hot_remove_disk= raid1_remove_disk, - .spare_active = raid1_spare_active, - .sync_request = raid1_sync_request, - .resize = raid1_resize, - .size = raid1_size, - .check_reshape = raid1_reshape, - .quiesce = raid1_quiesce, - .takeover = raid1_takeover, - .congested = raid1_congested, + .name ="raid1" , + .level =1 , + .owner =THIS_MODULE , + .make_request = raid1_make_request, + .run = raid1_run, + .free = raid1_free, + .status = raid1_status, + .error_handler = raid1_error, + .hot_add_disk = raid1_add_disk, + .hot_remove_disk = raid1_remove_disk, + .spare_active = raid1_spare_active, + .sync_request = raid1_sync_request, + .resize = raid1_resize, + .size = raid1_size, + .check_reshape = raid1_reshape, + .quiesce = raid1_quiesce, + .takeover = raid1_takeover, + .congested = raid1_congested, };static int __init raid_init (void )
Signature · 1 line
2.10.1
PATCH 21/54 md/raid1: Delete three unwanted spaces behind asterisks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:01:34 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: "foo * bar" should be "foo *bar"
--- drivers/md/raid1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/raid1.c +3 -3
@@ -72,7 +72,7 @@ static void allow_barrier(struct r1conf *conf, sector_t start_next_window, sector_t bi_sector);static void lower_barrier (struct r1conf *conf); -static void *r1bio_pool_alloc (gfp_t gfp_flags,void *data) +static void *r1bio_pool_alloc (gfp_t gfp_flags,void *data) {struct pool_info *pi = data; int size = offsetof(struct r1bio, bios[pi->raid_disks]);
@@ -96,7 +96,7 @@ static void r1bio_pool_free(void *r1_bio, void *data)#define CLUSTER_RESYNC_WINDOW_SECTORS (CLUSTER_RESYNC_WINDOW >> 9)#define NEXT_NORMALIO_DISTANCE (3 * RESYNC_WINDOW_SECTORS) -static void *r1buf_pool_alloc (gfp_t gfp_flags,void *data) +static void *r1buf_pool_alloc (gfp_t gfp_flags,void *data) {struct pool_info *pi = data;struct r1bio *r1_bio;
@@ -1027,7 +1027,7 @@ static void raid1_unplug(struct blk_plug_cb *cb, bool from_schedule)kfree (plug); } -static void raid1_make_request (struct mddev *mddev,struct bio * bio) +static void raid1_make_request (struct mddev *mddev,struct bio *bio) {struct r1conf *conf = mddev->private;struct raid1_info *mirror;
Signature · 1 line
2.10.1
PATCH 22/54 md/raid1: Delete three unwanted spaces before increment operators
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:10:37 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: space prohibited before that '++' (ctx:WxO)
Thus fix the affected source code places.
--- drivers/md/raid1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/raid1.c +3 -3
@@ -220,7 +220,7 @@ static void reschedule_retry(struct r1bio *r1_bio)spin_lock_irqsave (&conf->device_lock, flags);list_add (&r1_bio->retry_list, &conf->retry_list); - conf->nr_queued ++; + conf->nr_queued++;spin_unlock_irqrestore (&conf->device_lock, flags);wake_up (&conf->wait_barrier);
@@ -1878,7 +1878,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio) } sectors -= s; sect += s; - idx ++; + idx++; }set_bit (R1BIO_Uptodate, &r1_bio->state); bio->bi_error =0 ;
@@ -2570,7 +2570,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr, }else if (!test_bit (In_sync, &rdev->flags)) {bio_set_op_attrs (bio,REQ_OP_WRITE ,0 ); bio->bi_end_io = end_sync_write; - write_targets ++; + write_targets++; }else {/* may need to read from here */ sector_t first_bad = MaxSector;
Signature · 1 line
2.10.1
PATCH 23/54 md/raid1: Replace a seq_printf() call by seq_puts() in raid1_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:16:13 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Prefer seq_puts to seq_printf
--- drivers/md/raid1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid1.c +1 -1
@@ -1417,7 +1417,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" ); }static void raid1_error (struct mddev *mddev,struct md_rdev *rdev)
Signature · 1 line
2.10.1
PATCH 24/54 md/raid1: Improve another size determination in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/raid1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid1.c +1 -1
@@ -2776,7 +2776,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)struct md_rdev *rdev;int err; - conf =kzalloc (sizeof (struct r1conf ),GFP_KERNEL ); + conf =kzalloc (sizeof (*conf),GFP_KERNEL );if (!conf)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.10.1
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200Replace 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.
Isn't this pure matter of taste?
Some developers prefer sizeof(*ptr) because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
Signature · 2 lines
Thanks, //richard
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
Quoted 5 lines · Richard Weinberger
Quoted 3 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200
Quoted 8 lines
Quoted 3 lines
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.
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr) is more future proof and normally more obvious and easier to review. That said, I've tried to tell Markus to only send bugfix patches because these are a waste of time and regularly introduce bugs.
regards,
dan carpenter
Richard Weinberger
maintainerRe: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
Quoted 10 lines · Dan Carpenter
Quoted 9 lines · Richard Weinberger
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200Replace 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.
Quoted 7 lines
Quoted 4 lines
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr)is more future proof and normally more obvious and easier to review.
Also a matter of taste.
See http://yarchive.net/comp/linux/struct_init.html
Thanks,
//richard
Re: md/raid1: Improve another size determination in setup_conf()
In reply to Dan CarpenterQuoted 11 lines
Quoted 8 lines
Quoted 3 lines
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.
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr)is more future proof and normally more obvious and easier to review.
Is it interesting to see how different the software development opinions can be for such an implementation detail?
Quoted 1 line
That said, I've tried to tell Markus to only send bugfix patches
Can any deviations from the Linux coding style become "bugs" also in your view of the software situation?
Quoted 1 line
because these are a waste of time
How do you value compliance with coding styles?
Quoted 1 line
and regularly introduce bugs.
Really?
Would you like to discuss concrete incidents any further?
Regards,
Markus
Richard Weinberger
maintainerRe: md/raid1: Improve another size determination in setup_conf()
Quoted 18 lines · SF Markus Elfring
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
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.
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr)is more future proof and normally more obvious and easier to review.Is it interesting to see how different the software development opinions can be for such an implementation detail?
Quoted 1 line
That said, I've tried to tell Markus to only send bugfix patches
Quoted 7 lines
Can any deviations from the Linux coding style become "bugs" also in your view of the software situation?
Quoted 1 line
because these are a waste of time
How do you value compliance with coding styles?
Just stop sending these kind of patches, *please*.
Linux has tons of issues, fixes for real problems are very welcome. But coding style bike shedding is just a waste of time.
Thanks,
//richard
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 1 line
Linux has tons of issues, fixes for real problems are very welcome.
Is a spectrum of software improvements to reconsider there?
Quoted 1 line
But coding style bike shedding is just a waste of time.
Why do various software developers bother about coding style specifications at all then?
Regards,
Markus
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 9 lines · SF Markus Elfring
Quoted 1 line
Linux has tons of issues, fixes for real problems are very welcome.
Is a spectrum of software improvements to reconsider there?
Quoted 1 line
But coding style bike shedding is just a waste of time.
Why do various software developers bother about coding style specifications at all then?
Coding style is important, but patches that just fix coding style are a bad thing because they break things like git blame and run the risk of introducing new bugs without any net benefit to end users. This goes double for code you don't actually work on regularly or don't completely understand.
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 3 lines
Quoted 2 lines
Why do various software developers bother about coding style specifications at all then?
Coding style is important,
Thanks that you "dare" to express also such an opinion.
Quoted 1 line
but patches that just fix coding style are a bad thing
When you find such a change opportunity so "bad", are there any circumstances left over where you would dare to touch the corresponding source code line.
Quoted 1 line
because they break things like
git blame
I follow your concern to some degree.
But can this argument evolve against a lot of changes generally?
Quoted 1 line
and run the risk of introducing new bugs
Did this really "happen" because of an update suggestion for this software module?
Quoted 1 line
without any net benefit to end users.
Can the proposed adjustment help to make a function like "setup_conf" a bit more robust (together with related update steps) so that an improved coding style compliance will hopefully influence the error probability in positive ways?
Quoted 2 lines
This goes double for code you don't actually work on regularly or don't completely understand.
How does such a kind of general feedback fit to the shown change possibilities in this patch series?
Do you reject this update step?
Regards,
Markus
Jiri Kosina
maintainerRe: md/raid1: Improve another size determination in setup_conf()
Quoted 5 lines · SF Markus Elfring
Quoted 1 line
but patches that just fix coding style are a bad thing
When you find such a change opportunity so "bad", are there any circumstances left over where you would dare to touch the corresponding source code line.
If you actually rewrite the code or fix some real bug there.
Quoted 5 lines
Quoted 1 line
because they break things like
git blameI follow your concern to some degree.
But can this argument evolve against a lot of changes generally?
If I have to reiterate git blame multiple times just because of whitespace or codingstyle changes, it's a pure waste of my time.
If I have to reiterate git blame multiple times to skip actual real changes, I have no other option than to live with that (because there was an actual functional reason for the change).
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
but patches that just fix coding style are a bad thing
When you find such a change opportunity so "bad", are there any circumstances left over where you would dare to touch the corresponding source code line.
If you actually rewrite the code or fix some real bug there.
Do the proposed update steps 12 - 16 for the function "setup_conf" (in this software module) fit to your condition?
Do you reject this update step?
Regards,
Markus
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 6 lines · SF Markus Elfring
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
but patches that just fix coding style are a bad thing
When you find such a change opportunity so "bad", are there any circumstances left over where you would dare to touch the corresponding source code line.
Quoted 6 lines
Quoted 1 line
If you actually rewrite the code or fix some real bug there.
Do the proposed update steps 12 - 16 for the function "
setup_conf" (in this software module) fit to your condition?Do you reject this update step?
I do - those changes do nothing to improve the code and simply hides a lot of history.
Jes
Re: md/raid1: Improve another size determination in setup_conf()
In reply to SF Markus ElfringQuoted 15 lines · SF Markus Elfring
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
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.
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr)is more future proof and normally more obvious and easier to review.Is it interesting to see how different the software development opinions can be for such an implementation detail?
Quoted 8 lines
Quoted 1 line
That said, I've tried to tell Markus to only send bugfix patches
Can any deviations from the Linux coding style become "bugs" also in your view of the software situation?
Quoted 1 line
because these are a waste of time
How do you value compliance with coding styles?
The Linux Coding Style is not a law, nor is it at all perfect. You clearly misunderstood how Linux development work and you are doing a great job wasting everyone's time with this patchset.
Jes
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 3 lines
Quoted 1 line
How do you value compliance with coding styles?
The Linux Coding Style is not a law,
How serious can such guidelines become for software developers?
Quoted 1 line
nor is it at all perfect.
I got a similar impression. But are there enough items where a mostly clear guidance is specified?
Quoted 1 line
You clearly misunderstood how Linux development work
I got an other impression.
Quoted 1 line
and you are doing a great job wasting everyone's time with this patchset.
Would you like to reject any update steps for the affected source files from this patch series?
Can it "accidentally" happen that some of them will be really worth also for your precious software development attention?
Regards,
Markus
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 15 lines · SF Markus Elfring
Quoted 3 lines
Quoted 1 line
How do you value compliance with coding styles?
The Linux Coding Style is not a law,
How serious can such guidelines become for software developers?
Quoted 1 line
nor is it at all perfect.
I got a similar impression. But are there enough items where a mostly clear guidance is specified?
Quoted 1 line
You clearly misunderstood how Linux development work
I got an other impression.
Quoted 7 lines
Quoted 1 line
and you are doing a great job wasting everyone's time with this patchset.
Would you like to reject any update steps for the affected source files from this patch series?
Can it "accidentally" happen that some of them will be really worth also for your precious software development attention?
Given that none of your patches fix any real bugs and you do your best to ignore any guidance you have been given, I do reject your entire patchset and you can consider this a NACK for this entire series.
I get the impression you obtain your response to any email from M-x doctor.
Jes
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 4 lines
Quoted 2 lines
Can it "accidentally" happen that some of them will be really worth also for your precious software development attention?
Given that none of your patches fix any real bugs
Are there any ones which would eventually become "real" also for you?
Quoted 1 line
and you do your best to ignore any guidance you have been given,
I dare occasionally to find reasons out for a specific disagreement.
Quoted 1 line
I do reject your entire patchset and you can consider this a NACK for this entire series.
Thanks for your feedback.
I am still curious if any other software developers or source code reviewers would dare to express an other opinion for one of the shown update possibilities.
Regards,
Markus
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
In reply to Dan CarpenterQuoted 10 lines · Dan Carpenter
Quoted 9 lines · Richard Weinberger
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200Replace 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.
Quoted 8 lines
Quoted 4 lines
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
sizeof(*ptr)is more future proof and normally more obvious and easier to review. That said, I've tried to tell Markus to only send bugfix patches because these are a waste of time and regularly introduce bugs.
This is totally a matter of taste. I for one find it way easier to review something which says 'sizeof(struct ....)' because it stands out more. I am curious what you mean by it being more future proof - if the code says 'struct foo' in the sizeof argument, what is the problem?
The one area where there is a higher risk is if the type is changed, but that is outweighed by the fact the spelled out version is easier to review.
Jes
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
Compare:
foo = kmalloc(sizeof(*foo), GFP_KERNEL);
This says you are allocating enough space for foo. It can be reviewed by looking at one line. If you change the type of foo it will still work.
foo = kmalloc(sizeof(struct whatever), GFP_KERNEL);
There isn't enough information to say if this is correct. If you change the type of foo then you have to update the allocation as well.
It's not a super common type of bug, but I see it occasionally.
regards,
dan carpenter
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
Quoted 8 lines · Dan Carpenter
Compare:
foo = kmalloc(sizeof(*foo), GFP_KERNEL);This says you are allocating enough space for foo. It can be reviewed by looking at one line. If you change the type of foo it will still work.
Quoted 6 lines
foo = kmalloc(sizeof(struct whatever), GFP_KERNEL);There isn't enough information to say if this is correct. If you change the type of foo then you have to update the allocation as well.
It's not a super common type of bug, but I see it occasionally.
I know what you are saying, but the latter in my book is easier to read and reminds you what the type is when you review the code.
Point being this comes down to personal preference and stating that the former is the right way or making that a rule and using checkpatch to harrass people with patches to change it is bogus.
Jes
Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
In reply to Richard WeinbergerQuoted 5 lines · Richard Weinberger
Quoted 3 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200
Quoted 9 lines
Quoted 3 lines
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.
Isn't this pure matter of taste?
Some developers prefersizeof(*ptr)because it is easier to type, other developers prefer sizeof(struct foo) because you can determine the type at first sight and makes review more easy.
I am ignoring Markus patches and have told him that he should focus on bug fixes. These patches don't add any value and regularly introduce bugs.
That said, "sizeof(*ptr)" is sort of official style. It's slightly more obvious and easier to review because all the information you need is on that one line. Also if we change the datatype of ptr then that format is slightly more future proof.
regards,
dan carpenter
Re: md/raid1: Improve another size determination in setup_conf()
Quoted 1 line
I am ignoring Markus patches
It's a pity that you chose such a reaction.
Quoted 1 line
and have told him that he should focus on bug fixes.
I find that I suggest to improve something. Could you admit a few times that I found a "bug" you care also about at other source code places?
Quoted 1 line
These patches don't add any value
Can it be that you express a lower value for the Linux coding style here than desired as there might be other concerns behind such negative feedback?
Quoted 1 line
and regularly introduce bugs.
How do you think about to discuss corresponding facts further?
Quoted 1 line
That said, "
sizeof(*ptr)" is sort of official style.
When this implementation detail is so official, I wonder then why some software developers can become "special" about the proposed update step like for this module.
Regards,
Markus
Re: md/raid1: Improve another size determination in setup_conf()
Hi Markus,
I'm mostly a lurker on this, sometimes trying to help out other users when I can. Either way, I'm not a kernel coder, so take my comments with a grain of salt...
Quoted 2 lines · SF Markus Elfring
Quoted 1 line
I am ignoring Markus patches
It's a pity that you chose such a reaction.
Different people will have different priorities, and that's OK.
Quoted 3 lines
Quoted 1 line
and have told him that he should focus on bug fixes.
I find that I suggest to improve something. Could you admit a few times that I found a "bug" you care also about at other source code places?
Different people will describe a bug differently. Has *any* of your patches been accepted on this list yet? Has *any* of them fixed a problem that a user encountered?
Quoted 3 lines
Quoted 1 line
These patches don't add any value
Can it be that you express a lower value for the Linux coding style here than desired as there might be other concerns behind such negative feedback?
Desired by who? Everyone is different. Sure, the coding style is there, and if you see a proposed patch which doesn't comply with the coding style, then advise everyone involved, and let's fix it before the patch goes in. After the code is already in, most people are more concerned with other things (different priorities and all)...
Quoted 2 lines
Quoted 1 line
and regularly introduce bugs.
How do you think about to discuss corresponding facts further?
You haven't proposed any facts.... These are just different priorities from different people...
Quoted 4 lines
Quoted 1 line
That said, "
sizeof(*ptr)" is sort of official style.When this implementation detail is so official, I wonder then why some software developers can become "special" about the proposed update step like for this module.
It's not special, like I said above, if there is a new patch proposed by someone which doesn't meet the coding guidelines, then speak up.....
The problem here is that you don't have a history of providing "useful" patches (ie, where other kernel developers can see that you have fixed something that was broken/not working). Currently, all they see is that you have run some tool over the code, and then thrown together 50 patches to change a bunch of code that doesn't really make any difference....
So, in short, I would guess you are beating a dead horse.Trying to create arguments over what is or is not right, better, or whatever is also nothing short of divisive and plain rude (whether intended or not). I would guess that if you had found one small style issue, and brought it up, explained that you were just starting out and found this code which doesn't meet the guidelines, you were confused about how it works, you think you understand now, but could it be changed to this which is easier to understand and matches the guidelines. Then it would probably have been accepted. You would probably then be tempted to go and find the other 200 similar patches, and we would be back at this spot, but hopefully, you might move onto finding and fixing "harder" problems rather than another 100 easy ones, and progressively your skills would improve, and everyone on the list would be delighted to receive your patches, and discuss them in detail.
Leave the other 100 easy patches to the next 100 people who come after you and need to start with an easy patch, before they progress toward the harder code/logic issues.
Like I said, I don't speak for anyone, and I myself don't like to see code with spelling/grammar mistakes, but with open source, while we can all help by submitting patches, "someone" needs to verify those patches, and so they must meet a certain usefulness criteria for them to "waste" their time on them.
PPS, deleted a bunch of CC's that didn't seem relevant, both lists and individuals....
Regards,
Adam
Bjørn Mork
maintainerRe: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()
In reply to Dan CarpenterQuoted 3 lines · Dan Carpenter
I am ignoring Markus patches and have told him that he should focus on bug fixes. These patches don't add any value and regularly introduce bugs.
I think there should be a big fat warning in CodingStyle:
THIS DOCUMENT DOES NOT APPLY TO ANY EXISTING KERNEL CODE.
Preserving existing style is more important than any minor style issue anyway. Style changes for the only purpose of style change should be considered harmful and destructive behaviour. You'd think that is bloody obvious, but evidently it isn't. Not only are the untested, buggy, churning patches still being submitted - some of them are even applied!
Adding such a statement will not prevent style changes, even changes to bring code more in line with CodingStyle, as long as the patches are part of some work of substance. E.g. cleaning up before fixing bugs. If you submit new code, then you can of course fix the style of any touched context.
Oh well, I can dream..
Bjørn
--
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 24/54] md/raid1: Improve another size determination in setup_conf()
In reply to Dan CarpenterOops. I sent this email twice. Sorry, about that.
regards,
dan carpenter
PATCH 25/54 md/raid5: Use kcalloc() in three functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:30:12 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
* Delete the local variable "size" which became unnecessary with this refactoring.
--- drivers/md/raid5.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/md/raid5.c +4 -9
@@ -2243,7 +2243,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)* is completely stalled, so now is a good time to resize * conf->disks and the scribble region */ - ndisks =kzalloc (newsize *sizeof (struct disk_info ),GFP_NOIO ); + ndisks =kcalloc (newsize,sizeof (*ndisks),GFP_NOIO );if (ndisks) {for (i=0 ; i<conf->raid_disks; i++) ndisks[i] = conf->disks[i];
@@ -6255,7 +6255,6 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt, struct r5worker_group **worker_groups) {int i, j, k; -ssize_t size;struct r5worker *workers; *worker_cnt_per_group = cnt;
@@ -6265,10 +6264,8 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,return 0 ; } *group_cnt =num_possible_nodes (); - size =sizeof (struct r5worker ) * cnt; - workers =kzalloc (size * *group_cnt,GFP_NOIO ); - *worker_groups =kzalloc (sizeof (struct r5worker_group ) * - *group_cnt,GFP_NOIO ); + workers =kcalloc (cnt * *group_cnt,sizeof (*workers),GFP_NOIO ); + *worker_groups =kcalloc (*group_cnt,sizeof (**worker_groups),GFP_NOIO );if (!*worker_groups || !workers) {kfree (workers);kfree (*worker_groups);
@@ -6519,9 +6516,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)else conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; max_disks =max (conf->raid_disks, conf->previous_raid_disks); - - conf->disks =kzalloc (max_disks *sizeof (struct disk_info ), -GFP_KERNEL ); + conf->disks =kcalloc (max_disks,sizeof (*conf->disks),GFP_KERNEL );if (!conf->disks) goto abort;
Signature · 1 line
2.10.1
PATCH 26/54 md/raid5: Improve another size determination in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:35:06 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/raid5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid5.c +1 -1
@@ -6481,7 +6481,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)return ERR_PTR (-EINVAL ); } - conf =kzalloc (sizeof (struct r5conf ),GFP_KERNEL ); + conf =kzalloc (sizeof (*conf),GFP_KERNEL );if (conf =NULL ) goto abort;/* Don't enable multi-threading by default*/
Signature · 1 line
2.10.1
PATCH 27/54 md/raid5: Return directly after a failed kzalloc() in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:44:59 +0200
* Return directly after a call of the function "kzalloc" failed at the beginning.
* Delete a repeated check for the local variable "conf" which became unnecessary with this refactoring.
--- drivers/md/raid5.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/md/raid5.c +4 -7
@@ -6482,8 +6482,8 @@ static struct r5conf *setup_conf(struct mddev *mddev) } conf =kzalloc (sizeof (*conf),GFP_KERNEL ); -if (conf =NULL ) - goto abort; +if (!conf) +return ERR_PTR (-ENOMEM );/* Don't enable multi-threading by default*/ if (!alloc_thread_groups (conf,0 , &group_cnt, &worker_cnt_per_group, &new_group)) {
@@ -6646,11 +6646,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)return conf; abort: -if (conf) { -free_conf (conf); -return ERR_PTR (-EIO ); - }else -return ERR_PTR (-ENOMEM ); +free_conf (conf); +return ERR_PTR (-EIO ); }static int only_parity (int raid_disk,int algo,int raid_disks,int max_degraded)
Signature · 1 line
2.10.1
PATCH 28/54 md/raid5: Rename a jump label in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 08:18:38 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/md/raid5.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/md/raid5.c +13 -12
@@ -6490,8 +6490,10 @@ static struct r5conf *setup_conf(struct mddev *mddev) conf->group_cnt = group_cnt; conf->worker_cnt_per_group = worker_cnt_per_group; conf->worker_groups = new_group; - }else - goto abort; + }else { + goto free_conf; + } +spin_lock_init (&conf->device_lock);seqcount_init (&conf->gen_lock);mutex_init (&conf->cache_size_mutex);
@@ -6518,12 +6520,12 @@ static struct r5conf *setup_conf(struct mddev *mddev) max_disks =max (conf->raid_disks, conf->previous_raid_disks); conf->disks =kcalloc (max_disks,sizeof (*conf->disks),GFP_KERNEL );if (!conf->disks) - goto abort; + goto free_conf; conf->mddev = mddev;if ((conf->stripe_hashtbl =kzalloc (PAGE_SIZE ,GFP_KERNEL )) =NULL ) - goto abort; + goto free_conf;/* We init hash_locks[0] separately to that it can be used * as the reference lock in the spin_lock_nest_lock() call
@@ -6543,7 +6545,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) conf->level = mddev->new_level; conf->chunk_sectors = mddev->new_chunk_sectors;if (raid5_alloc_percpu (conf) !=0 ) - goto abort; + goto free_conf;pr_debug ("raid456: run(%s) called.\n" ,mdname (mddev));
@@ -6556,11 +6558,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (test_bit (Replacement, &rdev->flags)) {if (disk->replacement) - goto abort; + goto free_conf; disk->replacement = rdev; }else {if (disk->rdev) - goto abort; + goto free_conf; disk->rdev = rdev; }
@@ -6613,7 +6615,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)printk (KERN_ERR "md/raid:%s: couldn't allocate %dkB for buffers\n" ,mdname (mddev), memory); - goto abort; + goto free_conf; }else printk (KERN_INFO "md/raid:%s: allocated %dkB\n" ,mdname (mddev), memory);
@@ -6631,7 +6633,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)printk (KERN_ERR "md/raid:%s: couldn't register shrinker.\n" ,mdname (mddev)); - goto abort; + goto free_conf; }sprintf (pers_name,"raid%d" , mddev->new_level);
@@ -6640,12 +6642,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)printk (KERN_ERR "md/raid:%s: couldn't allocate thread.\n" ,mdname (mddev)); - goto abort; + goto free_conf; }return conf; - - abort: +free_conf:free_conf (conf);return ERR_PTR (-EIO ); }
Signature · 1 line
2.10.1
PATCH 29/54 md/raid5: Return directly after a failed kcalloc() in alloc_thread_groups()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 08:54:40 +0200
The kfree() function was called in up to two cases by the alloc_thread_groups() function during error handling even if the passed variable contained a null pointer.
* Return directly after a call of the kcalloc() function failed at the beginning.
* Simplify a condition check for memory allocation failures.
--- drivers/md/raid5.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/md/raid5.c +4 -2
@@ -6265,10 +6265,12 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt, } *group_cnt =num_possible_nodes (); workers =kcalloc (cnt * *group_cnt,sizeof (*workers),GFP_NOIO ); +if (!workers) +return -ENOMEM ; + *worker_groups =kcalloc (*group_cnt,sizeof (**worker_groups),GFP_NOIO ); -if (!*worker_groups || !workers) { +if (!*worker_groups) {kfree (workers); -kfree (*worker_groups);return -ENOMEM ; }
Signature · 1 line
2.10.1
PATCH 30/54 md/raid5: Delete two error messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 09:43:40 +0200
Omit extra messages for a memory allocation failure in this function.
--- drivers/md/raid5.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/md/raid5.c +3 -10
@@ -6613,12 +6613,9 @@ static struct r5conf *setup_conf(struct mddev *mddev) memory = conf->min_nr_stripes * (sizeof (struct stripe_head ) + max_disks * ((sizeof (struct bio ) +PAGE_SIZE ))) /1024 ;atomic_set (&conf->empty_inactive_list_nr,NR_STRIPE_HASH_LOCKS ); -if (grow_stripes (conf, conf->min_nr_stripes)) { -printk (KERN_ERR -"md/raid:%s: couldn't allocate %dkB for buffers\n" , -mdname (mddev), memory); +if (grow_stripes (conf, conf->min_nr_stripes)) goto free_conf; - }else +else printk (KERN_INFO "md/raid:%s: allocated %dkB\n" ,mdname (mddev), memory);/*
@@ -6640,12 +6637,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)sprintf (pers_name,"raid%d" , mddev->new_level); conf->thread =md_register_thread (raid5d, mddev, pers_name); -if (!conf->thread) { -printk (KERN_ERR -"md/raid:%s: couldn't allocate thread.\n" , -mdname (mddev)); +if (!conf->thread) goto free_conf; - }return conf; free_conf:
Signature · 1 line
2.10.1
Re: [PATCH 30/54] md/raid5: Delete two error messages for a failed memory allocation
Quoted 36 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 09:43:40 +0200Omit extra messages for a memory allocation failure in this function.
Signed-off-by Markus Elfring <[email protected]>--- drivers/md/raid5.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/md/raid5.c +2
-5@@ -6613,12 +6613,9 @@ static struct r5conf *setup_conf(struct mddev *mddev) memory = conf->min_nr_stripes * (sizeof (struct stripe_head ) + max_disks * ((sizeof (struct bio ) +PAGE_SIZE ))) /1024 ;atomic_set (&conf->empty_inactive_list_nr,NR_STRIPE_HASH_LOCKS ); -if (grow_stripes (conf, conf->min_nr_stripes)) { -printk (KERN_ERR -"md/raid:%s: couldn't allocate %dkB for buffers\n" , -mdname (mddev), memory); +if (grow_stripes (conf, conf->min_nr_stripes)) goto free_conf; - }else +else printk (KERN_INFO "md/raid:%s: allocated %dkB\n" ,mdname (mddev), memory);/* @@ -6640,12 +6637,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)sprintf (pers_name,"raid%d" , mddev->new_level); conf->thread =md_register_thread (raid5d, mddev, pers_name);
drivers/md/raid5.c static struct r5conf *setup_conf(struct mddev *mddev) · line 6644
Quoted 10 lines
drivers/md/raid5.c +1
-5-if (!conf->thread) { -printk (KERN_ERR -"md/raid:%s: couldn't allocate thread.\n" , -mdname (mddev)); +if (!conf->thread) goto free_conf; - }return conf; free_conf:
Actually I prefer having error messages, especially if you have several possible failures all leading to the same return value. Without it debugging becomes really hard.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 31/54 md/raid5: Adjust two function calls together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 10:00:07 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
--- drivers/md/raid5.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/raid5.c +4 -5
@@ -501,11 +501,10 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)int num = sh->raid_conf->pool_size;for (i =0 ; i < num; i++) { -struct page *page; +struct page *page =alloc_page (gfp); -if (!(page =alloc_page (gfp))) { +if (!page)return 1 ; - } sh->dev[i].page = page; sh->dev[i].orig_page = page; }
@@ -6525,8 +6524,8 @@ static struct r5conf *setup_conf(struct mddev *mddev) goto free_conf; conf->mddev = mddev; - -if ((conf->stripe_hashtbl =kzalloc (PAGE_SIZE ,GFP_KERNEL )) =NULL ) + conf->stripe_hashtbl =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!conf->stripe_hashtbl) goto free_conf;/* We init hash_locks[0] separately to that it can be used
Signature · 1 line
2.10.1
PATCH 32/54 md/raid5: Move a brace for three designated initialisers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 10:20:05 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/raid5.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/md/raid5.c +3 -4
@@ -7868,8 +7868,7 @@ static void *raid6_takeover(struct mddev *mddev)return setup_conf (mddev); } -static struct md_personality raid6_personality -{ +static struct md_personality raid6_personality = { .name ="raid6" , .level =6 , .owner =THIS_MODULE ,
@@ -7891,8 +7890,7 @@ static struct md_personality raid6_personality .takeover = raid6_takeover, .congested = raid5_congested, }; -static struct md_personality raid5_personality -{ +static struct md_personality raid5_personality = { .name ="raid5" , .level =5 , .owner =THIS_MODULE ,
@@ -7914,9 +7912,7 @@ static struct md_personality raid5_personality .takeover = raid5_takeover, .congested = raid5_congested, }; - -static struct md_personality raid4_personality -{ +static struct md_personality raid4_personality = { .name ="raid4" , .level =4 , .owner =THIS_MODULE ,
Signature · 1 line
2.10.1
PATCH 33/54 md/raid5: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 13:40:03 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
--- drivers/md/raid5.c | 215 ++++++++++++++++++++++++----------------------------- 1 file changed, 96 insertions(+), 119 deletions(-)
drivers/md/raid5.c +96 -119
@@ -43,6 +43,8 @@* miss any bits. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/blkdev.h> #include <linux/kthread.h> #include <linux/raid/pq.h>
@@ -540,7 +542,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)if (dev->toread || dev->read || dev->towrite || dev->written ||test_bit (R5_LOCKED , &dev->flags)) { -printk (KERN_ERR "sector=%llx i=%d %p %p %p %p %d\n" , +pr_err ("sector=%llx i=%d %p %p %p %p %d\n" , (unsigned long long )sh->sector, i, dev->toread, dev->read, dev->towrite, dev->written,test_bit (R5_LOCKED , &dev->flags));
@@ -2346,13 +2348,12 @@ static void raid5_end_read_request(struct bio * bi)* replacement device. We just fail those on * any error */ -printk_ratelimited ( -KERN_INFO -"md/raid:%s: read error corrected" -" (%lu sectors at %llu on %s)\n" , -mdname (conf->mddev),STRIPE_SECTORS , - (unsigned long long )s, -bdevname (rdev->bdev, b)); +pr_info_ratelimited ("%s: read error corrected (" +"%lu sectors at %llu on %s)\n" , +mdname (conf->mddev), +STRIPE_SECTORS , + (unsigned long long )s, +bdevname (rdev->bdev, b));atomic_add (STRIPE_SECTORS , &rdev->corrected_errors);clear_bit (R5_ReadError, &sh->dev[i].flags);clear_bit (R5_ReWrite, &sh->dev[i].flags);
@@ -2369,37 +2370,27 @@ static void raid5_end_read_request(struct bio * bi)clear_bit (R5_UPTODATE , &sh->dev[i].flags);atomic_inc (&rdev->read_errors);if (test_bit (R5_ReadRepl, &sh->dev[i].flags)) -printk_ratelimited ( -KERN_WARNING -"md/raid:%s: read error on replacement device " -"(sector %llu on %s).\n" , -mdname (conf->mddev), - (unsigned long long )s, - bdn); +pr_warn_ratelimited ("%s: read error on replacement device (sector %llu on %s).\n" , +mdname (conf->mddev), + (unsigned long long )s, + bdn);else if (conf->mddev->degraded >= conf->max_degraded) { set_bad =1 ; -printk_ratelimited ( -KERN_WARNING -"md/raid:%s: read error not correctable " -"(sector %llu on %s).\n" , -mdname (conf->mddev), - (unsigned long long )s, - bdn); +pr_warn_ratelimited ("%s: read error not correctable (sector %llu on %s).\n" , +mdname (conf->mddev), + (unsigned long long )s, + bdn); }else if (test_bit (R5_ReWrite, &sh->dev[i].flags)) {/* Oh, no!!! */ set_bad =1 ; -printk_ratelimited ( -KERN_WARNING -"md/raid:%s: read error NOT corrected!! " -"(sector %llu on %s).\n" , -mdname (conf->mddev), - (unsigned long long )s, - bdn); +pr_warn_ratelimited ("%s: read error NOT corrected! (sector %llu on %s).\n" , +mdname (conf->mddev), + (unsigned long long )s, + bdn); }else if (atomic_read (&rdev->read_errors) > conf->max_nr_stripes) -printk (KERN_WARNING -"md/raid:%s: Too many read errors, failing device %s.\n" , -mdname (conf->mddev), bdn); +pr_warn ("%s: Too many read errors, failing device %s.\n" , +mdname (conf->mddev), bdn);else retry =1 ; if (set_bad && test_bit(In_sync, &rdev->flags)
@@ -2532,13 +2523,12 @@ static void raid5_error(struct mddev *mddev, struct md_rdev *rdev)set_bit (Faulty, &rdev->flags);set_mask_bits (&mddev->flags,0 ,BIT (MD_CHANGE_DEVS ) |BIT (MD_CHANGE_PENDING )); -printk (KERN_ALERT -"md/raid:%s: Disk failure on %s, disabling device.\n" -"md/raid:%s: Operation continuing on %d devices.\n" , -mdname (mddev), -bdevname (rdev->bdev, b), -mdname (mddev), - conf->raid_disks - mddev->degraded); +pr_alert ("%s: Disk failure on %s, disabling device.\n" +MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n" , +mdname (mddev), +bdevname (rdev->bdev, b), +mdname (mddev), + conf->raid_disks - mddev->degraded); }/*
@@ -2860,7 +2850,7 @@ sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous) previous, &dummy1, &sh2);if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx || sh2.qd_idx != sh->qd_idx) { -printk (KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n" , +pr_err ("%s: compute_blocknr: map not correct\n" ,mdname (conf->mddev));return 0 ; }
@@ -3781,7 +3771,7 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,case check_state_compute_run:break ;default : -printk (KERN_ERR "%s: unknown check_state: %d sector: %llu\n" , +pr_err ("%s: unknown check_state: %d sector: %llu\n" , __func__, sh->check_state, (unsigned long long ) sh->sector);BUG ();
@@ -3945,7 +3935,7 @@ static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,case check_state_compute_run:break ;default : -printk (KERN_ERR "%s: unknown check_state: %d sector: %llu\n" , +pr_err ("%s: unknown check_state: %d sector: %llu\n" , __func__, sh->check_state, (unsigned long long ) sh->sector);BUG ();
@@ -6456,7 +6446,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (mddev->new_level !=5 && mddev->new_level !=4 && mddev->new_level !=6 ) { -printk (KERN_ERR "md/raid:%s: raid level not set to 4/5/6 (%d)\n" , +pr_err ("%s: raid level not set to 4/5/6 (%d)\n" ,mdname (mddev), mddev->new_level);return ERR_PTR (-EIO ); }
@@ -6464,12 +6454,12 @@ static struct r5conf *setup_conf(struct mddev *mddev) && !algorithm_valid_raid5(mddev->new_layout)) || (mddev->new_level = 6 && !algorithm_valid_raid6(mddev->new_layout))) { -printk (KERN_ERR "md/raid:%s: layout %d not supported\n" , +pr_err ("%s: layout %d not supported\n" ,mdname (mddev), mddev->new_layout);return ERR_PTR (-EIO ); }if (mddev->new_level =6 && mddev->raid_disks <4 ) { -printk (KERN_ERR "md/raid:%s: not enough configured devices (%d, minimum 4)\n" , +pr_err ("%s: not enough configured devices (%d, minimum 4)\n" ,mdname (mddev), mddev->raid_disks);return ERR_PTR (-EINVAL ); }
@@ -6477,7 +6467,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (!mddev->new_chunk_sectors || (mddev->new_chunk_sectors <<9 ) %PAGE_SIZE || !is_power_of_2 (mddev->new_chunk_sectors)) { -printk (KERN_ERR "md/raid:%s: invalid chunk size %d\n" , +pr_err ("%s: invalid chunk size %d\n" ,mdname (mddev), mddev->new_chunk_sectors <<9 );return ERR_PTR (-EINVAL ); }
@@ -6569,8 +6559,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (test_bit (In_sync, &rdev->flags)) {char b[BDEVNAME_SIZE ]; -printk (KERN_INFO "md/raid:%s: device %s operational as raid" -" disk %d\n" , +pr_info ("%s: device %s operational as raid disk %d\n" ,mdname (mddev),bdevname (rdev->bdev, b), raid_disk); }else if (rdev->saved_raid_disk != raid_disk)/* Cannot rely on bitmap to complete recovery */
@@ -6605,8 +6594,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4); conf->min_nr_stripes =max (NR_STRIPES , stripes);if (conf->min_nr_stripes !=NR_STRIPES ) -printk (KERN_INFO -"md/raid:%s: force stripe size %d for reshape\n" , +pr_info ("%s: force stripe size %d for reshape\n" ,mdname (mddev), conf->min_nr_stripes); } memory = conf->min_nr_stripes * (sizeof(struct stripe_head) +
@@ -6615,8 +6603,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (grow_stripes (conf, conf->min_nr_stripes)) goto free_conf;else -printk (KERN_INFO "md/raid:%s: allocated %dkB\n" , -mdname (mddev), memory); +pr_info ("%s: allocated %dkB\n" ,mdname (mddev), memory);/* * Losing a stripe head costs more than the time to refill it, * it reduces the queue depth and so can hurt throughput.
@@ -6628,9 +6615,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) conf->shrinker.batch =128 ; conf->shrinker.flags =0 ;if (register_shrinker (&conf->shrinker)) { -printk (KERN_ERR -"md/raid:%s: couldn't register shrinker.\n" , -mdname (mddev)); +pr_err ("%s: couldn't register shrinker.\n" ,mdname (mddev)); goto free_conf; }
@@ -6684,9 +6669,8 @@ static int raid5_run(struct mddev *mddev)int first =1 ;if (mddev->recovery_cp != MaxSector) -printk (KERN_NOTICE "md/raid:%s: not clean" -" -- starting background reconstruction\n" , -mdname (mddev)); +pr_notice ("%s: not clean - starting background reconstruction\n" , +mdname (mddev));rdev_for_each (rdev, mddev) {long long diff;
@@ -6729,15 +6713,14 @@ static int raid5_run(struct mddev *mddev)int new_data_disks;if (journal_dev) { -printk (KERN_ERR "md/raid:%s: don't support reshape with journal - aborting.\n" , -mdname (mddev)); +pr_err ("%s: don't support reshape with journal%s" , +mdname (mddev)," - aborting.\n" );return -EINVAL ; }if (mddev->new_level != mddev->level) { -printk (KERN_ERR "md/raid:%s: unsupported reshape " -"required - aborting.\n" , -mdname (mddev)); +pr_err ("%s: unsupported reshape required%s" , +mdname (mddev)," - aborting.\n" );return -EINVAL ; } old_disks = mddev->raid_disks - mddev->delta_disks;
@@ -6752,8 +6735,8 @@ static int raid5_run(struct mddev *mddev) chunk_sectors =max (mddev->chunk_sectors, mddev->new_chunk_sectors); new_data_disks = mddev->raid_disks - max_degraded;if (sector_div (here_new, chunk_sectors * new_data_disks)) { -printk (KERN_ERR "md/raid:%s: reshape_position not " -"on a stripe boundary\n" ,mdname (mddev)); +pr_err ("%s: reshape_position not on a stripe boundary\n" , +mdname (mddev));return -EINVAL ; } reshape_offset = here_new * chunk_sectors;
@@ -6774,10 +6757,8 @@ static int raid5_run(struct mddev *mddev) abs(min_offset_diff) >= mddev->new_chunk_sectors)/* not really in-place - so OK */ ; else if (mddev->ro = 0) { -printk (KERN_ERR "md/raid:%s: in-place reshape " -"must be started in read-only mode " -"- aborting\n" , - mdname(mddev)); +pr_err ("%s: in-place reshape must be started in read-only mode%s" , + mdname(mddev), " - aborting.\n");return -EINVAL ; } } else if (mddev->reshape_backwards
@@ -6786,13 +6767,11 @@ static int raid5_run(struct mddev *mddev) : (here_new * chunk_sectors > here_old * chunk_sectors + (-min_offset_diff))) {/* Reading from the same stripe as writing to - bad */ -printk (KERN_ERR "md/raid:%s: reshape_position too early for " -"auto-recovery - aborting.\n" , -mdname (mddev)); +pr_err ("%s: reshape_position too early for auto-recovery%s" , +mdname (mddev)," - aborting.\n" );return -EINVAL ; } -printk (KERN_INFO "md/raid:%s: reshape will continue\n" , -mdname (mddev)); +pr_info ("%s: reshape will continue\n" ,mdname (mddev));/* OK, we should be able to continue; */ }else {BUG_ON (mddev->level != mddev->new_level);
@@ -6811,7 +6790,7 @@ static int raid5_run(struct mddev *mddev)if (test_bit (MD_HAS_JOURNAL , &mddev->flags)) {if (!journal_dev) { -pr_err ("md/raid:%s: journal disk is missing, force array readonly\n" , +pr_err ("%s: journal disk is missing, force array readonly\n" ,mdname (mddev)); mddev->ro =1 ;set_disk_ro (mddev->gendisk,1 );
@@ -6839,8 +6818,7 @@ static int raid5_run(struct mddev *mddev)if (conf->disks[i].replacement && conf->reshape_progress != MaxSector) {/* replacements and reshape simply do not mix. */ -printk (KERN_ERR "md: cannot handle concurrent " -"replacement and reshape.\n" ); +pr_err ("cannot handle concurrent replacement and reshape.\n" ); goto abort; }if (test_bit (In_sync, &rdev->flags)) {
@@ -6882,9 +6860,8 @@ static int raid5_run(struct mddev *mddev) mddev->degraded =calc_degraded (conf);if (has_failed (conf)) { -printk (KERN_ERR "md/raid:%s: not enough operational devices" -" (%d/%d failed)\n" , -mdname (mddev), mddev->degraded, conf->raid_disks); +pr_err ("%s: not enough operational devices (%d/%d failed)\n" , +mdname (mddev), mddev->degraded, conf->raid_disks); goto abort; }
@@ -6894,30 +6871,30 @@ static int raid5_run(struct mddev *mddev)if (mddev->degraded > dirty_parity_disks && mddev->recovery_cp != MaxSector) { -if (mddev->ok_start_degraded) -printk (KERN_WARNING -"md/raid:%s: starting dirty degraded array" -" - data corruption possible.\n" , -mdname (mddev)); -else { -printk (KERN_ERR -"md/raid:%s: cannot start dirty degraded array.\n" , +if (mddev->ok_start_degraded) { +pr_warn ("%s: starting dirty degraded array - data corruption possible.\n" , +mdname (mddev)); + }else { +pr_err ("%s: cannot start dirty degraded array.\n" ,mdname (mddev)); goto abort; } }if (mddev->degraded =0 ) -printk (KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" -" devices, algorithm %d\n" ,mdname (mddev), conf->level, - mddev->raid_disks-mddev->degraded, mddev->raid_disks, - mddev->new_layout); +pr_info ("%s: raid level %d active with %d out of %d devices, algorithm %d\n" , +mdname (mddev), + conf->level, + mddev->raid_disks-mddev->degraded, + mddev->raid_disks, + mddev->new_layout);else -printk (KERN_ALERT "md/raid:%s: raid level %d active with %d" -" out of %d devices, algorithm %d\n" , -mdname (mddev), conf->level, - mddev->raid_disks - mddev->degraded, - mddev->raid_disks, mddev->new_layout); +pr_alert ("%s: raid level %d active with %d out of %d devices, algorithm %d\n" , +mdname (mddev), + conf->level, + mddev->raid_disks - mddev->degraded, + mddev->raid_disks, + mddev->new_layout);print_raid5_conf (conf);
@@ -6937,9 +6914,8 @@ static int raid5_run(struct mddev *mddev) mddev->to_remove =NULL ; else if (mddev->kobj.sd && sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) - printk(KERN_WARNING -"raid5: failed to create sysfs attributes for %s\n" , - mdname(mddev)); + pr_warn("failed to create sysfs attributes for %s\n", + mdname(mddev));md_set_array_sectors (mddev,raid5_size (mddev,0 ,0 ));if (mddev->queue) {
@@ -7027,8 +7003,8 @@ static int raid5_run(struct mddev *mddev)if (journal_dev) {char b[BDEVNAME_SIZE ]; -printk (KERN_INFO "md/raid:%s: using device %s as journal\n" , -mdname (mddev),bdevname (journal_dev->bdev, b)); +pr_info ("%s: using device %s as journal\n" , +mdname (mddev),bdevname (journal_dev->bdev, b));r5l_init_log (conf, journal_dev); }
@@ -7038,7 +7014,7 @@ static int raid5_run(struct mddev *mddev)print_raid5_conf (conf);free_conf (conf); mddev->private =NULL ; -printk (KERN_ALERT "md/raid:%s: failed to run raid set.\n" ,mdname (mddev)); +pr_alert ("%s: failed to run raid set.\n" ,mdname (mddev));return -EIO ; }
@@ -7072,22 +7048,23 @@ static void print_raid5_conf (struct r5conf *conf)int i;struct disk_info *tmp; -printk (KERN_DEBUG "RAID conf printout:\n" ); +pr_debug ("conf printout:\n" );if (!conf) { -printk ("(conf=NULL)\n" ); +pr_debug ("(conf=NULL)\n" );return ; } -printk (KERN_DEBUG " --- level:%d rd:%d wd:%d\n" , conf->level, - conf->raid_disks, - conf->raid_disks - conf->mddev->degraded); +pr_debug ("--- level:%d rd:%d wd:%d\n" , + conf->level, + conf->raid_disks, + conf->raid_disks - conf->mddev->degraded);for (i =0 ; i < conf->raid_disks; i++) {char b[BDEVNAME_SIZE ]; tmp = conf->disks + i;if (tmp->rdev) -printk (KERN_DEBUG " disk %d, o:%d, dev:%s\n" , - i, !test_bit (Faulty, &tmp->rdev->flags), -bdevname (tmp->rdev->bdev, b)); +pr_debug ("disk %d, o:%d, dev:%s\n" , + i, !test_bit (Faulty, &tmp->rdev->flags), +bdevname (tmp->rdev->bdev, b)); } }
@@ -7233,8 +7210,8 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)* write requests running. We should be safe */ r5l_init_log (conf, rdev); -printk (KERN_INFO "md/raid:%s: using device %s as journal\n" , -mdname (mddev),bdevname (rdev->bdev, b)); +pr_info ("%s: using device %s as journal\n" , +mdname (mddev),bdevname (rdev->bdev, b));return 0 ; }if (mddev->recovery_disabled = conf->recovery_disabled)
@@ -7338,9 +7315,9 @@ static int check_stripe_cache(struct mddev *mddev) > conf->min_nr_stripes || ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 > conf->min_nr_stripes) { -printk (KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n" , -mdname (mddev), - ((max (mddev->chunk_sectors, mddev->new_chunk_sectors) <<9 ) +pr_warn ("%s: reshape: not enough stripes. Needed %lu\n" , +mdname (mddev), + ((max (mddev->chunk_sectors, mddev->new_chunk_sectors) <<9 ) /STRIPE_SIZE )*4 );return 0 ; }
@@ -7422,8 +7399,8 @@ static int raid5_start_reshape(struct mddev *mddev)*/ if (raid5_size (mddev,0 , conf->raid_disks + mddev->delta_disks) < mddev->array_sectors) { -printk (KERN_ERR "md/raid:%s: array size must be reduced " -"before number of disks\n" ,mdname (mddev)); +pr_err ("%s: array size must be reduced before number of disks\n" , +mdname (mddev));return -EINVAL ; }
@@ -7641,7 +7618,7 @@ static void *raid45_takeover_raid0(struct mddev *mddev, int level)/* for raid0 takeover only one zone is supported */ if (raid0_conf->nr_strip_zones >1 ) { -printk (KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n" , +pr_err ("%s: cannot takeover raid0 with more than one zone.\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }
Signature · 1 line
2.10.1
PATCH 34/54 md/raid5: Delete indentation for two jump labels
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 13:45:18 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: labels should not be indented
Thus fix the affected source code places.
--- drivers/md/raid5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid5.c +2 -2
@@ -5089,7 +5089,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi) logical_sector += STRIPE_SECTORS) {DEFINE_WAIT (w);int d; - again: +again: sh =raid5_get_active_stripe (conf, logical_sector,0 ,0 ,0 );prepare_to_wait (&conf->wait_for_overlap, &w,TASK_UNINTERRUPTIBLE );
@@ -5204,7 +5204,7 @@ static void raid5_make_request(struct mddev *mddev, struct bio * bi)int seq; do_prepare = false; - retry: +retry: seq =read_seqcount_begin (&conf->gen_lock); previous =0 ;if (do_prepare)
Signature · 1 line
2.10.1
PATCH 35/54 md/raid5: Adjust 13 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:07:49 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/md/raid5.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/md/raid5.c +13 -14
@@ -679,7 +679,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,set_bit (R5_ALLOC_MORE , &conf->cache_state); } -if (noblock && sh =NULL ) +if (noblock && !sh)break ;if (!sh) { set_bit(R5_INACTIVE_BLOCKED,
@@ -719,7 +719,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,atomic_inc (&sh->count);spin_unlock (&conf->device_lock); } - }while (sh =NULL ); + }while (!sh);spin_unlock_irq (conf->hash_locks + hash);return sh;
@@ -2260,7 +2260,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)list_del_init (&nsh->lru);for (i=conf->raid_disks; i < newsize; i++) -if (nsh->dev[i].page =NULL ) { +if (!nsh->dev[i].page) {struct page *p =alloc_page (GFP_NOIO ); nsh->dev[i].page = p; nsh->dev[i].orig_page = p;
@@ -2977,7 +2977,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, goto overlap;if (forwrite) { bip = &sh->dev[dd_idx].towrite; -if (*bip =NULL ) +if (!*bip) firstwrite =1 ; }else bip = &sh->dev[dd_idx].toread;
@@ -3962,7 +3962,7 @@ static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh)sector_t s =raid5_compute_sector (conf, bn,0 , &dd_idx,NULL ); sh2 =raid5_get_active_stripe (conf, s,0 ,1 ,1 ); -if (sh2 =NULL ) +if (!sh2)/* so far only the early blocks of this stripe * have been requested. When later blocks * get requested, we will try again
@@ -4094,7 +4094,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)if (rdev) { is_bad =is_badblock (rdev, sh->sector,STRIPE_SECTORS , &first_bad, &bad_sectors); -if (s->blocked_rdev =NULL +if (!s->blocked_rdev && (test_bit (Blocked, &rdev->flags) || is_bad <0 )) {if (is_bad <0 )
@@ -5044,8 +5044,7 @@ static void release_stripe_plug(struct mddev *mddev, } cb = container_of(blk_cb, struct raid5_plug_cb, cb); - -if (cb->list.next =NULL ) { +if (!cb->list.next) {int i;INIT_LIST_HEAD (&cb->list);for (i =0 ; i <NR_STRIPE_HASH_LOCKS ; i++)
@@ -5653,7 +5652,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_nbitmap_cond_end_sync (mddev->bitmap, sector_nr, false); sh =raid5_get_active_stripe (conf, sector_nr,0 ,1 ,0 ); -if (sh =NULL ) { +if (!sh) { sh =raid5_get_active_stripe (conf, sector_nr,0 ,0 ,0 );/* make sure we don't swamp the stripe cache if someone else * is trying to get access
@@ -5668,7 +5667,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_nfor (i =0 ; i < conf->raid_disks; i++) {struct md_rdev *rdev =ACCESS_ONCE (conf->disks[i].rdev); -if (rdev =NULL ||test_bit (Faulty, &rdev->flags)) +if (!rdev ||test_bit (Faulty, &rdev->flags)) still_degraded =1 ; }rcu_read_unlock ();
@@ -6780,7 +6779,7 @@ static int raid5_run(struct mddev *mddev)BUG_ON (mddev->delta_disks !=0 ); } -if (mddev->private =NULL ) +if (!mddev->private) conf =setup_conf (mddev);else conf = mddev->private;
@@ -7230,12 +7229,12 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)*/ if (rdev->saved_raid_disk >=0 && rdev->saved_raid_disk >= first && - conf->disks[rdev->saved_raid_disk].rdev =NULL ) + !conf->disks[rdev->saved_raid_disk].rdev) first = rdev->saved_raid_disk;for (disk = first; disk <= last; disk++) { p = conf->disks + disk; -if (p->rdev =NULL ) { +if (!p->rdev) {clear_bit (In_sync, &rdev->flags); rdev->raid_disk = disk; err =0 ;
@@ -7248,7 +7247,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)for (disk = first; disk <= last; disk++) { p = conf->disks + disk;if (test_bit (WantReplacement, &p->rdev->flags) && - p->replacement =NULL ) { + !p->replacement) {clear_bit (In_sync, &rdev->flags);set_bit (Replacement, &rdev->flags); rdev->raid_disk = disk;
Signature · 6 lines
2.10.1 -- 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 36/54 md/raid5: Delete four unwanted spaces behind function names
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:37:17 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: space prohibited between function name and open parenthesis '('
Thus fix the affected source code places.
--- drivers/md/raid5.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/md/raid5.c +9 -4
@@ -236,7 +236,7 @@ static void return_io(struct bio_list *return_bi) } } -static void print_raid5_conf (struct r5conf *conf); +static void print_raid5_conf (struct r5conf *conf);static int stripe_operations_active (struct stripe_head *sh) {
@@ -7032,17 +7032,22 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq," level %d, %dk chunk, algorithm %d" , mddev->level, conf->chunk_sectors /2 , mddev->layout); -seq_printf (seq," [%d/%d] [" , conf->raid_disks, conf->raid_disks - mddev->degraded); +seq_printf (seq, +" [%d/%d] [" , + conf->raid_disks, + conf->raid_disks - mddev->degraded);rcu_read_lock ();for (i =0 ; i < conf->raid_disks; i++) {struct md_rdev *rdev =rcu_dereference (conf->disks[i].rdev); -seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); +seq_printf (seq, +"%s" , + rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock ();seq_printf (seq,"]" ); } -static void print_raid5_conf (struct r5conf *conf) +static void print_raid5_conf (struct r5conf *conf) {int i;struct disk_info *tmp;
Signature · 1 line
2.10.1
PATCH 37/54 md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:40:27 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Prefer seq_puts to seq_printf
--- drivers/md/raid5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid5.c +1 -1
@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" ); }static void print_raid5_conf (struct r5conf *conf)
Signature · 1 line
2.10.1
Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
drivers/md/raid5.c
Quoted 1 line · SF Markus Elfring
drivers/md/raid5.c +0
-0
[]
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7047
Quoted 6 lines
drivers/md/raid5.c +1
-1@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" );
seq_putc
Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
Quoted 10 lines
drivers/md/raid5.c
Quoted 1 line
drivers/md/raid5.c +0
-0[]
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7047
Quoted 6 lines
drivers/md/raid5.c +1
-1@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" );
seq_putc
Thanks for your update suggestion.
How do you think about the possibility that the script "checkpatch.pl" can also point such a source code transformation out directly?
Would an additional check for the length of the passed string be useful in similar use cases?
Regards,
Markus
Joe Perches
maintainerRe: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
Quoted 11 lines · SF Markus Elfring
Quoted 9 lines
drivers/md/raid5.c
Quoted 1 line
drivers/md/raid5.c +0
-0[]
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7047
Quoted 6 lines
drivers/md/raid5.c +1
-1@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); } rcu_read_unlock(); -seq_printf (seq,"]" ); +seq_puts (seq,"]" );
seq_putcHow do you think about the possibility that the script "checkpatch.pl" can also point such a source code transformation out directly?
Why don't _you_ try to implement that in checkpatch instead?
--
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 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/md/raid5.c
Quoted 1 line
drivers/md/raid5.c +0
-0[]
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7047
Quoted 6 lines
drivers/md/raid5.c +1
-1@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" );
seq_putc
Quoted 4 lines
Quoted 2 lines
How do you think about the possibility that the script "checkpatch.pl" can also point such a source code transformation out directly?
Why don't _you_ try to implement that in checkpatch instead?
How are the chances that any other software developer would be quicker (than me) for such an addition because of more practical knowledge for the programming language "Perl"?
Regards,
Markus
Joe Perches
maintainerRe: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
Quoted 3 lines · SF Markus Elfring
Quoted 1 line
Why don't _you_ try to implement that in checkpatch instead?
How are the chances that any other software developer would be quicker (than me) for such an addition because of more practical knowledge for the programming language "Perl"?
Extremely high.
What are the chances you can add useful attributes to your skilz?
Re: md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Why don't _you_ try to implement that in checkpatch instead?
How are the chances that any other software developer would be quicker (than me) for such an addition because of more practical knowledge for the programming language "Perl"?
Extremely high.
Thanks for this feedback.
Quoted 1 line
What are the chances you can add useful attributes to your skilz?
Unfortunately, "Perl" does not belong to a favourite in my current collection of programming languages I learned through my software development activities. I imagine that I would prefer to improve other Linux software modules for a while instead?
Would it be interesting if the Coccinelle software could help a bit more with corresponding semantic patches?
Regards,
Markus
Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
In reply to SF Markus ElfringHi all!
Quoted 16 lines · SF Markus Elfring
Quoted 16 lines
drivers/md/raid5.c +0
-0Quoted 14 lines
Quoted 11 lines
[]
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7047
Quoted 9 lines
(quoted diff) +0
-0@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)rdev && test_bit(In_sync, &rdev-
Quoted 1 line
flags) ? "U" : "_");
}
rcu_read_unlock();drivers/md/raid5.c +1
-1-seq_printf (seq,"]" ); +seq_puts (seq,"]" );
seq_putcHow do you think about the possibility that the script "checkpatch.pl" can also point
such a source code transformation out directly?
Quoted 6 lines
Quoted 1 line
Why don't _you_ try to implement that in checkpatch instead?
How are the chances that any other software developer would be quicker (than me) for such
an addition because of more practical knowledge for the programming language "Perl"?
The above is BTW a pretty simple thing and thus good for a learning experience for regular expressions and copy-pasting a few lines in that perl-script and editing them.
MfG,
Bernd
PS: Sry for the noise - it's somewhat OT here ....
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
PATCH 1/1 MD-RAID: Use seq_putc() in three status functions
In reply to Joe PerchesFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Oct 2016 10:10:28 +0200
A single character (a closing square bracket) should be put into a sequence at the end in these functions.
Thus use the corresponding function "seq_putc".
This issue was detected also by using the Coccinelle software.
--- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 2 +- drivers/md/raid5.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/md/raid1.c +1 -1
@@ -1418,7 +1418,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static void raid1_error (struct mddev *mddev,struct md_rdev *rdev)
drivers/md/raid10.c +1 -1
@@ -1499,7 +1499,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }/* check if there are enough drives for
drivers/md/raid5.c +1 -1
@@ -7077,7 +7077,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static void print_raid5_conf (struct r5conf *conf)
Signature · 1 line
2.10.1
Re: [PATCH] MD-RAID: Use seq_putc() in three status functions
Quoted 48 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Oct 2016 10:10:28 +0200A single character (a closing square bracket) should be put into a sequence at the end in these functions.
Thus use the corresponding function "seq_putc".This issue was detected also by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 2 +- drivers/md/raid5.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)drivers/md/raid1.c +1
-1@@ -1418,7 +1418,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev) rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static void raid1_error (struct mddev *mddev,struct md_rdev *rdev)drivers/md/raid10.c +1
-1@@ -1499,7 +1499,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }/* check if there are enough drives for drivers/md/raid5.c +0
-0
drivers/md/raid5.c static void raid5_status(struct seq_file *seq, struct mddev *mddev) · line 7083
Quoted 8 lines
drivers/md/raid5.c +1
-1@@ -7077,7 +7077,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_putc (seq,']' ); }static void print_raid5_conf (struct r5conf *conf)
The point of this patch being ... what?
Does it improve code? Does it improve anything?
Cheers,
Hannes
Signature · 8 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg) -- 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: MD-RAID: Use seq_putc() in three status functions?
Quoted 1 line
Does it improve code? Does it improve anything?
Yes. - I got such an impression.
* Is it more efficient to call the function "seq_printf" for the desired data processing for a single character than to pass it to the function "" in a string?
* Will the required data transfer shrink a bit for the affected functions because of such a change?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 1 line
Yes. - I got such an impression.
Correction:
* Is it more efficient to call the function "seq_putc" for the desired data processing for a single character than to pass it to the function "seq_printf" in a string?
* Will the required data transfer shrink a bit for the affected functions because of such a change?
How do you think about to reduce the transmission for such tiny strings containing delimiters?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Quoted 1 line
Does it improve code? Does it improve anything?
Yes. - I got such an impression.
* Is it more efficient to call the function "
seq_printf" for the desired data processing for a single character than to pass it to the function "" in a string?* Will the required data transfer shrink a bit for the affected functions because of such a change?
Which are questions _you_ should be able to answer. It's your patch, after all.
Once you do (and prove that the answer is 'yes' to the above two questions) the patch will be applied.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
Does it improve code? Does it improve anything?
Yes. - I got such an impression.
* Is it more efficient to call the function "
seq_printf" for the desired data processing for a single character than to pass it to the function "" in a string?* Will the required data transfer shrink a bit for the affected functions because of such a change?
Which are questions _you_ should be able to answer.
I wonder that the answers are not obvious for you already.
Calling the function "seq_putc" will be more efficient than "seq_printf" in this case because of the following reasons.
1. How does the distribution look like for supported processor architectures where the data transfer for bytes (as a function call parameter) is faster than for (string) pointers?
2. Did anybody measure already how many the execution times can vary for these functions?
3. seq_printf() provides more functionality as this kind of programming interface was designed for a bigger purpose.
How much do you care for consequences when such general functions are called with input data they were not designed for mainly?
4. The seq_putc() implementation is so simple.
http://lxr.free-electrons.com/source/fs/seq_file.c?v=4.8#L657
Where do you get doubts about its efficiency for the data processing of a single character?
Quoted 1 line
It's your patch, after all.
Yes. - I published a special update suggestion once again.
Quoted 2 lines
Once you do (and prove that the answer is 'yes' to the above two questions) the patch will be applied.
How do you think about to share a bit more from your software development and testing experience?
Which call frequencies do you observe for the affected functions?
1. raid1_status
2. raid10_status
3. raid5_status
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 12 lines · SF Markus Elfring
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
Does it improve code? Does it improve anything?
Yes. - I got such an impression.
* Is it more efficient to call the function "
seq_printf" for the desired data processing for a single character than to pass it to the function "" in a string?* Will the required data transfer shrink a bit for the affected functions because of such a change?
Which are questions _you_ should be able to answer.
Quoted 9 lines
I wonder that the answers are not obvious for you already.
Calling the function "
seq_putc" will be more efficient than "seq_printf" in this case because of the following reasons.1. How does the distribution look like for supported processor architectures where the data transfer for bytes (as a function call parameter) is faster than for (string) pointers?
How would I know? I would assume that _you_ did some measurements here; after all, _you_ are trying to push this patch.
I could easily claim that seq_printf() is more efficient than seq_putc(), and won't apply your patch.
So _you_ have to prove that your patch is more efficient.
Quoted 3 lines
2. Did anybody measure already how many the execution times can vary for these functions?
Probably not.
But referring to the previous topic:
Unless _you_ prove that _your_ patch is more efficient it won't get applied. _You_ want us to apply your patch, so the burden is on _you_ to provide the required data.
Quoted 3 lines
Where do you get doubts about its efficiency for the data processing of a single character?
Because it's being called at the end of a function calling seq_printf() already. So exchanging a single call is probably not helping anything, as the compiler will optimize it anyway.
Case in point: with your patch the x86_64 compiler generates nearly identical code for driver/md/raid1.c, but with one instruction _more_ after your patch has been applied.
So it's not immediately obvious that your patch is an improvement.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- 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: MD-RAID: Use seq_putc() in three status functions?
Quoted 8 lines
Quoted 7 lines
Calling the function "
seq_putc" will be more efficient than "seq_printf" in this case because of the following reasons.1. How does the distribution look like for supported processor architectures where the data transfer for bytes (as a function call parameter) is faster than for (string) pointers?
How would I know?
How many processor architecture characteristics do you know already?
* Is a string pointer often longer than a byte?
* I imagine that it can become also interesting to check byte level data access under constraints of machine word sizes and alignment.
Quoted 1 line
I would assume that _you_ did some measurements here;
How much would you trust in any concrete numbers I could present for this use case?
Do you give more trust to a reference testing platform?
Quoted 2 lines
I could easily claim that
seq_printf()is more efficient thanseq_putc(), and won't apply your patch.
This is also possible in principle.
Quoted 1 line
So _you_ have to prove that your patch is more efficient.
How many results would we like to clarify from various hardware and software combinations?
Quoted 4 lines
Quoted 3 lines
2. Did anybody measure already how many the execution times can vary for these functions?
Probably not.
Thanks for this information.
How important are the mentioned functions for you within the Linux programming interface so far?
Quoted 1 line
Unless _you_ prove that _your_ patch is more efficient it won't get applied.
Which data would you accept as a "prove" in this case?
Quoted 4 lines
Quoted 3 lines
Where do you get doubts about its efficiency for the data processing of a single character?
Because it's being called at the end of a function calling
seq_printf()already.
Interesting view …
Quoted 2 lines
So exchanging a single call is probably not helping anything, as the compiler will optimize it anyway.
How common is the discussed software transformation between implementations for optimising compilers?
Quoted 3 lines
Case in point: with your patch the
x86_64compiler generates nearly identical code fordriver/md/raid1.c, but with one instruction _more_ after your patch has been applied.
Which software versions and command parameters did you try out for this information (from an unspecified run time environment)?
Quoted 1 line
So it's not immediately obvious that your patch is an improvement.
I agree that there are system properties and constraints which can be considered further.
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: MD-RAID: Use seq_putc() in three status functions?
Quoted 11 lines · SF Markus Elfring
Quoted 8 lines
Quoted 7 lines
Calling the function "
seq_putc" will be more efficient than "seq_printf" in this case because of the following reasons.1. How does the distribution look like for supported processor architectures where the data transfer for bytes (as a function call parameter) is faster than for (string) pointers?
How would I know?
How many processor architecture characteristics do you know already?
x86, s390x, ppc/ppc64.
Quoted 2 lines
* Is a string pointer often longer than a byte?
Always.
(Which up to now I thought was basic programming knowledge...)
Quoted 3 lines
* I imagine that it can become also interesting to check byte level data access under constraints of machine word sizes and alignment.
So, another test for you to do.
Quoted 8 lines
Quoted 2 lines
I would assume that _you_ did some measurements here;
How much would you trust in any concrete numbers I could present for this use case?
Do you give more trust to a reference testing platform?
At the moment _any_ test would do.
With every response from your side you just keep on asking further questions. But so far you haven't delivered any answers nor measurements.
Quoted 6 lines
Quoted 3 lines
I could easily claim that
seq_printf()is more efficient thanseq_putc(), and won't apply your patch.This is also possible in principle.
No, this is what's going to happen if you don't show any measurements.
Quoted 6 lines
Quoted 2 lines
So _you_ have to prove that your patch is more efficient.
How many results would we like to clarify from various hardware and software combinations?
See above. At the moment _any_ test result from your side would do.
Quoted 11 lines
Quoted 5 lines
Quoted 4 lines
2. Did anybody measure already how many the execution times can vary for these functions?
Probably not.
Thanks for this information.
How important are the mentioned functions for you within the Linux programming interface so far?
Not very. The interface is only used in a slow path, and the execution time doesn't affect I/O performance in any way.
Quoted 5 lines
Quoted 2 lines
Unless _you_ prove that _your_ patch is more efficient it won't get applied.
Which data would you accept as a "prove" in this case?
Again: You want something from us. We don't have to prove anything, you need to convince us. And it is really hard to convince anyone by asking questions.
Quoted 16 lines
Quoted 5 lines
Quoted 4 lines
Where do you get doubts about its efficiency for the data processing of a single character?
Because it's being called at the end of a function calling
seq_printf()already.Interesting view …
Quoted 2 lines
So exchanging a single call is probably not helping anything, as the compiler will optimize it anyway.
How common is the discussed software transformation between implementations for optimising compilers?
Quoted 8 lines
Quoted 3 lines
Case in point: with your patch the
x86_64compiler generates nearly identical code fordriver/md/raid1.c, but with one instruction _more_ after your patch has been applied.Which software versions and command parameters did you try out for this information (from an unspecified run time environment)?
# gcc --version gcc (SUSE Linux) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
git tree from git.kernel.org/mkp/u/4.10/scsi-queue
_I_ did some measurements.
I'm still waiting from results from your side.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- 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: MD-RAID: Use seq_putc() in three status functions?
Quoted 3 lines
Quoted 2 lines
* Is a string pointer often longer than a byte?
Always.
I have got doubts for this specific information.
Quoted 1 line
(Which up to now I thought was basic programming knowledge...)
By the way:
Run time environments still exist where the size of a pointer can be also just one byte, don't they?
Quoted 4 lines
Quoted 3 lines
How many results would we like to clarify from various hardware and software combinations?
See above. At the moment _any_ test result from your side would do.
I imagine that another single result might not be representative. How many lessons from test statistics will usually be also relevant here?
Quoted 5 lines
Quoted 3 lines
How important are the mentioned functions for you within the Linux programming interface so far?
Not very. The interface is only used in a slow path, and the execution time doesn't affect I/O performance in any way.
Thanks for another interesting information.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Case in point: with your patch the
x86_64compiler generates nearly identical code fordriver/md/raid1.c, but with one instruction _more_ after your patch has been applied.Which software versions and command parameters did you try out for this information (from an unspecified run time environment)?
# gcc --version gcc (SUSE Linux) 4.8.5
Thanks for this detail.
* Did you choose any special optimisation settings for your quick check?
* Will any compilation results matter if "optimisation" would be switched off there?
Quoted 1 line
I'm still waiting from results from your side.
Would any other software developers or testers dare to add related information?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
On Mon, 2016-10-17 at 13:10 +0200, SF Markus Elfring wrote:
[...]
Quoted 5 lines
Quoted 1 line
(Which up to now I thought was basic programming knowledge...)
By the way:
Run time environments still exist where the size of a pointer can be also just one byte, don't they?
In the context of the Linux kernel: No.
[ Side note: there might be some DSP out there with a running Linux kernel which cannot really address a "byte" (meaning 8bits) but only in register sized quantities (and also aligned for that). But no one cares here really deeply as that is a so fundamental difference that the C- compiler must cope with that anyways in the first place. ]
[...]
Quoted 3 lines
Quoted 1 line
See above. At the moment _any_ test result from your side would do.
I imagine that another single result might not be representative.
Publish not only results but also everything (complete!) so that anyone can *easily* follow it to check and reproduce the results - especially if you want people with knowledge of other architectures to comment (otherwise they probably won't bother).
Kind regards,
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
See above. At the moment _any_ test result from your side would do.
I imagine that another single result might not be representative.
Publish not only results but also everything (complete!) so that anyone can *easily* follow it to check and reproduce the results - especially if you want people with knowledge of other architectures to comment (otherwise they probably won't bother).
Am I the only software developer so far who would dare to reconsider implementation details from three status functions?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 4 lines · SF Markus Elfring
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
See above. At the moment _any_ test result from your side would do.
I imagine that another single result might not be representative.
Quoted 8 lines
Quoted 4 lines
Publish not only results but also everything (complete!) so that anyone can *easily* follow it to check and reproduce the results - especially if you want people with knowledge of other architectures to comment (otherwise they probably won't bother).
Am I the only software developer so far who would dare to reconsider implementation details from three status functions?
No.
But we're waiting for you showing is that it is an improvement. Which at the moment we don't see.
Hence we're waiting from a proof or validation from your side.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- 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: MD-RAID: Use seq_putc() in three status functions?
Quoted 4 lines
Quoted 3 lines
Am I the only software developer so far who would dare to reconsider implementation details from three status functions?
No.
Thanks for this kind of promising feedback.
Quoted 1 line
But we're waiting for you showing is that it is an improvement.
Can this aspect also be clarified to some degree from a logical point of view?
* Would you really like to know under which circumstances data processing will be faster for a single character instead of using a string pointer and corresponding two characters?
* Do you care for a changed memory allocation characteristic?
* Will it occasionally be useful to avoid the storage for another string literal?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 12 lines · SF Markus Elfring
Quoted 4 lines
Quoted 3 lines
Am I the only software developer so far who would dare to reconsider implementation details from three status functions?
No.
Thanks for this kind of promising feedback.
Quoted 1 line
But we're waiting for you showing is that it is an improvement.
Can this aspect also be clarified to some degree from a logical point of view?
I sincerely doubt that.
We've discussed the logical implications already, and failed to come to a consensus. So we need some proof (as in: on this architecture I'm seeing this and that performance improvements).
Which you have to deliver.
Quoted 4 lines
* Would you really like to know under which circumstances data processing will be faster for a single character instead of using a string pointer and corresponding two characters?
It's not a problem of the interface, it's a problem of the resulting code (ie assembler output). We can discuss all we like, if the compiler decides to throw in an optimisation none of the arguments even apply.
Quoted 4 lines
* Do you care for a changed memory allocation characteristic?
* Will it occasionally be useful to avoid the storage for another string literal?
Occasionally: yes.
In this particular case: hardly.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 6 lines
Quoted 4 lines
* Would you really like to know under which circumstances data processing will be faster for a single character instead of using a string pointer and corresponding two characters?
It's not a problem of the interface, it's a problem of the resulting code (ie assembler output).
How do you think about to discuss concrete generated code any further?
Quoted 2 lines
We can discuss all we like, if the compiler decides to throw in an optimisation none of the arguments even apply.
Would it make sense to clarify assembler output with optimisation switched off?
Do you eventually care for code from non-optimising compilers?
Quoted 4 lines
Quoted 2 lines
* Will it occasionally be useful to avoid the storage for another string literal?
Occasionally: yes.
In this particular case: hardly.
I am curious when such a software design aspect can become more relevant. Would it be nice to get rid of three questionable string terminators (null bytes) for example?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 9 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
* Would you really like to know under which circumstances data processing will be faster for a single character instead of using a string pointer and corresponding two characters?
It's not a problem of the interface, it's a problem of the resulting code (ie assembler output).
How do you think about to discuss concrete generated code any further?
Sure. Show me the generated code and point out where the benefits are.
Quoted 7 lines
Quoted 2 lines
We can discuss all we like, if the compiler decides to throw in an optimisation none of the arguments even apply.
Would it make sense to clarify assembler output with optimisation switched off?
Do you eventually care for code from non-optimising compilers?
No. This is the linux kernel. There is a very, _very_ limited benefit of trying to use a non-standard compiler.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
* Will it occasionally be useful to avoid the storage for another string literal?
Occasionally: yes.
In this particular case: hardly.I am curious when such a software design aspect can become more relevant. Would it be nice to get rid of three questionable string terminators (null bytes) for example?
Again, all this does it trying to out-guess what the compiler might be doing during compilation. For which the easiest method is checking. So back to the original task for you: Show me in the generated output where the benefits are.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 1 line
So back to the original task for you: Show me in the generated output where the benefits are.
I can offer a bit more information for this software development discussion.
The afffected source files can be compiled for the processor architecture "x86_64" by a tool like "GCC 6.2.1+r239849-1.3" from the software distribution "openSUSE Tumbleweed" with the following command examples.
git checkout next-20161014 && my_cc=/usr/bin/gcc-6 && make HOSTCC="${my_cc}" allmodconfig && make -j6 HOSTCC="${my_cc}" drivers/md/ git checkout next_usage_of_seq_putc_in_md_raid_1 && my_cc=/usr/bin/gcc-6 && make HOSTCC="${my_cc}" allmodconfig && make -j6 HOSTCC="${my_cc}" drivers/md/
The tool "objdump" from the software package "binutils 2.27-1.3" can be used to get corresponding disassemblies for a file like "drivers/md/raid1.obj" which can then be compared as follows.
disassembly-md-raid1-seq_putc-1.txt renamed from disassembly-md-raid1-next-20161014-1.txt +34 -33
@@ -3349,7 +3349,7 @@ 37ad: 85 c0 test %eax,%eax 37af: 74 0d je 37be <raid1_status+0x9e> 37b1: 80 3d 00 00 00 00 00 cmpb $0x0,0x0(%rip) # 37b8 <raid1_status+0x98> - 37b8: 0f 84 1d 01 00 00 je 38db <raid1_status+0x1bb> + 37b8: 0f 84 1b 01 00 00 je 38d9 <raid1_status+0x1b9> 37be: 4c 89 ff mov %r15,%rdi 37c1: 31 db xor %ebx,%ebx 37c3: e8 00 00 00 00 callq 37c8 <raid1_status+0xa8>
@@ -3404,42 +3404,43 @@ 3891: 85 c0 test %eax,%eax 3893: 74 09 je 389e <raid1_status+0x17e> 3895: 80 3d 00 00 00 00 00 cmpb $0x0,0x0(%rip) # 389c <raid1_status+0x17c> - 389c: 74 6e je 390c <raid1_status+0x1ec> + 389c: 74 6c je 390a <raid1_status+0x1ea> 389e: 48 c7 c2 00 00 00 00 mov $0x0,%rdx 38a5: be 01 00 00 00 mov $0x1,%esi 38aa: 48 c7 c7 00 00 00 00 mov $0x0,%rdi 38b1: 65 ff 0d 00 00 00 00 decl %gs:0x0(%rip) # 38b8 <raid1_status+0x198> 38b8: e8 00 00 00 00 callq 38bd <raid1_status+0x19d> 38bd: 4c 89 f7 mov %r14,%rdi - 38c0: 48 c7 c6 00 00 00 00 mov $0x0,%rsi - 38c7: e8 00 00 00 00 callq 38cc <raid1_status+0x1ac> - 38cc: 48 83 c4 10 add $0x10,%rsp - 38d0: 5b pop %rbx - 38d1: 41 5c pop %r12 - 38d3: 41 5d pop %r13 - 38d5: 41 5e pop %r14 - 38d7: 41 5f pop %r15 - 38d9: 5d pop %rbp - 38da: c3 retq - 38db: e8 00 00 00 00 callq 38e0 <raid1_status+0x1c0> - 38e0: 84 c0 test %al,%al - 38e2: 0f 85 d6 fe ff ff jne 37be <raid1_status+0x9e> - 38e8: 48 c7 c2 00 00 00 00 mov $0x0,%rdx - 38ef: be 69 03 00 00 mov $0x369,%esi - 38f4: 48 c7 c7 00 00 00 00 mov $0x0,%rdi - 38fb: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 3902 <raid1_status+0x1e2> - 3902: e8 00 00 00 00 callq 3907 <raid1_status+0x1e7> - 3907: e9 b2 fe ff ff jmpq 37be <raid1_status+0x9e> - 390c: e8 00 00 00 00 callq 3911 <raid1_status+0x1f1> - 3911: 84 c0 test %al,%al - 3913: 75 89 jne 389e <raid1_status+0x17e> - 3915: 48 c7 c2 00 00 00 00 mov $0x0,%rdx - 391c: be 9c 03 00 00 mov $0x39c,%esi - 3921: 48 c7 c7 00 00 00 00 mov $0x0,%rdi - 3928: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 392f <raid1_status+0x20f> - 392f: e8 00 00 00 00 callq 3934 <raid1_status+0x214> - 3934: e9 65 ff ff ff jmpq 389e <raid1_status+0x17e> - 3939: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) + 38c0: be 5d 00 00 00 mov $0x5d,%esi + 38c5: e8 00 00 00 00 callq 38ca <raid1_status+0x1aa> + 38ca: 48 83 c4 10 add $0x10,%rsp + 38ce: 5b pop %rbx + 38cf: 41 5c pop %r12 + 38d1: 41 5d pop %r13 + 38d3: 41 5e pop %r14 + 38d5: 41 5f pop %r15 + 38d7: 5d pop %rbp + 38d8: c3 retq + 38d9: e8 00 00 00 00 callq 38de <raid1_status+0x1be> + 38de: 84 c0 test %al,%al + 38e0: 0f 85 d8 fe ff ff jne 37be <raid1_status+0x9e> + 38e6: 48 c7 c2 00 00 00 00 mov $0x0,%rdx + 38ed: be 69 03 00 00 mov $0x369,%esi + 38f2: 48 c7 c7 00 00 00 00 mov $0x0,%rdi + 38f9: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 3900 <raid1_status+0x1e0> + 3900: e8 00 00 00 00 callq 3905 <raid1_status+0x1e5> + 3905: e9 b4 fe ff ff jmpq 37be <raid1_status+0x9e> + 390a: e8 00 00 00 00 callq 390f <raid1_status+0x1ef> + 390f: 84 c0 test %al,%al + 3911: 75 8b jne 389e <raid1_status+0x17e> + 3913: 48 c7 c2 00 00 00 00 mov $0x0,%rdx + 391a: be 9c 03 00 00 mov $0x39c,%esi + 391f: 48 c7 c7 00 00 00 00 mov $0x0,%rdi + 3926: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 392d <raid1_status+0x20d> + 392d: e8 00 00 00 00 callq 3932 <raid1_status+0x212> + 3932: e9 67 ff ff ff jmpq 389e <raid1_status+0x17e> + 3937: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) + 393e: 00 00 0000000000003940 <print_conf>: 3940: e8 00 00 00 00 callq 3945 <print_conf+0x5>
@@ -11134,7 +11135,7 @@ 0000000000000000 <_GLOBAL__sub_D_65535_0_raid1.c>: 0: 55 push %rbp - 1: be 35 00 00 00 mov $0x35,%esi + 1: be 34 00 00 00 mov $0x34,%esi 6: 48 c7 c7 00 00 00 00 mov $0x0,%rdi d: 48 89 e5 mov %rsp,%rbp 10: e8 00 00 00 00 callq 15 <_GLOBAL__sub_D_65535_0_raid1.c+0x15>
@@ -11145,7 +11146,7 @@ 0000000000000000 <_GLOBAL__sub_I_65535_1_raid1.c>: 0: 55 push %rbp - 1: be 35 00 00 00 mov $0x35,%esi + 1: be 34 00 00 00 mov $0x34,%esi 6: 48 c7 c7 00 00 00 00 mov $0x0,%rdi d: 48 89 e5 mov %rsp,%rbp 10: e8 00 00 00 00 callq 15 <_GLOBAL__sub_I_65535_1_raid1.c+0x15>
Does this kind of data display contain differences which are worth for further considerations?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 1 line
Quoted 1 line
So back to the original task for you: Show me in the generated output where the benefits are.
I can offer another bit of information for this software development discussion.
The following build settings were active in my "Makefile" for this Linux test case.
…
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89
…
The afffected source files can be compiled for the processor architecture "x86_64" by a tool like "GCC 6.2.1+r239849-1.4" from the software distribution "openSUSE Tumbleweed" with the following command example.
my_original=${my_build_dir}unchanged/test/ \
&& my_fixing=${my_build_dir}patched/test/ \
&& mkdir -p ${my_original} ${my_fixing} \
&& my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/md/raid1.s \
&& git checkout next-20161014 \
&& make -j6 O="${my_original}" HOSTCC="${my_cc}" allmodconfig ${my_module} \
&& git checkout next_usage_of_seq_putc_in_md_raid_1 \
&& make -j6 O="${my_fixing}" HOSTCC="${my_cc}" allmodconfig ${my_module} \
&& diff -u "${my_original}${my_module}" "${my_fixing}${my_module}" > "${my_build_dir}assembler_code_comparison_$(date -I)_1.diff"
Unfortunately, the generated file got the size "311 KiB". I guess that this is too big to send such a file around on the Linux mailing list.
Is this kind of assembler code comparison still useful to clarify relevant differences further?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
Quoted 1 line
Quoted 1 line
Quoted 1 line
So back to the original task for you: Show me in the generated output where the benefits are.
I can offer another bit of information for this software development discussion.
The following build settings were active in my "Makefile" for this Linux test case.
…
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89
…
The afffected source files can be compiled for the processor architecture "x86_64" by a tool like "GCC 6.2.1+r239849-1.5" from the software distribution "openSUSE Tumbleweed" with the following command example.
my_original=${my_build_dir}unchanged/test/ \
&& my_fixing=${my_build_dir}patched/test/ \
&& mkdir -p ${my_original} ${my_fixing} \
&& my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/md/raid1.s \
&& git checkout next-20161014 \
&& make -j6 O="${my_original}" CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& git checkout next_usage_of_seq_putc_in_md_raid_1 \
&& make -j6 O="${my_fixing}" CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& diff -u "${my_original}${my_module}" "${my_fixing}${my_module}" > "${my_build_dir}assembler_code_comparison_$(date -I)_3.diff"
The generated file got the size "25.4 KiB" this time. I guess that only the following two diff hunks are interesting then to show desired effects for the suggested software refactoring around data output of a single character (instead of a similar string).
…
@@ -4402,10 +4402,6 @@
.LC19:
.string "%s"
.zero 61
- .align 32
-.LC20:
- .string "]"
- .zero 62
.text
.p2align 4,,15
.type raid1_status, @function
@@ -4564,8 +4560,8 @@
movq $rcu_lock_map, %rdi #,
call lock_release #
movq %r14, %rdi # seq,
- movq $.LC20, %rsi #,
- call seq_printf #
+ movl $93, %esi #,
+ call seq_putc #
addq $16, %rsp #,
popq %rbx #
popq %r12 #
…
* Is this kind of assembler code comparison useful to clarify relevant differences further?
* Are any software development concerns left over for such a transformation?
Regards,
Markus
Re: MD-RAID: Use seq_putc() in three status functions?
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
Quoted 3 lines
Quoted 2 lines
* Is a string pointer often longer than a byte?
Always.
Quoted 9 lines
I have got doubts for this specific information.
Quoted 1 line
(Which up to now I thought was basic programming knowledge...)
By the way:
Run time environments still exist where the size of a pointer can be also just one byte, don't they?
Really? Name one.
You can only fit a point in one byte if you are on an 8-bit system. Which I don't think linux is running on.
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
How many results would we like to clarify from various hardware and software combinations?
See above. At the moment _any_ test result from your side would do.
I imagine that another single result might not be representative. How many lessons from test statistics will usually be also relevant here?
As said above, _any_ statistic will do at this point.
Quoted 19 lines
Quoted 5 lines
Quoted 3 lines
How important are the mentioned functions for you within the Linux programming interface so far?
Not very. The interface is only used in a slow path, and the execution time doesn't affect I/O performance in any way.
Thanks for another interesting information.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Case in point: with your patch the
x86_64compiler generates nearly identical code fordriver/md/raid1.c, but with one instruction _more_ after your patch has been applied.Which software versions and command parameters did you try out for this information (from an unspecified run time environment)?
# gcc --version gcc (SUSE Linux) 4.8.5
Quoted 8 lines
Thanks for this detail.
* Did you choose any special optimisation settings for your quick check?
* Will any compilation results matter if "optimisation" would be switched off there?
These were the results when calling 'make' in the kernel source tree. With all applicable options.
Quoted 4 lines
Quoted 1 line
I'm still waiting from results from your side.
Would any other software developers or testers dare to add related information?
No. It's your patch, _you_ have to do it.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- 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 38/54 md/raid5: Move four asterisks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 15:00:23 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: "foo* bar" should be "foo *bar"
--- drivers/md/raid5.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/raid5.c +4 -4
@@ -2306,7 +2306,7 @@ static void shrink_stripes(struct r5conf *conf) conf->slab_cache =NULL ; } -static void raid5_end_read_request (struct bio * bi) +static void raid5_end_read_request (struct bio *bi) {struct stripe_head *sh = bi->bi_private;struct r5conf *conf = sh->raid_conf;
@@ -4760,7 +4760,7 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)*/ static void raid5_align_endio (struct bio *bi) { -struct bio * raid_bi = bi->bi_private; +struct bio *raid_bi = bi->bi_private;struct mddev *mddev;struct r5conf *conf;struct md_rdev *rdev;
@@ -4793,7 +4793,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio) {struct r5conf *conf = mddev->private;int dd_idx; -struct bio * align_bi; +struct bio *align_bi;struct md_rdev *rdev;sector_t end_sector;
@@ -5149,7 +5149,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi) } } -static void raid5_make_request (struct mddev *mddev,struct bio * bi) +static void raid5_make_request (struct mddev *mddev,struct bio *bi) {struct r5conf *conf = mddev->private;int dd_idx;
Signature · 1 line
2.10.1
PATCH 39/54 md/raid5: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:00:32 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/raid5.c | 165 +++++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 82 deletions(-)
drivers/md/raid5.c +83 -82
@@ -292,7 +292,7 @@ static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, struct list_head *temp_inactive_list) {BUG_ON (!list_empty (&sh->lru)); -BUG_ON (atomic_read (&conf->active_stripes)=0 ); +BUG_ON (atomic_read (&conf->active_stripes) =0 );if (test_bit (STRIPE_HANDLE , &sh->state)) {if (test_bit (STRIPE_DELAYED , &sh->state) && !test_bit (STRIPE_PREREAD_ACTIVE , &sh->state))
@@ -2224,7 +2224,7 @@ static int resize_stripes(struct r5conf *conf, int newsize) osh =get_free_stripe (conf, hash);unlock_device_hash_lock (conf, hash); -for (i=0 ; i<conf->pool_size; i++) { +for (i =0 ; i < conf->pool_size; i++) { nsh->dev[i].page = osh->dev[i].page; nsh->dev[i].orig_page = osh->dev[i].page; }
@@ -2246,7 +2246,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)*/ ndisks =kcalloc (newsize,sizeof (*ndisks),GFP_NOIO );if (ndisks) { -for (i=0 ; i<conf->raid_disks; i++) +for (i =0 ; i < conf->raid_disks; i++) ndisks[i] = conf->disks[i];kfree (conf->disks); conf->disks = ndisks;
@@ -2255,11 +2255,11 @@ static int resize_stripes(struct r5conf *conf, int newsize)mutex_unlock (&conf->cache_size_mutex);/* Step 4, return new stripes to service */ -while (!list_empty (&newstripes)) { +while (!list_empty (&newstripes)) { nsh = list_entry(newstripes.next, struct stripe_head, lru);list_del_init (&nsh->lru); -for (i=conf->raid_disks; i < newsize; i++) +for (i = conf->raid_disks; i < newsize; i++)if (!nsh->dev[i].page) {struct page *p =alloc_page (GFP_NOIO ); nsh->dev[i].page = p;
@@ -2315,7 +2315,7 @@ static void raid5_end_read_request(struct bio *bi)struct md_rdev *rdev =NULL ;sector_t s; -for (i=0 ; i<disks; i++) +for (i =0 ; i < disks; i++)if (bi = &sh->dev[i].req)break ;
@@ -2571,7 +2571,7 @@ sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector,* Select the parity disk based on the user selected algorithm. */ pd_idx = qd_idx =-1 ; -switch (conf->level) { +switch (conf->level) {case 4 : pd_idx = data_disks;break ;
@@ -2759,7 +2759,7 @@ sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous)if (i = sh->pd_idx)return 0 ; -switch (conf->level) { +switch (conf->level) {case 4 :break ;case 5 :switch (algorithm) {
@@ -2957,7 +2957,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, {struct bio **bip;struct r5conf *conf = sh->raid_conf; -int firstwrite=0 ; +int firstwrite =0 ; pr_debug("adding bi b#%llu to stripe s#%llu\n", (unsigned long long)bi->bi_iter.bi_sector,
@@ -3001,7 +3001,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,if (forwrite) {/* check if page is covered */ sector_t sector = sh->dev[dd_idx].sector; -for (bi=sh->dev[dd_idx].towrite; +for (bi = sh->dev[dd_idx].towrite; sector < sh->dev[dd_idx].sector +STRIPE_SECTORS && bi && bi->bi_iter.bi_sector <= sector; bi =r5_next_bio (bi, sh->dev[dd_idx].sector)) {
@@ -3639,7 +3639,8 @@ static void handle_stripe_dirtying(struct r5conf *conf, }if ((rcw < rmw || (rcw = rmw && conf->rmw_level !=PARITY_PREFER_RMW )) && rcw >0 ) {/* want reconstruct write, but need to get some data */ -int qread =0 ; +int qread =0 ; + rcw =0 ;for (i = disks; i--; ) {struct r5dev *dev = &sh->dev[i];
@@ -4031,7 +4032,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)/* Now to look around and see what can be done */ rcu_read_lock (); -for (i=disks; i--; ) { +for (i = disks; i--; ) {struct md_rdev *rdev;sector_t first_bad;int bad_sectors;
@@ -4716,7 +4717,7 @@ static int in_chunk_boundary(struct mddev *mddev, struct bio *bio)* add bio to the retry LIFO ( in O(1) ... we are in interrupt ) * later sampled by raid5d. */ -static void add_bio_to_retry (struct bio *bi,struct r5conf *conf) +static void add_bio_to_retry (struct bio *bi,struct r5conf *conf) {unsigned long flags;
@@ -4739,7 +4740,7 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)return bi; } bi = conf->retry_read_aligned_list; -if (bi) { +if (bi) { conf->retry_read_aligned_list = bi->bi_next; bi->bi_next =NULL ;/*
@@ -4768,7 +4769,7 @@ static void raid5_align_endio(struct bio *bi)bio_put (bi); - rdev = (void *)raid_bi->bi_next; + rdev = (void *)raid_bi->bi_next; raid_bi->bi_next =NULL ; mddev = rdev->mddev; conf = mddev->private;
@@ -4838,7 +4839,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)atomic_inc (&rdev->nr_pending);rcu_read_unlock (); - raid_bio->bi_next = (void *)rdev; + raid_bio->bi_next = (void *)rdev; align_bi->bi_bdev = rdev->bdev;bio_clear_flag (align_bi,BIO_SEG_VALID );
@@ -5198,7 +5199,7 @@ static void raid5_make_request(struct mddev *mddev, struct bio *bi) bi->bi_phys_segments =1 ;/* over-loaded to count active stripes */ prepare_to_wait (&conf->wait_for_overlap, &w,TASK_UNINTERRUPTIBLE ); -for (;logical_sector < last_sector; logical_sector +=STRIPE_SECTORS ) { +for (; logical_sector < last_sector; logical_sector +=STRIPE_SECTORS ) {int previous;int seq;
@@ -5464,10 +5465,10 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *skif ((mddev->reshape_backwards ? (safepos > writepos && readpos < writepos) : (safepos < writepos && readpos > writepos)) || -time_after (jiffies, conf->reshape_checkpoint +10 *HZ )) { +time_after (jiffies, conf->reshape_checkpoint +10 *HZ )) {/* Cannot proceed until we've updated the superblock... */ wait_event (conf->wait_for_overlap, -atomic_read (&conf->reshape_stripes)=0 +atomic_read (&conf->reshape_stripes) =0 ||test_bit (MD_RECOVERY_INTR , &mddev->recovery));if (atomic_read (&conf->reshape_stripes) !=0 )return 0 ;
@@ -5497,7 +5498,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk/* If any of this stripe is beyond the end of the old * array, then we need to zero those blocks */ -for (j=sh->disks; j--;) { +for (j = sh->disks; j--;) {sector_t s;if (j = sh->pd_idx)continue ;
@@ -6406,7 +6407,7 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink,unsigned long ret =SHRINK_STOP ;if (mutex_trylock (&conf->cache_size_mutex)) { - ret=0 ; + ret =0 ;while (ret < sc->nr_to_scan && conf->max_nr_stripes > conf->min_nr_stripes) {if (drop_one_stripe (conf) =0 ) {
@@ -7582,7 +7583,7 @@ static void raid5_quiesce(struct mddev *mddev, int state) {struct r5conf *conf = mddev->private; -switch (state) { +switch (state) {case 2 :/* resume for a suspend */ wake_up (&conf->wait_for_overlap);break ;
@@ -7850,70 +7851,70 @@ static void *raid6_takeover(struct mddev *mddev) }static struct md_personality raid6_personality = { - .name ="raid6" , - .level =6 , - .owner =THIS_MODULE , - .make_request = raid5_make_request, - .run = raid5_run, - .free = raid5_free, - .status = raid5_status, - .error_handler = raid5_error, - .hot_add_disk = raid5_add_disk, - .hot_remove_disk= raid5_remove_disk, - .spare_active = raid5_spare_active, - .sync_request = raid5_sync_request, - .resize = raid5_resize, - .size = raid5_size, - .check_reshape = raid6_check_reshape, - .start_reshape = raid5_start_reshape, - .finish_reshape = raid5_finish_reshape, - .quiesce = raid5_quiesce, - .takeover = raid6_takeover, - .congested = raid5_congested, + .name ="raid6" , + .level =6 , + .owner =THIS_MODULE , + .make_request = raid5_make_request, + .run = raid5_run, + .free = raid5_free, + .status = raid5_status, + .error_handler = raid5_error, + .hot_add_disk = raid5_add_disk, + .hot_remove_disk = raid5_remove_disk, + .spare_active = raid5_spare_active, + .sync_request = raid5_sync_request, + .resize = raid5_resize, + .size = raid5_size, + .check_reshape = raid6_check_reshape, + .start_reshape = raid5_start_reshape, + .finish_reshape = raid5_finish_reshape, + .quiesce = raid5_quiesce, + .takeover = raid6_takeover, + .congested = raid5_congested, };static struct md_personality raid5_personality = { - .name ="raid5" , - .level =5 , - .owner =THIS_MODULE , - .make_request = raid5_make_request, - .run = raid5_run, - .free = raid5_free, - .status = raid5_status, - .error_handler = raid5_error, - .hot_add_disk = raid5_add_disk, - .hot_remove_disk= raid5_remove_disk, - .spare_active = raid5_spare_active, - .sync_request = raid5_sync_request, - .resize = raid5_resize, - .size = raid5_size, - .check_reshape = raid5_check_reshape, - .start_reshape = raid5_start_reshape, - .finish_reshape = raid5_finish_reshape, - .quiesce = raid5_quiesce, - .takeover = raid5_takeover, - .congested = raid5_congested, + .name ="raid5" , + .level =5 , + .owner =THIS_MODULE , + .make_request = raid5_make_request, + .run = raid5_run, + .free = raid5_free, + .status = raid5_status, + .error_handler = raid5_error, + .hot_add_disk = raid5_add_disk, + .hot_remove_disk = raid5_remove_disk, + .spare_active = raid5_spare_active, + .sync_request = raid5_sync_request, + .resize = raid5_resize, + .size = raid5_size, + .check_reshape = raid5_check_reshape, + .start_reshape = raid5_start_reshape, + .finish_reshape = raid5_finish_reshape, + .quiesce = raid5_quiesce, + .takeover = raid5_takeover, + .congested = raid5_congested, };static struct md_personality raid4_personality = { - .name ="raid4" , - .level =4 , - .owner =THIS_MODULE , - .make_request = raid5_make_request, - .run = raid5_run, - .free = raid5_free, - .status = raid5_status, - .error_handler = raid5_error, - .hot_add_disk = raid5_add_disk, - .hot_remove_disk= raid5_remove_disk, - .spare_active = raid5_spare_active, - .sync_request = raid5_sync_request, - .resize = raid5_resize, - .size = raid5_size, - .check_reshape = raid5_check_reshape, - .start_reshape = raid5_start_reshape, - .finish_reshape = raid5_finish_reshape, - .quiesce = raid5_quiesce, - .takeover = raid4_takeover, - .congested = raid5_congested, + .name ="raid4" , + .level =4 , + .owner =THIS_MODULE , + .make_request = raid5_make_request, + .run = raid5_run, + .free = raid5_free, + .status = raid5_status, + .error_handler = raid5_error, + .hot_add_disk = raid5_add_disk, + .hot_remove_disk = raid5_remove_disk, + .spare_active = raid5_spare_active, + .sync_request = raid5_sync_request, + .resize = raid5_resize, + .size = raid5_size, + .check_reshape = raid5_check_reshape, + .start_reshape = raid5_start_reshape, + .finish_reshape = raid5_finish_reshape, + .quiesce = raid5_quiesce, + .takeover = raid4_takeover, + .congested = raid5_congested, };static int __init raid5_init (void )
Signature · 1 line
2.10.1
PATCH 40/54 md/raid10: Use kcalloc() in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:45:05 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/md/raid10.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/md/raid10.c +6 -7
@@ -3504,8 +3504,8 @@ static struct r10conf *setup_conf(struct mddev *mddev) goto out;/* FIXME calc properly */ - conf->mirrors =kzalloc (sizeof (struct raid10_info )*(mddev->raid_disks + -max (0 ,-mddev->delta_disks)), + conf->mirrors =kcalloc (mddev->raid_disks +max (0 , -mddev->delta_disks), +sizeof (*conf->mirrors),GFP_KERNEL );if (!conf->mirrors) goto out;
@@ -3936,11 +3936,10 @@ static int raid10_check_reshape(struct mddev *mddev) conf->mirrors_new =NULL ;if (mddev->delta_disks >0 ) {/* allocate new 'mirrors' list */ - conf->mirrors_new =kzalloc ( -sizeof (struct raid10_info ) - *(mddev->raid_disks + - mddev->delta_disks), -GFP_KERNEL ); + conf->mirrors_new =kcalloc (mddev->raid_disks + + mddev->delta_disks, +sizeof (*conf->mirrors_new), +GFP_KERNEL );if (!conf->mirrors_new)return -ENOMEM ; }
Signature · 1 line
2.10.1
PATCH 41/54 md/raid10: Improve another size determination in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:51:52 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/raid10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid10.c +1 -1
@@ -3499,7 +3499,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) } err = -ENOMEM ; - conf =kzalloc (sizeof (struct r10conf ),GFP_KERNEL ); + conf =kzalloc (sizeof (*conf),GFP_KERNEL );if (!conf) goto out;
Signature · 1 line
2.10.1
PATCH 42/54 md/raid10: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:57:19 +0200
Omit an extra message for a memory allocation failure (and another corresponding condition check) in this function.
--- drivers/md/raid10.c | 3 --- 1 file changed, 3 deletions(-)
drivers/md/raid10.c +0 -3
@@ -3554,9 +3554,6 @@ static struct r10conf *setup_conf(struct mddev *mddev)return conf; out: -if (err = -ENOMEM ) -printk (KERN_ERR "md/raid10:%s: couldn't allocate memory.\n" , -mdname (mddev));if (conf) {mempool_destroy (conf->r10bio_pool);kfree (conf->mirrors);
Signature · 1 line
2.10.1
PATCH 43/54 md/raid10: Return directly after detection of unsupported settings in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 17:32:49 +0200
* Return directly after unsupported system settings were detected at the beginning.
* Delete the explicit initialisation for the local variables "conf" and "err" which became unnecessary with this refactoring.
--- drivers/md/raid10.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/raid10.c +4 -4
@@ -3478,8 +3478,8 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)static struct r10conf *setup_conf (struct mddev *mddev) { -struct r10conf *conf =NULL ; -int err = -EINVAL ; +struct r10conf *conf; +int err;struct geom geo;int copies;
@@ -3489,13 +3489,13 @@ static struct r10conf *setup_conf(struct mddev *mddev)printk (KERN_ERR "md/raid10:%s: chunk size must be " "at least PAGE_SIZE(%ld) and be a power of 2.\n" ,mdname (mddev),PAGE_SIZE ); - goto out; +return ERR_PTR (-EINVAL ); }if (copies <2 || copies > mddev->raid_disks) {printk (KERN_ERR "md/raid10:%s: unsupported raid10 layout: 0x%8x\n" ,mdname (mddev), mddev->new_layout); - goto out; +return ERR_PTR (-EINVAL ); } err = -ENOMEM ;
Signature · 1 line
2.10.1
PATCH 44/54 md/raid10: Return directly after a failed kzalloc() in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 17:46:02 +0200
* Return directly after a call of the function "kzalloc" failed at the beginning.
* Delete a repeated check for the local variable "conf" which became unnecessary with this refactoring.
* Reorder calls for the functions "kfree" and "safe_put_page" at the end.
--- drivers/md/raid10.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/md/raid10.c +5 -7
@@ -3501,7 +3501,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) err = -ENOMEM ; conf =kzalloc (sizeof (*conf),GFP_KERNEL );if (!conf) - goto out; +return ERR_PTR (-ENOMEM );/* FIXME calc properly */ conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
@@ -3554,12 +3554,10 @@ static struct r10conf *setup_conf(struct mddev *mddev)return conf; out: -if (conf) { -mempool_destroy (conf->r10bio_pool); -kfree (conf->mirrors); -safe_put_page (conf->tmppage); -kfree (conf); - } +mempool_destroy (conf->r10bio_pool); +safe_put_page (conf->tmppage); +kfree (conf->mirrors); +kfree (conf);return ERR_PTR (err); }
Signature · 1 line
2.10.1
PATCH 45/54 md/raid10: Move assignments for the variable "err" in setup_conf()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:26:45 +0200
One local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignments into if branches to indicate a memory allocation failure there.
--- drivers/md/raid10.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/md/raid10.c +12 -5
@@ -3498,7 +3498,6 @@ static struct r10conf *setup_conf(struct mddev *mddev)return ERR_PTR (-EINVAL ); } - err = -ENOMEM ; conf =kzalloc (sizeof (*conf),GFP_KERNEL );if (!conf)return ERR_PTR (-ENOMEM );
@@ -3507,19 +3506,25 @@ static struct r10conf *setup_conf(struct mddev *mddev) conf->mirrors =kcalloc (mddev->raid_disks +max (0 , -mddev->delta_disks),sizeof (*conf->mirrors),GFP_KERNEL ); -if (!conf->mirrors) +if (!conf->mirrors) { + err = -ENOMEM ; goto out; + } conf->tmppage =alloc_page (GFP_KERNEL ); -if (!conf->tmppage) +if (!conf->tmppage) { + err = -ENOMEM ; goto out; + } conf->geo = geo; conf->copies = copies; conf->r10bio_pool =mempool_create (NR_RAID10_BIOS , r10bio_pool_alloc, r10bio_pool_free, conf); -if (!conf->r10bio_pool) +if (!conf->r10bio_pool) { + err = -ENOMEM ; goto out; + }calc_sectors (conf, mddev->dev_sectors);if (mddev->reshape_position = MaxSector) {
@@ -3547,8 +3552,10 @@ static struct r10conf *setup_conf(struct mddev *mddev)atomic_set (&conf->nr_pending,0 ); conf->thread =md_register_thread (raid10d, mddev,"raid10" ); -if (!conf->thread) +if (!conf->thread) { + err = -ENOMEM ; goto out; + } conf->mddev = mddev;return conf;
Signature · 1 line
2.10.1
PATCH 46/54 md/raid10: Less function calls in setup_conf() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:32:30 +0200
Resource release functions were called in up to three cases by the setup_conf() function during error handling even if the passed data structure members contained a null pointer.
Adjust jump targets according to the Linux coding style convention.
--- drivers/md/raid10.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/md/raid10.c +9 -7
@@ -3508,13 +3508,13 @@ static struct r10conf *setup_conf(struct mddev *mddev) GFP_KERNEL);if (!conf->mirrors) { err = -ENOMEM ; - goto out; + goto free_conf; } conf->tmppage =alloc_page (GFP_KERNEL );if (!conf->tmppage) { err = -ENOMEM ; - goto out; + goto kfree_mirrors; } conf->geo = geo;
@@ -3523,7 +3523,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) r10bio_pool_free, conf);if (!conf->r10bio_pool) { err = -ENOMEM ; - goto out; + goto put_page; }calc_sectors (conf, mddev->dev_sectors);
@@ -3533,7 +3533,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) }else {if (setup_geo (&conf->prev, mddev, geo_old) != conf->copies) { err = -EINVAL ; - goto out; + goto destroy_pool; } conf->reshape_progress = mddev->reshape_position;if (conf->prev.far_offset)
@@ -3554,16 +3554,18 @@ static struct r10conf *setup_conf(struct mddev *mddev) conf->thread =md_register_thread (raid10d, mddev,"raid10" );if (!conf->thread) { err = -ENOMEM ; - goto out; + goto destroy_pool; } conf->mddev = mddev;return conf; - - out: +destroy_pool:mempool_destroy (conf->r10bio_pool); +put_page:safe_put_page (conf->tmppage); +kfree_mirrors:kfree (conf->mirrors); +free_conf:kfree (conf);return ERR_PTR (err); }
Signature · 1 line
2.10.1
PATCH 47/54 md/raid10: Improve another size determination in raid10_start_reshape()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:48:17 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/md/raid10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid10.c +1 -1
@@ -4065,7 +4065,7 @@ static int raid10_start_reshape(struct mddev *mddev)spin_lock_irq (&conf->device_lock);if (conf->mirrors_new) {memcpy (conf->mirrors_new, conf->mirrors, -sizeof (struct raid10_info )*conf->prev.raid_disks); +sizeof (*conf->mirrors_new) * conf->prev.raid_disks);smp_mb ();kfree (conf->mirrors_old); conf->mirrors_old = conf->mirrors;
Signature · 1 line
2.10.1
PATCH 48/54 md/raid10: Move a brace for a designated initialiser
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 20:03:32 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: that open brace { should be on the previous line
--- drivers/md/raid10.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/raid10.c +1 -1
@@ -4676,8 +4676,7 @@ static void raid10_finish_reshape(struct mddev *mddev) mddev->reshape_backwards =0 ; } -static struct md_personality raid10_personality -{ +static struct md_personality raid10_personality = { .name ="raid10" , .level =10 , .owner =THIS_MODULE ,
Signature · 1 line
2.10.1
PATCH 49/54 md/raid10: Replace printk() calls by the usage of higher level interfaces
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:00:05 +0200
1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt" so that their information can be used for consistent message output.
2. Prefer usage of some higher level macros over calling "printk" directly in this software module.
--- drivers/md/raid10.c | 168 +++++++++++++++++++++++----------------------------- 1 file changed, 74 insertions(+), 94 deletions(-)
drivers/md/raid10.c +74 -94
@@ -18,6 +18,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt#include <linux/slab.h> #include <linux/delay.h> #include <linux/blkdev.h>
@@ -404,8 +406,8 @@ static void raid10_end_read_request(struct bio *bio)* oops, read error - keep the refcount on the rdev */ char b[BDEVNAME_SIZE ]; -printk_ratelimited (KERN_ERR -"md/raid10:%s: %s: rescheduling sector %llu\n" , + +pr_err_ratelimited ("%s: %s: rescheduling sector %llu\n" ,mdname (conf->mddev),bdevname (rdev->bdev, b), (unsigned long long )r10_bio->sector);
@@ -1586,11 +1588,10 @@ static void raid10_error(struct mddev *mddev, struct md_rdev *rdev)set_mask_bits (&mddev->flags,0 ,BIT (MD_CHANGE_DEVS ) |BIT (MD_CHANGE_PENDING ));spin_unlock_irqrestore (&conf->device_lock, flags); -printk (KERN_ALERT -"md/raid10:%s: Disk failure on %s, disabling device.\n" -"md/raid10:%s: Operation continuing on %d devices.\n" , -mdname (mddev),bdevname (rdev->bdev, b), -mdname (mddev), conf->geo.raid_disks - mddev->degraded); +pr_alert ("%s: Disk failure on %s, disabling device.\n" +MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n" , +mdname (mddev),bdevname (rdev->bdev, b), +mdname (mddev), conf->geo.raid_disks - mddev->degraded); }static void print_conf (struct r10conf *conf)
@@ -1598,13 +1599,14 @@ static void print_conf(struct r10conf *conf)int i;struct md_rdev *rdev; -printk (KERN_DEBUG "RAID10 conf printout:\n" ); +pr_debug ("conf printout:\n" );if (!conf) { -printk (KERN_DEBUG "(!conf)\n" ); +pr_debug ("(!conf)\n" );return ; } -printk (KERN_DEBUG " --- wd:%d rd:%d\n" , conf->geo.raid_disks - conf->mddev->degraded, - conf->geo.raid_disks); +pr_debug ("--- wd:%d rd:%d\n" , + conf->geo.raid_disks - conf->mddev->degraded, + conf->geo.raid_disks);/* This is only called with ->reconfix_mutex held, so * rcu protection of rdev is not needed */
@@ -1612,10 +1614,10 @@ static void print_conf(struct r10conf *conf)char b[BDEVNAME_SIZE ]; rdev = conf->mirrors[i].rdev;if (rdev) -printk (KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n" , - i, !test_bit (In_sync, &rdev->flags), - !test_bit (Faulty, &rdev->flags), -bdevname (rdev->bdev,b)); +pr_debug ("disk %d, wo:%d, o:%d, dev:%s\n" , + i, !test_bit (In_sync, &rdev->flags), + !test_bit (Faulty, &rdev->flags), +bdevname (rdev->bdev, b)); } }
@@ -2106,11 +2108,8 @@ static void fix_recovery_read_error(struct r10bio *r10_bio) ok =rdev_set_badblocks (rdev2, addr, s,0 );if (!ok) {/* just abort the recovery */ -printk (KERN_NOTICE -"md/raid10:%s: recovery aborted" -" due to read error\n" , -mdname (mddev)); - +pr_notice ("%s: recovery aborted due to read error\n" , +mdname (mddev)); conf->mirrors[dw].recovery_disabled = mddev->recovery_disabled; set_bit(MD_RECOVERY_INTR,
@@ -2256,14 +2255,10 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10char b[BDEVNAME_SIZE ];bdevname (rdev->bdev, b); -printk (KERN_NOTICE -"md/raid10:%s: %s: Raid device exceeded " -"read_error threshold [cur %d:max %d]\n" , -mdname (mddev), b, -atomic_read (&rdev->read_errors), max_read_errors); -printk (KERN_NOTICE -"md/raid10:%s: %s: Failing raid device\n" , -mdname (mddev), b); +pr_notice ("%s: %s: Raid device exceeded read_error threshold [cur %d:max %d]\n" , +mdname (mddev), b, +atomic_read (&rdev->read_errors), max_read_errors); +pr_notice ("%s: %s: Failing raid device\n" ,mdname (mddev), b);md_error (mddev, rdev); r10_bio->devs[r10_bio->read_slot].bio =IO_BLOCKED ;return ;
@@ -2353,20 +2348,17 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 s, conf->tmppage, WRITE) = 0) {/* Well, this device is dead */ -printk (KERN_NOTICE -"md/raid10:%s: read correction " -"write failed" -" (%d sectors at %llu on %s)\n" , -mdname (mddev), s, - (unsigned long long )( - sect + -choose_data_offset (r10_bio, - rdev)), -bdevname (rdev->bdev, b)); -printk (KERN_NOTICE "md/raid10:%s: %s: failing " -"drive\n" , -mdname (mddev), -bdevname (rdev->bdev, b)); +pr_notice ("%s: read correction write failed (" +"%d sectors at %llu on %s)\n" , +mdname (mddev), + s, + (unsigned long long ) + (sect + +choose_data_offset (r10_bio, rdev)), +bdevname (rdev->bdev, b)); +pr_notice ("%s: %s: failing drive\n" , +mdname (mddev), +bdevname (rdev->bdev, b)); }rdev_dec_pending (rdev, mddev);rcu_read_lock ();
@@ -2394,29 +2386,27 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 READ)) {case 0 :/* Well, this device is dead */ -printk (KERN_NOTICE -"md/raid10:%s: unable to read back " -"corrected sectors" -" (%d sectors at %llu on %s)\n" , -mdname (mddev), s, - (unsigned long long )( - sect + -choose_data_offset (r10_bio, rdev)), -bdevname (rdev->bdev, b)); -printk (KERN_NOTICE "md/raid10:%s: %s: failing " -"drive\n" , -mdname (mddev), -bdevname (rdev->bdev, b)); +pr_notice ("%s: unable to read back corrected sectors (" +"%d sectors at %llu on %s)\n" , +mdname (mddev), + s, + (unsigned long long ) + (sect + +choose_data_offset (r10_bio, rdev)), +bdevname (rdev->bdev, b)); +pr_notice ("%s: %s: failing drive\n" , +mdname (mddev), +bdevname (rdev->bdev, b));break ;case 1 : -printk (KERN_INFO -"md/raid10:%s: read error corrected" -" (%d sectors at %llu on %s)\n" , -mdname (mddev), s, - (unsigned long long )( - sect + -choose_data_offset (r10_bio, rdev)), -bdevname (rdev->bdev, b)); +pr_info ("%s: read error corrected (" +"%d sectors at %llu on %s)\n" , +mdname (mddev), + s, + (unsigned long long ) + (sect + +choose_data_offset (r10_bio, rdev)), +bdevname (rdev->bdev, b));atomic_add (s, &rdev->corrected_errors); }
@@ -2526,23 +2516,19 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio) read_more: rdev =read_balance (conf, r10_bio, &max_sectors);if (rdev =NULL ) { -printk (KERN_ALERT "md/raid10:%s: %s: unrecoverable I/O" -" read error for block %llu\n" , -mdname (mddev), b, - (unsigned long long )r10_bio->sector); +pr_alert ("%s: %s: unrecoverable I/O read error for block %llu\n" , +mdname (mddev), b, + (unsigned long long )r10_bio->sector);raid_end_bio_io (r10_bio);return ; } do_sync = (r10_bio->master_bio->bi_opf &REQ_SYNC ); slot = r10_bio->read_slot; -printk_ratelimited ( -KERN_ERR -"md/raid10:%s: %s: redirecting " -"sector %llu to another mirror\n" , -mdname (mddev), -bdevname (rdev->bdev, b), - (unsigned long long )r10_bio->sector); +pr_err_ratelimited ("%s: %s: redirecting sector %llu to another mirror\n" , +mdname (mddev), +bdevname (rdev->bdev, b), + (unsigned long long )r10_bio->sector); bio =bio_clone_mddev (r10_bio->master_bio,GFP_NOIO , mddev);bio_trim (bio, r10_bio->sector - bio->bi_iter.bi_sector, max_sectors);
@@ -3157,9 +3143,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,if (!any_working) {if (!test_and_set_bit (MD_RECOVERY_INTR , &mddev->recovery)) -printk (KERN_INFO "md/raid10:%s: insufficient " -"working devices for recovery.\n" , -mdname (mddev)); +pr_info ("%s: insufficient working devices for recovery.\n" , +mdname (mddev)); mirror->recovery_disabled = mddev->recovery_disabled; }
@@ -3486,14 +3471,13 @@ static struct r10conf *setup_conf(struct mddev *mddev) copies =setup_geo (&geo, mddev, geo_new);if (copies =-2 ) { -printk (KERN_ERR "md/raid10:%s: chunk size must be " -"at least PAGE_SIZE(%ld) and be a power of 2.\n" , +pr_err ("%s: chunk size must be at least PAGE_SIZE(%ld) and be a power of 2.\n" ,mdname (mddev),PAGE_SIZE );return ERR_PTR (-EINVAL ); }if (copies <2 || copies > mddev->raid_disks) { -printk (KERN_ERR "md/raid10:%s: unsupported raid10 layout: 0x%8x\n" , +pr_err ("%s: unsupported raid10 layout: 0x%8x\n" ,mdname (mddev), mddev->new_layout);return ERR_PTR (-EINVAL ); }
@@ -3657,8 +3641,7 @@ static int raid10_run(struct mddev *mddev) }/* need to check that every block has at least one working mirror */ if (!enough (conf,-1 )) { -printk (KERN_ERR "md/raid10:%s: not enough operational mirrors.\n" , -mdname (mddev)); +pr_err ("%s: not enough operational mirrors.\n" ,mdname (mddev)); goto out_free_conf; }
@@ -3699,12 +3682,11 @@ static int raid10_run(struct mddev *mddev) }if (mddev->recovery_cp != MaxSector) -printk (KERN_NOTICE "md/raid10:%s: not clean" -" -- starting background reconstruction\n" , -mdname (mddev)); -printk (KERN_INFO -"md/raid10:%s: active with %d out of %d devices\n" , -mdname (mddev), conf->geo.raid_disks - mddev->degraded, +pr_notice ("%s: not clean - starting background reconstruction\n" , +mdname (mddev)); +pr_info ("%s: active with %d out of %d devices\n" , +mdname (mddev), + conf->geo.raid_disks - mddev->degraded, conf->geo.raid_disks);/* * Ok, everything is just fine now
@@ -3740,7 +3722,7 @@ static int raid10_run(struct mddev *mddev)if (max (before_length, after_length) > min_offset_diff) {/* This cannot work */ -printk ("md/raid10: offset difference not enough to continue reshape\n" ); +pr_notice ("offset difference not enough to continue reshape\n" ); goto out_free_conf; } conf->offset_diff = min_offset_diff;
@@ -3847,8 +3829,7 @@ static void *raid10_takeover_raid0(struct mddev *mddev, sector_t size, int devs)struct r10conf *conf;if (mddev->degraded >0 ) { -printk (KERN_ERR "md/raid10:%s: Error: degraded raid0!\n" , -mdname (mddev)); +pr_err ("%s: Error: degraded raid0!\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }sector_div (size, devs);
@@ -3888,8 +3869,7 @@ static void *raid10_takeover(struct mddev *mddev)/* for raid0 takeover only one zone is supported */ raid0_conf = mddev->private;if (raid0_conf->nr_strip_zones >1 ) { -printk (KERN_ERR "md/raid10:%s: cannot takeover raid 0" -" with more than one zone.\n" , +pr_err ("%s: cannot takeover raid 0 with more than one zone.\n" ,mdname (mddev));return ERR_PTR (-EINVAL ); }
@@ -4078,7 +4058,7 @@ static int raid10_start_reshape(struct mddev *mddev)sector_t size =raid10_size (mddev,0 ,0 );if (size < mddev->array_sectors) {spin_unlock_irq (&conf->device_lock); -printk (KERN_ERR "md/raid10:%s: array size must be reduce before number of disks\n" , +pr_err ("%s: array size must be reduced before number of disks\n" ,mdname (mddev));return -EINVAL ; }
Signature · 1 line
2.10.1
Re: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces
On Thu, 2016-10-06 at 11:49 +0200, SF Markus Elfring wrote:
[]
drivers/md/raid10.c line 22
Quoted 10 lines
drivers/md/raid10.c +0
-0@@ -18,6 +18,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ drivers/md/raid10.c +2
-0+#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmt
Please just use
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
like the more than thousand other uses in the kernel.
--
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 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces
Quoted 8 lines
Quoted 8 lines
drivers/md/raid10.c +0
-0@@ -18,6 +18,8 @@* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Quoted 8 lines
drivers/md/raid10.c line 22
Quoted 2 lines
drivers/md/raid10.c +2
-0+#define MY_LOG_PREFIX KBUILD_MODNAME ": " +#define pr_fmt (fmt) MY_LOG_PREFIX fmtPlease just use
#define
pr_fmt(fmt)KBUILD_MODNAME": " fmtlike the more than thousand other uses in the kernel.
Thanks for your suggestion.
I got the impression that the omission of a macro like "MY_LOG_PREFIX" would not really work for the suggested source code transformation so far.
How should a multiline log message be achieved as it was constructed in the function "raid10_error" (for example)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?idÈ02e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Joe Perches
maintainerRe: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces
Quoted 3 lines · SF Markus Elfring
How should a multiline log message be achieved as it was constructed in the function "
raid10_error" (for example)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?idÈ02e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589
As two individual calls to pr_alert
--
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: md/raid10: Replace printk() calls by the usage of higher level interfaces
Quoted 5 lines
Quoted 3 lines
How should a multiline log message be achieved as it was constructed in the function "
raid10_error" (for example)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?idÈ02e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589As two individual calls to
pr_alert
I know also such an approach.
Would it be nicer if a single call will be sufficient for such a log message?
Can an idea picked up which was discussed for the update suggestion
"[PATCH 4/4] Input-gameport: Replace some printk() calls by pr_info() in joydump_connect()" for a moment (on 2016-09-24)?
https://lkml.kernel.org/r/<[email protected]>
https://lkml.org/lkml/2016/9/24/149
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Joe Perches
maintainerRe: md/raid10: Replace printk() calls by the usage of higher level interfaces
Quoted 7 lines · SF Markus Elfring
Would it be nicer if a single call will be sufficient for such a log message?
Can an idea picked up which was discussed for the update suggestion
"[PATCH 4/4] Input-gameport: Replace someprintk()calls bypr_info()injoydump_connect()" for a moment (on 2016-09-24)?
https://lkml.kernel.org/r/<[email protected]>;
https://lkml.org/lkml/2016/9/24/149
That'd be great.
Pease come back only after you've implemented that.
Re: md/raid10: Replace printk() calls by the usage of higher level interfaces
Quoted 10 lines
Quoted 7 lines
Would it be nicer if a single call will be sufficient for such a log message?
Can an idea picked up which was discussed for the update suggestion
"[PATCH 4/4] Input-gameport: Replace someprintk()calls bypr_info()injoydump_connect()" for a moment (on 2016-09-24)?
https://lkml.kernel.org/r/<[email protected]>;
https://lkml.org/lkml/2016/9/24/149That'd be great.
Pease come back only after you've implemented that.
Does this use case show another improvement opportunity for involved software developers (besides me)?
Are there any more contributors around who would like to tackle such a challenge?
Regards,
Markus
PATCH 50/54 md/raid10: Delete indentation for one jump label
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:07:35 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: labels should not be indented
Thus fix the affected source code place.
--- drivers/md/raid10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid10.c +1 -1
@@ -4559,7 +4559,7 @@ static int handle_reshape_read_error(struct mddev *mddev,rcu_read_lock ();if (success)break ; - failed: +failed: slot++;if (slot >= conf->copies) slot =0 ;
Signature · 1 line
2.10.1
PATCH 51/54 md/raid10: Adjust 22 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:36:43 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/md/raid10.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
drivers/md/raid10.c +22 -21
@@ -734,10 +734,10 @@ static struct md_rdev *read_balance(struct r10conf *conf,continue ; disk = r10_bio->devs[slot].devnum; rdev =rcu_dereference (conf->mirrors[disk].replacement); -if (rdev =NULL ||test_bit (Faulty, &rdev->flags) || +if (!rdev ||test_bit (Faulty, &rdev->flags) || r10_bio->devs[slot].addr + sectors > rdev->recovery_offset) rdev =rcu_dereference (conf->mirrors[disk].rdev); -if (rdev =NULL || +if (!rdev ||test_bit (Faulty, &rdev->flags))continue ; if (!test_bit(In_sync, &rdev->flags) &&
@@ -1386,7 +1386,8 @@ static void __make_request(struct mddev *mddev, struct bio *bio)if (r10_bio->devs[i].repl_bio) {struct md_rdev *rdev = conf->mirrors[d].replacement; -if (rdev =NULL ) { + +if (!rdev) {/* Replacement just got moved to main 'rdev' */ smp_mb (); rdev = conf->mirrors[d].rdev;
@@ -1701,7 +1702,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev) first = last = rdev->raid_disk;if (rdev->saved_raid_disk >= first && - conf->mirrors[rdev->saved_raid_disk].rdev =NULL ) + !conf->mirrors[rdev->saved_raid_disk].rdev) mirror = rdev->saved_raid_disk;else mirror = first;
@@ -1711,7 +1712,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)continue ;if (p->rdev) {if (!test_bit (WantReplacement, &p->rdev->flags) || - p->replacement !=NULL ) + p->replacement)continue ;clear_bit (In_sync, &rdev->flags);set_bit (Replacement, &rdev->flags);
@@ -1849,7 +1850,7 @@ static void end_sync_request(struct r10bio *r10_bio)struct mddev *mddev = r10_bio->mddev;while (atomic_dec_and_test (&r10_bio->remaining)) { -if (r10_bio->master_bio =NULL ) { +if (!r10_bio->master_bio) {/* the primary of several recovery bios */ sector_t s = r10_bio->sectors; if (test_bit(R10BIO_MadeGood, &r10_bio->state) ||
@@ -2515,7 +2516,7 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio) read_more: rdev =read_balance (conf, r10_bio, &max_sectors); -if (rdev =NULL ) { +if (!rdev) {pr_alert ("%s: %s: unrecoverable I/O read error for block %llu\n" ,mdname (mddev), b, (unsigned long long )r10_bio->sector);
@@ -2587,7 +2588,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)for (m =0 ; m < conf->copies; m++) {int dev = r10_bio->devs[m].devnum; rdev = conf->mirrors[dev].rdev; -if (r10_bio->devs[m].bio =NULL ) +if (!r10_bio->devs[m].bio)continue ;if (!r10_bio->devs[m].bio->bi_error) { rdev_clear_badblocks(
@@ -2602,7 +2603,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)md_error (conf->mddev, rdev); } rdev = conf->mirrors[dev].replacement; -if (r10_bio->devs[m].repl_bio =NULL ) +if (!r10_bio->devs[m].repl_bio)continue ;if (!r10_bio->devs[m].repl_bio->bi_error) {
@@ -2631,7 +2632,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) r10_bio->devs[m].addr, r10_bio->sectors, 0);rdev_dec_pending (rdev, conf->mddev); - }else if (bio !=NULL && bio->bi_error) { + }else if (bio && bio->bi_error) { fail = true;if (!narrow_write_error (r10_bio, m)) {md_error (conf->mddev, rdev);
@@ -2816,7 +2817,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,* Allow skipping a full rebuild for incremental assembly * of a clean array, like RAID1 does. */ -if (mddev->bitmap =NULL && +if (!mddev->bitmap && mddev->recovery_cp = MaxSector && mddev->reshape_position = MaxSector && !test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
@@ -2945,10 +2946,10 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, mrdev =rcu_dereference (mirror->rdev); mreplace =rcu_dereference (mirror->replacement); -if ((mrdev =NULL || +if ((!mrdev ||test_bit (Faulty, &mrdev->flags) ||test_bit (In_sync, &mrdev->flags)) && - (mreplace =NULL || + (!mreplace ||test_bit (Faulty, &mreplace->flags))) {rcu_read_unlock ();continue ;
@@ -2976,7 +2977,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,if (sync_blocks < max_sync) max_sync = sync_blocks;if (!must_sync && - mreplace =NULL && + !mreplace && !conf->fullsync) {/* yep, skip the sync_blocks here, but don't assume * that there will never be anything to do here
@@ -3011,7 +3012,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,for (j =0 ; j < conf->geo.raid_disks; j++) {struct md_rdev *rdev =rcu_dereference ( conf->mirrors[j].rdev); -if (rdev =NULL ||test_bit (Faulty, &rdev->flags)) { +if (!rdev ||test_bit (Faulty, &rdev->flags)) { still_degraded =1 ;break ; }
@@ -3099,7 +3100,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,* this comment keeps human reviewers * happy. */ -if (mreplace =NULL || bio =NULL || +if (!mreplace || !bio ||test_bit (Faulty, &mreplace->flags))break ;bio_reset (bio);
@@ -3161,7 +3162,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,if (mreplace)rdev_dec_pending (mreplace, mddev); } -if (biolist =NULL ) { +if (!biolist) {while (r10_bio) {struct r10bio *rb2 = r10_bio; r10_bio = (struct r10bio *) rb2->master_bio;
@@ -3214,7 +3215,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, bio->bi_error = -EIO ;rcu_read_lock (); rdev =rcu_dereference (conf->mirrors[d].rdev); -if (rdev =NULL ||test_bit (Faulty, &rdev->flags)) { +if (!rdev ||test_bit (Faulty, &rdev->flags)) {rcu_read_unlock ();continue ; }
@@ -3243,7 +3244,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, count++; rdev =rcu_dereference (conf->mirrors[d].replacement); -if (rdev =NULL ||test_bit (Faulty, &rdev->flags)) { +if (!rdev ||test_bit (Faulty, &rdev->flags)) {rcu_read_unlock ();continue ; }
@@ -3565,7 +3566,7 @@ static int raid10_run(struct mddev *mddev)int first =1 ;bool discard_supported = false; -if (mddev->private =NULL ) { +if (!mddev->private) { conf =setup_conf (mddev);if (IS_ERR (conf))return PTR_ERR (conf);
@@ -4542,7 +4543,7 @@ static int handle_reshape_read_error(struct mddev *mddev,int d = r10b->devs[slot].devnum;struct md_rdev *rdev =rcu_dereference (conf->mirrors[d].rdev);sector_t addr; -if (rdev =NULL || +if (!rdev ||test_bit (Faulty, &rdev->flags) || !test_bit (In_sync, &rdev->flags)) goto failed;
Signature · 6 lines
2.10.1 -- 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 52/54 md/raid10: Replace a seq_printf() call by seq_puts() in raid10_status()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:41:09 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Prefer seq_puts to seq_printf
--- drivers/md/raid10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid10.c +1 -1
@@ -1502,7 +1502,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)seq_printf (seq,"%s" , rdev &&test_bit (In_sync, &rdev->flags) ?"U" :"_" ); }rcu_read_unlock (); -seq_printf (seq,"]" ); +seq_puts (seq,"]" ); }/* check if there are enough drives for
Signature · 1 line
2.10.1
PATCH 53/54 md/raid10: Delete two unwanted spaces behind asterisks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 22:02:18 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: "foo * bar" should be "foo *bar"
--- drivers/md/raid10.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid10.c +2 -2
@@ -107,7 +107,7 @@ static void reshape_request_write(struct mddev *mddev, struct r10bio *r10_bio);static void end_reshape_write (struct bio *bio);static void end_reshape (struct r10conf *conf); -static void *r10bio_pool_alloc (gfp_t gfp_flags,void *data) +static void *r10bio_pool_alloc (gfp_t gfp_flags,void *data) {struct r10conf *conf = data; int size = offsetof(struct r10bio, devs[conf->copies]);
@@ -137,7 +137,7 @@ static void r10bio_pool_free(void *r10_bio, void *data)* one for write (we recover only one drive per r10buf) * */ -static void *r10buf_pool_alloc (gfp_t gfp_flags,void *data) +static void *r10buf_pool_alloc (gfp_t gfp_flags,void *data) {struct r10conf *conf = data;struct page *page;
Signature · 1 line
2.10.1
PATCH 54/54 md/raid10: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 22:22:14 +0200
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/md/raid10.c | 71 +++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 35 deletions(-)
drivers/md/raid10.c +36 -35
@@ -224,7 +224,7 @@ static void r10buf_pool_free(void *__r10_bio, void *data)struct r10bio *r10bio = __r10_bio;int j; -for (j=0 ; j < conf->copies; j++) { +for (j =0 ; j < conf->copies; j++) {struct bio *bio = r10bio->devs[j].bio;if (bio) {for (i =0 ; i <RESYNC_PAGES ; i++) {
@@ -553,7 +553,7 @@ static void raid10_end_write_request(struct bio *bio)static void __raid10_find_phys (struct geom *geo,struct r10bio *r10bio) { -int n,f; +int n, f;sector_t sector;sector_t chunk;sector_t stripe;
@@ -1937,7 +1937,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)atomic_set (&r10_bio->remaining,1 );/* find the first device with a block */ -for (i=0 ; i<conf->copies; i++) +for (i =0 ; i < conf->copies; i++)if (!r10_bio->devs[i].bio->bi_error)break ;
@@ -1951,7 +1951,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) vcnt = (r10_bio->sectors + (PAGE_SIZE >>9 ) -1 ) >> (PAGE_SHIFT -9 );/* now find blocks with errors */ -for (i=0 ; i < conf->copies ; i++) { +for (i =0 ; i < conf->copies; i++) {int j, d; tbio = r10_bio->devs[i].bio;
@@ -2236,7 +2236,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 {int sect =0 ;/* Offset from r10_bio->sector */ int sectors = r10_bio->sectors; -struct md_rdev *rdev; +struct md_rdev *rdev;int max_read_errors =atomic_read (&mddev->max_corr_read_errors);int d = r10_bio->devs[r10_bio->read_slot].devnum;
@@ -2265,7 +2265,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10return ; } -while (sectors) { +while (sectors) {int s = sectors;int sl = r10_bio->read_slot;int success =0 ;
@@ -2331,7 +2331,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10while (sl != r10_bio->read_slot) {char b[BDEVNAME_SIZE ]; -if (sl=0 ) +if (sl =0 ) sl = conf->copies; sl--; d = r10_bio->devs[sl].devnum;
@@ -2368,7 +2368,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10while (sl != r10_bio->read_slot) {char b[BDEVNAME_SIZE ]; -if (sl=0 ) +if (sl =0 ) sl = conf->copies; sl--; d = r10_bio->devs[sl].devnum;
@@ -2996,7 +2996,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,raise_barrier (conf, rb2 !=NULL );atomic_set (&r10_bio->remaining,0 ); - r10_bio->master_bio = (struct bio *)rb2; + r10_bio->master_bio = (struct bio *)rb2;if (rb2)atomic_inc (&rb2->remaining); r10_bio->mddev = mddev;
@@ -3022,7 +3022,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, &sync_blocks, still_degraded); any_working =0 ; -for (j=0 ; j<conf->copies;j++) { +for (j =0 ; j < conf->copies; j++) {int k;int d = r10_bio->devs[j].devnum;sector_t from_addr, to_addr;
@@ -3063,7 +3063,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,atomic_inc (&rdev->nr_pending);/* and we write to 'i' (if not in_sync) */ -for (k=0 ; k<conf->copies; k++) +for (k =0 ; k < conf->copies; k++)if (r10_bio->devs[k].devnum = i)break ;BUG_ON (k = conf->copies);
@@ -3165,7 +3165,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,if (!biolist) {while (r10_bio) {struct r10bio *rb2 = r10_bio; - r10_bio = (struct r10bio *) rb2->master_bio; + + r10_bio = (struct r10bio *) rb2->master_bio; rb2->master_bio =NULL ;put_buf (rb2); }
@@ -3268,7 +3269,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, }if (count <2 ) { -for (i=0 ; i<conf->copies; i++) { +for (i =0 ; i < conf->copies; i++) {int d = r10_bio->devs[i].devnum;if (r10_bio->devs[i].bio->bi_end_io) rdev_dec_pending(conf->mirrors[d].rdev,
@@ -3295,7 +3296,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, len = (max_sector - sector_nr) <<9 ;if (len =0 )break ; -for (bio= biolist ; bio ; bio=bio->bi_next) { +for (bio = biolist; bio; bio = bio->bi_next) {struct bio *bio2; page = bio->bi_io_vec[bio->bi_vcnt].bv_page;if (bio_add_page (bio, page, len,0 ))
@@ -3765,7 +3766,7 @@ static void raid10_quiesce(struct mddev *mddev, int state) {struct r10conf *conf = mddev->private; -switch (state) { +switch (state) {case 1 :raise_barrier (conf,0 );break ;
@@ -4658,26 +4659,26 @@ static void raid10_finish_reshape(struct mddev *mddev) }static struct md_personality raid10_personality = { - .name ="raid10" , - .level =10 , - .owner =THIS_MODULE , - .make_request = raid10_make_request, - .run = raid10_run, - .free = raid10_free, - .status = raid10_status, - .error_handler = raid10_error, - .hot_add_disk = raid10_add_disk, - .hot_remove_disk= raid10_remove_disk, - .spare_active = raid10_spare_active, - .sync_request = raid10_sync_request, - .quiesce = raid10_quiesce, - .size = raid10_size, - .resize = raid10_resize, - .takeover = raid10_takeover, - .check_reshape = raid10_check_reshape, - .start_reshape = raid10_start_reshape, - .finish_reshape = raid10_finish_reshape, - .congested = raid10_congested, + .name ="raid10" , + .level =10 , + .owner =THIS_MODULE , + .make_request = raid10_make_request, + .run = raid10_run, + .free = raid10_free, + .status = raid10_status, + .error_handler = raid10_error, + .hot_add_disk = raid10_add_disk, + .hot_remove_disk = raid10_remove_disk, + .spare_active = raid10_spare_active, + .sync_request = raid10_sync_request, + .quiesce = raid10_quiesce, + .size = raid10_size, + .resize = raid10_resize, + .takeover = raid10_takeover, + .check_reshape = raid10_check_reshape, + .start_reshape = raid10_start_reshape, + .finish_reshape = raid10_finish_reshape, + .congested = raid10_congested, };static int __init raid_init (void )
Signature · 1 line
2.10.1
cover dvb-tc90522: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:38:12 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Use kmalloc_array()
Rename a jump label
drivers/media/dvb-frontends/tc90522.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.10.1
PATCH 1/2 dvb-tc90522: Use kmalloc_array() in tc90522_master_xfer()
From: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:07:43 +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/media/dvb-frontends/tc90522.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/tc90522.c +1 -1
@@ -656,7 +656,7 @@ tc90522_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)for (i =0 ; i < num; i++)if (msgs[i].flags &I2C_M_RD ) rd_num++; - new_msgs =kmalloc (sizeof (*new_msgs) * (num + rd_num),GFP_KERNEL ); + new_msgs =kmalloc_array (num + rd_num,sizeof (*new_msgs),GFP_KERNEL );if (!new_msgs)return -ENOMEM ;
Signature · 1 line
2.10.1
PATCH 2/2 dvb-tc90522: Rename a jump label in tc90522_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:13:57 +0200
Adjust a jump label according to the Linux coding style convention.
--- drivers/media/dvb-frontends/tc90522.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/tc90522.c +2 -3
@@ -794,14 +794,13 @@ static int tc90522_probe(struct i2c_client *client,i2c_set_adapdata (adap, state); ret =i2c_add_adapter (adap);if (ret <0 ) - goto err; + goto free_state; cfg->tuner_i2c = state->cfg.tuner_i2c = adap;i2c_set_clientdata (client, &state->cfg);dev_info (&client->dev,"Toshiba TC90522 attached.\n" );return 0 ; - -err: +free_state:kfree (state);return ret; }
Signature · 1 line
2.10.1
Re: [PATCH 2/2] [media] dvb-tc90522: Rename a jump label in tc90522_probe()
Am 07.10.2016 21:46, schrieb SF Markus Elfring:
Quoted 21 lines
From: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:13:57 +0200Adjust a jump label according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/dvb-frontends/tc90522.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/media/dvb-frontends/tc90522.c +1
-1@@ -794,14 +794,13 @@ static int tc90522_probe(struct i2c_client *client,i2c_set_adapdata (adap, state); ret =i2c_add_adapter (adap);if (ret <0 ) - goto err; + goto free_state; cfg->tuner_i2c = state->cfg.tuner_i2c = adap;
drivers/media/dvb-frontends/tc90522.c static int tc90522_probe(struct i2c_client *client, · line 806
Quoted 10 lines
drivers/media/dvb-frontends/tc90522.c +1
-2i2c_set_clientdata (client, &state->cfg);dev_info (&client->dev,"Toshiba TC90522 attached.\n" );return 0 ; - -err: +free_state:kfree (state);return ret; }
there is only one user, IMHO this can be moved to the if block.
re,
wh
cover RedRat3: Fine-tuning for several function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 18:06:18 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (18):
Use kcalloc() in two functions
Move two assignments in redrat3_transmit_ir()
Return directly after a failed kcalloc() in redrat3_transmit_ir() One function call less in redrat3_transmit_ir() after error detection Delete six messages for a failed memory allocation
Delete an unnecessary variable initialisation in redrat3_get_firmware_rev() Improve another size determination in redrat3_reset()
Improve another size determination in redrat3_send_cmd()
Move a variable assignment in redrat3_dev_probe()
Delete an unnecessary variable initialisation in redrat3_init_rc_dev() Delete the variable "dev" in redrat3_init_rc_dev()
Move a variable assignment in redrat3_init_rc_dev()
Return directly after a failed rc_allocate_device() in redrat3_init_rc_dev() Rename a jump label in redrat3_init_rc_dev()
Delete two variables in redrat3_set_timeout()
Move a variable assignment in redrat3_set_timeout()
Adjust two checks for null pointers in redrat3_dev_probe() Combine substrings for six messages
drivers/media/rc/redrat3.c | 146 +++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 79 deletions(-)
Signature · 1 line
2.10.1
PATCH 1/18 RedRat3: Use kcalloc() in two functions
From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 08:35:57 +0200
* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/media/rc/redrat3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/rc/redrat3.c +4 -2
@@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)int rc =0 ;char *buffer; - buffer =kzalloc (sizeof (char ) * (RR3_FW_VERSION_LEN +1 ),GFP_KERNEL ); + buffer =kcalloc (RR3_FW_VERSION_LEN +1 ,sizeof (*buffer),GFP_KERNEL );if (!buffer) {dev_err (rr3->dev,"Memory allocation failure\n" );return ;
@@ -741,7 +741,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,/* rr3 will disable rc detector on transmit */ rr3->transmitting = true; - sample_lens =kzalloc (sizeof (int ) *RR3_DRIVER_MAXLENS ,GFP_KERNEL ); + sample_lens =kcalloc (RR3_DRIVER_MAXLENS , +sizeof (*sample_lens), +GFP_KERNEL );if (!sample_lens) { ret = -ENOMEM ; goto out;
Signature · 1 line
2.10.1
Joe Perches
maintainerRe: [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions
drivers/media/rc/redrat3.c
Quoted 1 line · SF Markus Elfring
drivers/media/rc/redrat3.c +0
-0
[]
drivers/media/rc/redrat3.c static void redrat3_get_firmware_rev(struct redrat3_dev *rr3) · line 555
Quoted 9 lines
drivers/media/rc/redrat3.c +1
-1@@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)int rc =0 ;char *buffer; - buffer =kzalloc (sizeof (char ) * (RR3_FW_VERSION_LEN +1 ),GFP_KERNEL ); + buffer =kcalloc (RR3_FW_VERSION_LEN +1 ,sizeof (*buffer),GFP_KERNEL );if (!buffer) {dev_err (rr3->dev,"Memory allocation failure\n" ); return;,
Markus, please stop being _so_ mechanical and use your brain a little too. By definition, sizeof(char) = 1.
This _really_ should be kzalloc(RR3_FW_VERSION_LEN + 1,...)
Re: [media] RedRat3: Use kcalloc() in two functions?
Quoted 4 lines
Markus, please stop being _so_ mechanical and use your brain a little too. By definition, sizeof(char) = 1.
This _really_ should be
kzalloc(RR3_FW_VERSION_LEN + 1,...)
Do you expect that function call examples like the following will be equivalent?
zbuffer = kzalloc(123, …); cbuffer = kcalloc(123, 1, …);
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/18 RedRat3: Move two assignments in redrat3_transmit_ir()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:25:57 +0200
Move the assignment for the data structure member "transmitting" and the local variable "curlencheck" behind the source code for memory allocations by this function.
--- drivers/media/rc/redrat3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/rc/redrat3.c +4 -4
@@ -727,7 +727,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,int ret, ret_len;int lencheck, cur_sample_len, pipe;int *sample_lens =NULL ; -u8 curlencheck =0 ; +u8 curlencheck;unsigned i, sendbuf_len;if (rr3->transmitting) {
@@ -738,9 +738,6 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,if (count >RR3_MAX_SIG_SIZE -RR3_TX_TRAILER_LEN )return -EINVAL ; -/* rr3 will disable rc detector on transmit */ - rr3->transmitting = true; - sample_lens =kcalloc (RR3_DRIVER_MAXLENS ,sizeof (*sample_lens),GFP_KERNEL );
@@ -755,6 +752,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, goto out; } +/* rr3 will disable rc detector on transmit */ + rr3->transmitting = true; + curlencheck =0 ;for (i =0 ; i < count; i++) { cur_sample_len =redrat3_us_to_len (txbuf[i]);if (cur_sample_len >0xffff ) {
Signature · 1 line
2.10.1
Re: [PATCH 02/18] [media] RedRat3: Move two assignments in redrat3_transmit_ir()
I have asked you about six or seven times to only send bug fixes and stop sending clean up patches. You have refused. But now I'm asking you to stop randomly doing things without at least thinking about it for a bit.
The original code was correct.
regards,
dan carpenter
Re: [media] RedRat3: Move two assignments in redrat3_transmit_ir()?
Quoted 1 line
The original code was correct.
Your view can be appropriate for this function implementation to some degree.
I got the impression that it contains the specification of assignments which will happen a bit too early here.
Is this a weakness for which software developers can care about?
Regards,
Markus
PATCH 3/18 RedRat3: Return directly after a failed kcalloc() in redrat3_transmit_ir()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:34:29 +0200
* Return directly after a call of the function "kcalloc" failed at the beginning.
* Reorder two calls for the function "kfree" at the end.
--- drivers/media/rc/redrat3.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/rc/redrat3.c +3 -5
@@ -741,10 +741,8 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, sample_lens =kcalloc (RR3_DRIVER_MAXLENS ,sizeof (*sample_lens),GFP_KERNEL ); -if (!sample_lens) { - ret = -ENOMEM ; - goto out; - } +if (!sample_lens) +return -ENOMEM ; irdata =kzalloc (sizeof (*irdata),GFP_KERNEL );if (!irdata) {
@@ -815,8 +813,8 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, ret = count; out: -kfree (sample_lens);kfree (irdata); +kfree (sample_lens); rr3->transmitting = false;/* rr3 re-enables rc detector because it was enabled before */
Signature · 1 line
2.10.1
PATCH 4/18 RedRat3: One function call less in redrat3_transmit_ir() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:50:24 +0200
The kfree() function was called in one case by the redrat3_transmit_ir() function during error handling even if the passed variable contained a null pointer.
* Adjust jump targets according to the Linux coding style convention.
* Move the resetting for the data structure member "transmitting" at the end.
* Delete initialisations for the variables "irdata" and "sample_lens" at the beginning which became unnecessary with this refactoring.
--- drivers/media/rc/redrat3.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/media/rc/redrat3.c +8 -10
@@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, {struct redrat3_dev *rr3 = rcdev->priv;struct device *dev = rr3->dev; -struct redrat3_irdata *irdata =NULL ; +struct redrat3_irdata *irdata;int ret, ret_len;int lencheck, cur_sample_len, pipe; -int *sample_lens =NULL ; +int *sample_lens;u8 curlencheck;unsigned i, sendbuf_len;
@@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, irdata =kzalloc (sizeof (*irdata),GFP_KERNEL );if (!irdata) { ret = -ENOMEM ; - goto out; + goto free_sample; }/* rr3 will disable rc detector on transmit */
@@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, curlencheck++; }else { ret = -EINVAL ; - goto out; + goto reset_member; } } irdata->sigdata[i] = lencheck;
@@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,dev_err (dev,"Error: control msg send failed, rc %d\n" , ret); else ret = count; - -out: -kfree (irdata); -kfree (sample_lens); - +reset_member: rr3->transmitting = false;/* rr3 re-enables rc detector because it was enabled before */ - +kfree (irdata); +free_sample: +kfree (sample_lens);return ret; }
Signature · 1 line
2.10.1
Sean Young
maintainerRe: [PATCH 04/18] [media] RedRat3: One function call less in redrat3_transmit_ir() after error detection
Quoted 61 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:50:24 +0200The
kfree()function was called in one case by theredrat3_transmit_ir()function during error handling even if the passed variable contained a null pointer.* Adjust jump targets according to the Linux coding style convention.
* Move the resetting for the data structure member "transmitting" at the end.
* Delete initialisations for the variables "irdata" and "
sample_lens" at the beginning which became unnecessary with this refactoring.Signed-off-by Markus Elfring <[email protected]>--- drivers/media/rc/redrat3.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/media/rc/redrat3.c +4
-6@@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, {struct redrat3_dev *rr3 = rcdev->priv;struct device *dev = rr3->dev; -struct redrat3_irdata *irdata =NULL ; +struct redrat3_irdata *irdata;int ret, ret_len;int lencheck, cur_sample_len, pipe; -int *sample_lens =NULL ; +int *sample_lens;u8 curlencheck;unsigned i, sendbuf_len;@@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, irdata =kzalloc (sizeof (*irdata),GFP_KERNEL );if (!irdata) { ret = -ENOMEM ; - goto out; + goto free_sample; }/* rr3 will disable rc detector on transmit */ @@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, curlencheck++; }else { ret = -EINVAL ; - goto out; + goto reset_member; } } irdata->sigdata[i] = lencheck;@@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,dev_err (dev,"Error: control msg send failed, rc %d\n" , ret); else ret = count; - -out:
drivers/media/rc/redrat3.c static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, · line 819
Quoted 10 lines
drivers/media/rc/redrat3.c +4
-4-kfree (irdata); -kfree (sample_lens); - +reset_member: rr3->transmitting = false;/* rr3 re-enables rc detector because it was enabled before */ - +kfree (irdata); +free_sample: +kfree (sample_lens);
In this error path, rr3->transmitting is not set to false so now the driver will never allow you transmit again.
Also this patch does not apply against latest.
Sean
Quoted 10 lines
drivers/media/rc/redrat3.c +0
-0return ret; }Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 04/18] [media] RedRat3: One function call less in redrat3_transmit_ir() after error detection
Quoted 45 lines
Quoted 45 lines
drivers/media/rc/redrat3.c +5
-9@@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, {struct redrat3_dev *rr3 = rcdev->priv;struct device *dev = rr3->dev; -struct redrat3_irdata *irdata =NULL ; +struct redrat3_irdata *irdata;int ret, ret_len;int lencheck, cur_sample_len, pipe; -int *sample_lens =NULL ; +int *sample_lens;u8 curlencheck;unsigned i, sendbuf_len;@@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, irdata =kzalloc (sizeof (*irdata),GFP_KERNEL );if (!irdata) { ret = -ENOMEM ; - goto out; + goto free_sample; }/* rr3 will disable rc detector on transmit */ @@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, curlencheck++; }else { ret = -EINVAL ; - goto out; + goto reset_member; } } irdata->sigdata[i] = lencheck;@@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,dev_err (dev,"Error: control msg send failed, rc %d\n" , ret); else ret = count; - -out: -kfree (irdata); -kfree (sample_lens); - +reset_member:
Quoted 8 lines
drivers/media/rc/redrat3.c static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, · line 819
Quoted 6 lines
drivers/media/rc/redrat3.c +3
-1rr3->transmitting = false;/* rr3 re-enables rc detector because it was enabled before */ - +kfree (irdata); +free_sample: +kfree (sample_lens);In this error path,
rr3->transmittingis not set to false
Can it be that this reset is not needed because it should have still got this value already in the software refactoring I proposed here?
Quoted 1 line
so now the driver will never allow you transmit again.
I have got an other impression.
Quoted 1 line
Also this patch does not apply against latest.
Do you want that I rebase my update suggestion for this software module on a published commit that is more recent than 2016-09-22 (d6ae162bd13998a6511e5efbc7c19ab542ba1555 for example)?
Regards,
Markus
PATCH 5/18 RedRat3: Delete six messages for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:20:19 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus remove such a logging statement in five functions.
--- drivers/media/rc/redrat3.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/media/rc/redrat3.c +6 -18
@@ -453,10 +453,8 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3) len =sizeof (*tmp); tmp =kzalloc (len,GFP_KERNEL ); -if (!tmp) { -dev_warn (rr3->dev,"Memory allocation faillure\n" ); +if (!tmp)return timeout; - } pipe =usb_rcvctrlpipe (rr3->udev,0 ); ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM,
@@ -518,10 +516,8 @@ static void redrat3_reset(struct redrat3_dev *rr3) txpipe =usb_sndctrlpipe (udev,0 ); val =kmalloc (len,GFP_KERNEL ); -if (!val) { -dev_err (dev,"Memory allocation failure\n" ); +if (!val)return ; - } *val =0x01 ; rc = usb_control_msg(udev, rxpipe, RR3_RESET,
@@ -550,10 +546,8 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)char *buffer; buffer =kcalloc (RR3_FW_VERSION_LEN +1 ,sizeof (*buffer),GFP_KERNEL ); -if (!buffer) { -dev_err (rr3->dev,"Memory allocation failure\n" ); +if (!buffer)return ; - } rc = usb_control_msg(rr3->udev, usb_rcvctrlpipe(rr3->udev, 0), RR3_FW_VERSION,
@@ -866,10 +860,8 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)u16 prod =le16_to_cpu (rr3->udev->descriptor.idProduct); rc =rc_allocate_device (); -if (!rc) { -dev_err (dev,"remote input dev allocation failed\n" ); +if (!rc) goto out; - } snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s " "Infrared Remote Transceiver (%04x:%04x)",
@@ -959,10 +951,8 @@ static int redrat3_dev_probe(struct usb_interface *intf,/* allocate memory for our device state and initialize it */ rr3 =kzalloc (sizeof (*rr3),GFP_KERNEL ); -if (rr3 =NULL ) { -dev_err (dev,"Memory allocation failure\n" ); +if (!rr3) goto no_endpoints; - } rr3->dev = &intf->dev;
@@ -974,10 +964,8 @@ static int redrat3_dev_probe(struct usb_interface *intf, rr3->ep_in = ep_in; rr3->bulk_in_buf =usb_alloc_coherent (udev,le16_to_cpu (ep_in->wMaxPacketSize),GFP_KERNEL , &rr3->dma_in); -if (!rr3->bulk_in_buf) { -dev_err (dev,"Read buffer allocation failure\n" ); +if (!rr3->bulk_in_buf) goto error; - } pipe =usb_rcvbulkpipe (udev, ep_in->bEndpointAddress); usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf,
Signature · 1 line
2.10.1
PATCH 6/18 RedRat3: Delete an unnecessary variable initialisation in redrat3_get_firmware_rev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:21:55 +0200
The local variable "rc" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/rc/redrat3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/redrat3.c +1 -1
@@ -542,7 +542,7 @@ static void redrat3_reset(struct redrat3_dev *rr3)static void redrat3_get_firmware_rev (struct redrat3_dev *rr3) { -int rc =0 ; +int rc;char *buffer; buffer =kcalloc (RR3_FW_VERSION_LEN +1 ,sizeof (*buffer),GFP_KERNEL );
Signature · 1 line
2.10.1
PATCH 7/18 RedRat3: Improve another size determination in redrat3_reset()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:23:22 +0200
Replace the specification of a data type by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/media/rc/redrat3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/redrat3.c +1 -1
@@ -510,7 +510,7 @@ static void redrat3_reset(struct redrat3_dev *rr3)struct device *dev = rr3->dev;int rc, rxpipe, txpipe;u8 *val; -int len =sizeof (u8); +size_t const len =sizeof (*val); rxpipe =usb_rcvctrlpipe (udev,0 ); txpipe =usb_sndctrlpipe (udev,0 );
Signature · 1 line
2.10.1
PATCH 8/18 RedRat3: Improve another size determination in redrat3_send_cmd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:31:17 +0200
Replace the specification of a data type by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.
--- drivers/media/rc/redrat3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/redrat3.c +1 -1
@@ -388,7 +388,7 @@ static int redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)u8 *data;int res; - data =kzalloc (sizeof (u8),GFP_KERNEL ); + data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;
Signature · 1 line
2.10.1
PATCH 9/18 RedRat3: Move a variable assignment in redrat3_dev_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:07:03 +0200
* One local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into three if branches to indicate a memory allocation failure there.
* Adjust a jump label according to the Linux coding style convention.
--- drivers/media/rc/redrat3.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/media/rc/redrat3.c +15 -9
@@ -912,7 +912,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,struct usb_endpoint_descriptor *ep_out =NULL ;u8 addr, attrs;int pipe, i; -int retval = -ENOMEM ; +int retval; uhi = intf->cur_altsetting;
@@ -951,21 +951,27 @@ static int redrat3_dev_probe(struct usb_interface *intf,/* allocate memory for our device state and initialize it */ rr3 =kzalloc (sizeof (*rr3),GFP_KERNEL ); -if (!rr3) +if (!rr3) { + retval = -ENOMEM ; goto no_endpoints; + } rr3->dev = &intf->dev;/* set up bulk-in endpoint */ rr3->read_urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!rr3->read_urb) - goto error; +if (!rr3->read_urb) { + retval = -ENOMEM ; + goto delete_rr; + } rr3->ep_in = ep_in; rr3->bulk_in_buf =usb_alloc_coherent (udev,le16_to_cpu (ep_in->wMaxPacketSize),GFP_KERNEL , &rr3->dma_in); -if (!rr3->bulk_in_buf) - goto error; +if (!rr3->bulk_in_buf) { + retval = -ENOMEM ; + goto delete_rr; + } pipe =usb_rcvbulkpipe (udev, ep_in->bEndpointAddress); usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf,
@@ -982,7 +988,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,/* might be all we need to do? */ retval =redrat3_enable_detector (rr3);if (retval <0 ) - goto error; + goto delete_rr;/* store current hardware timeout, in µs */ rr3->hw_timeout =redrat3_get_timeout (rr3);
@@ -996,7 +1002,7 @@ static int redrat3_dev_probe(struct usb_interface *intf, rr3->led.brightness_set = redrat3_brightness_set; retval =led_classdev_register (&intf->dev, &rr3->led);if (retval) - goto error; + goto delete_rr;atomic_set (&rr3->flash,0 ); rr3->flash_urb =usb_alloc_urb (0 ,GFP_KERNEL );
@@ -1028,7 +1034,7 @@ static int redrat3_dev_probe(struct usb_interface *intf, led_free_error:led_classdev_unregister (&rr3->led); -error: +delete_rr:redrat3_delete (rr3, rr3->udev); no_endpoints:
Signature · 6 lines
2.10.1 -- 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 10/18 RedRat3: Delete an unnecessary variable initialisation in redrat3_init_rc_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:17:43 +0200
The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/rc/redrat3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/redrat3.c +1 -1
@@ -856,7 +856,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) {struct device *dev = rr3->dev;struct rc_dev *rc; -int ret = -ENODEV ; +int ret;u16 prod =le16_to_cpu (rr3->udev->descriptor.idProduct); rc =rc_allocate_device ();
Signature · 1 line
2.10.1
PATCH 11/18 RedRat3: Delete the variable "dev" in redrat3_init_rc_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:40:11 +0200
Use the data structure member "dev" directly without assigning it to an intermediate variable.
Thus delete the extra variable definition at the beginning.
--- drivers/media/rc/redrat3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/rc/redrat3.c +2 -3
@@ -854,7 +854,6 @@ static void redrat3_led_complete(struct urb *urb)static struct rc_dev *redrat3_init_rc_dev (struct redrat3_dev *rr3) { -struct device *dev = rr3->dev;struct rc_dev *rc;int ret;u16 prod =le16_to_cpu (rr3->udev->descriptor.idProduct);
@@ -873,7 +872,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) rc->input_name = rr3->name; rc->input_phys = rr3->phys;usb_to_input_id (rr3->udev, &rc->input_id); - rc->dev.parent = dev; + rc->dev.parent = rr3->dev; rc->priv = rr3; rc->driver_type =RC_DRIVER_IR_RAW ; rc->allowed_protocols =RC_BIT_ALL ;
@@ -889,7 +888,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) ret =rc_register_device (rc);if (ret <0 ) { -dev_err (dev,"remote dev registration failed\n" ); +dev_err (rr3->dev,"remote dev registration failed\n" ); goto out; }
Signature · 1 line
2.10.1
PATCH 12/18 RedRat3: Move a variable assignment in redrat3_init_rc_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:50:05 +0200
Move the assignment for the local variable "prod" behind the source code for a memory allocation by this function.
--- drivers/media/rc/redrat3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/rc/redrat3.c +2 -1
@@ -856,12 +856,13 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) {struct rc_dev *rc;int ret; -u16 prod =le16_to_cpu (rr3->udev->descriptor.idProduct); +u16 prod; rc =rc_allocate_device ();if (!rc) goto out; + prod =le16_to_cpu (rr3->udev->descriptor.idProduct); snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s " "Infrared Remote Transceiver (%04x:%04x)", prod = USB_RR3IIUSB_PRODUCT_ID ? "-II" : "",
Signature · 1 line
2.10.1
Sean Young
maintainerRe: [PATCH 12/18] [media] RedRat3: Move a variable assignment in redrat3_init_rc_dev()
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:50:05 +0200Move the assignment for the local variable "prod" behind the source code for a memory allocation by this function.
The redrat3 driver shouldn't be adding the usb vendor/product id to the device name. A better patch would be to remove those from the snprintf completely and to away with the local variable.
Sean
Quoted 32 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/rc/redrat3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/rc/redrat3.c +2
-1@@ -856,12 +856,13 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) {struct rc_dev *rc;int ret; -u16 prod =le16_to_cpu (rr3->udev->descriptor.idProduct); +u16 prod; rc =rc_allocate_device ();if (!rc) goto out; + prod =le16_to_cpu (rr3->udev->descriptor.idProduct); snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s " "Infrared Remote Transceiver (%04x:%04x)", prod = USB_RR3IIUSB_PRODUCT_ID ? "-II" : "",Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 13/18 RedRat3: Return directly after a failed rc_allocate_device() in redrat3_init_rc_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:54:46 +0200
Return directly after a call of the function "rc_allocate_device" failed at the beginning.
--- drivers/media/rc/redrat3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/redrat3.c +1 -1
@@ -860,7 +860,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) rc =rc_allocate_device ();if (!rc) - goto out; +return NULL ; prod =le16_to_cpu (rr3->udev->descriptor.idProduct); snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
Signature · 1 line
2.10.1
PATCH 14/18 RedRat3: Rename a jump label in redrat3_init_rc_dev()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:00:12 +0200
Adjust a jump label according to the Linux coding style convention.
--- drivers/media/rc/redrat3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/rc/redrat3.c +2 -3
@@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) ret =rc_register_device (rc);if (ret <0 ) {dev_err (rr3->dev,"remote dev registration failed\n" ); - goto out; + goto free_device; }return rc; - -out: +free_device:rc_free_device (rc);return NULL ; }
Signature · 1 line
2.10.1
Re: [PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()
Em Thu, 13 Oct 2016 18:42:16 +0200
SF Markus Elfring <[email protected]> escreveu:
Quoted 19 lines
From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:00:12 +0200Adjust a jump label according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/rc/redrat3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/media/rc/redrat3.c +0
-1@@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) ret =rc_register_device (rc);if (ret <0 ) {dev_err (rr3->dev,"remote dev registration failed\n" ); - goto out;
drivers/media/rc/redrat3.c static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) · line 900
Quoted 10 lines
drivers/media/rc/redrat3.c +2
-2+ goto free_device; }return rc; - -out: +free_device:rc_free_device (rc);return NULL ; }
I don't see *any* sense on patches like this. Please don't flood me with useless patches like that.
I'll silently ignore any patches like this during my review.
Regards,
Mauro
Thanks,
Mauro
Re: [PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()
Em Fri, 18 Nov 2016 10:52:40 -0200
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 36 lines
Em Thu, 13 Oct 2016 18:42:16 +0200
SF Markus Elfring <[email protected]> escreveu:Quoted 19 lines
From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:00:12 +0200Adjust a jump label according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/rc/redrat3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/media/rc/redrat3.c +0
-1@@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) ret =rc_register_device (rc);if (ret <0 ) {dev_err (rr3->dev,"remote dev registration failed\n" ); - goto out;drivers/media/rc/redrat3.c static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3) · line 900
Quoted 10 lines
drivers/media/rc/redrat3.c +2
-2+ goto free_device; }return rc; - -out: +free_device:rc_free_device (rc);return NULL ; }I don't see *any* sense on patches like this. Please don't flood me with useless patches like that.
Quoted 1 line
I'll silently ignore any patches like this during my review.
Btw:
[PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()
Don't use CamelCase for the name of the driver. We don't use CamelCase inside the Kernel, as it violates its coding style. Also, it means nothing, as the name of this driver, and its c file is "redhat3".
Thanks,
Mauro
PATCH 15/18 RedRat3: Delete two variables in redrat3_set_timeout()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:40:33 +0200
* Use the data structure members "dev" and "udev" directly without assigning them to intermediate variables. Thus delete the extra variable definitions at the beginning.
* Fix indentation for the parameters of two function calls.
--- drivers/media/rc/redrat3.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/media/rc/redrat3.c +11 -9
@@ -476,8 +476,6 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)static int redrat3_set_timeout (struct rc_dev *rc_dev,unsigned int timeoutns) {struct redrat3_dev *rr3 = rc_dev->priv; -struct usb_device *udev = rr3->udev; -struct device *dev = rr3->dev;__be32 *timeout;int ret;
@@ -486,13 +484,17 @@ static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)return -ENOMEM ; *timeout =cpu_to_be32 (redrat3_us_to_len (timeoutns /1000 )); - ret =usb_control_msg (udev,usb_sndctrlpipe (udev,0 ),RR3_SET_IR_PARAM , -USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_OUT , -RR3_IR_IO_SIG_TIMEOUT ,0 , timeout,sizeof (*timeout), -HZ *25 ); -dev_dbg (dev,"set ir parm timeout %d ret 0x%02x\n" , -be32_to_cpu (*timeout), ret); - + ret =usb_control_msg (rr3->udev, +usb_sndctrlpipe (rr3->udev,0 ), +RR3_SET_IR_PARAM , +USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_OUT , +RR3_IR_IO_SIG_TIMEOUT , +0 , + timeout, +sizeof (*timeout), +HZ *25 ); +dev_dbg (rr3->dev,"set ir parm timeout %d ret 0x%02x\n" , +be32_to_cpu (*timeout), ret);if (ret =sizeof (*timeout)) { rr3->hw_timeout = timeoutns /1000 ; ret =0 ;
Signature · 1 line
2.10.1
PATCH 16/18 RedRat3: Move a variable assignment in redrat3_set_timeout()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:13:41 +0200
Move the assignment for the local variable "rr3" behind the source code for a memory allocation by this function.
--- drivers/media/rc/redrat3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/rc/redrat3.c +2 -1
@@ -475,7 +475,7 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)static int redrat3_set_timeout (struct rc_dev *rc_dev,unsigned int timeoutns) { -struct redrat3_dev *rr3 = rc_dev->priv; +struct redrat3_dev *rr3;__be32 *timeout;int ret;
@@ -484,6 +484,7 @@ static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)return -ENOMEM ; *timeout =cpu_to_be32 (redrat3_us_to_len (timeoutns /1000 )); + rr3 = rc_dev->priv; ret = usb_control_msg(rr3->udev, usb_sndctrlpipe(rr3->udev, 0), RR3_SET_IR_PARAM,
Signature · 1 line
2.10.1
PATCH 17/18 RedRat3: Adjust two checks for null pointers in redrat3_dev_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:40:34 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
--- drivers/media/rc/redrat3.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/rc/redrat3.c +2 -3
@@ -923,8 +923,7 @@ static int redrat3_dev_probe(struct usb_interface *intf, ep = &uhi->endpoint[i].desc; addr = ep->bEndpointAddress; attrs = ep->bmAttributes; - -if ((ep_in =NULL ) && +if (!ep_in && ((addr &USB_ENDPOINT_DIR_MASK ) =USB_DIR_IN ) && ((attrs &USB_ENDPOINT_XFERTYPE_MASK ) =USB_ENDPOINT_XFER_BULK )) {
@@ -935,7 +934,7 @@ static int redrat3_dev_probe(struct usb_interface *intf, ep_in = ep; } -if ((ep_out =NULL ) && +if (!ep_out && ((addr &USB_ENDPOINT_DIR_MASK ) =USB_DIR_OUT ) && ((attrs &USB_ENDPOINT_XFERTYPE_MASK ) =USB_ENDPOINT_XFER_BULK )) {
Signature · 6 lines
2.10.1 -- 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 18/18 RedRat3: Combine substrings for six messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:50:11 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
Thus fix the affected source code places.
--- drivers/media/rc/redrat3.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/media/rc/redrat3.c +7 -12
@@ -233,8 +233,7 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)/* Codes 0x20 through 0x2f are IR Firmware Errors */ case 0x20 : -pr_cont ("Initial signal pulse not long enough " -"to measure carrier frequency\n" ); +pr_cont ("Initial signal pulse not long enough to measure carrier frequency\n" );break ;case 0x21 :pr_cont ("Not enough length values allocated for signal\n" );
@@ -246,18 +245,15 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)pr_cont ("Too many signal repeats\n" );break ;case 0x28 : -pr_cont ("Insufficient memory available for IR signal " -"data memory allocation\n" ); +pr_cont ("Insufficient memory available for IR signal data memory allocation\n" );break ;case 0x29 : -pr_cont ("Insufficient memory available " -"for IrDa signal data memory allocation\n" ); +pr_cont ("Insufficient memory available for IrDa signal data memory allocation\n" );break ;/* Codes 0x30 through 0x3f are USB Firmware Errors */ case 0x30 : -pr_cont ("Insufficient memory available for bulk " -"transfer structure\n" ); +pr_cont ("Insufficient memory available for bulk transfer structure\n" );break ;/*
@@ -269,8 +265,7 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)pr_cont ("Signal capture has been terminated\n" );break ;case 0x41 : -pr_cont ("Attempt to set/get and unknown signal I/O " -"algorithm parameter\n" ); +pr_cont ("Attempt to set/get and unknown signal I/O algorithm parameter\n" );break ;case 0x42 :pr_cont ("Signal capture already started\n" );
@@ -866,8 +861,8 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)return NULL ; prod =le16_to_cpu (rr3->udev->descriptor.idProduct); -snprintf (rr3->name,sizeof (rr3->name),"RedRat3%s " -"Infrared Remote Transceiver (%04x:%04x)" , +snprintf (rr3->name,sizeof (rr3->name), +"RedRat3%s Infrared Remote Transceiver (%04x:%04x)" , prod =USB_RR3IIUSB_PRODUCT_ID ?"-II" :"" ,le16_to_cpu (rr3->udev->descriptor.idVendor), prod);
Signature · 1 line
2.10.1
cover winbond-cir: Fine-tuning for four function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 13:24:35 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Use kmalloc_array() in wbcir_tx()
Move a variable assignment in wbcir_tx()
Move assignments for three variables in wbcir_shutdown()
One variable and its check less in wbcir_shutdown() after error detection Move a variable assignment in two functions
drivers/media/rc/winbond-cir.c | 95 +++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 51 deletions(-)
Signature · 1 line
2.10.1
PATCH 1/5 winbond-cir: Use kmalloc_array() in wbcir_tx()
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:19:00 +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/media/rc/winbond-cir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/winbond-cir.c +1 -1
@@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)unsigned i;unsigned long flags; - buf =kmalloc (count *sizeof (*b),GFP_KERNEL ); + buf =kmalloc_array (count,sizeof (*b),GFP_KERNEL );if (!buf)return -ENOMEM ;
Signature · 1 line
2.10.1
David Härdeman
maintainerRe: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:19:00 +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]>
Sure...why not...
Quoted 19 lines
---
drivers/media/rc/winbond-cir.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/rc/winbond-cir.c +1
-1@@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)unsigned i;unsigned long flags; - buf =kmalloc (count *sizeof (*b),GFP_KERNEL ); + buf =kmalloc_array (count,sizeof (*b),GFP_KERNEL );if (!buf)return -ENOMEM ;Signature · 1 line
2.10.1
--
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/5 winbond-cir: Move a variable assignment in wbcir_tx()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:34:46 +0200
Move the assignment for the local variable "data" behind the source code for a memory allocation by this function.
--- drivers/media/rc/winbond-cir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/rc/winbond-cir.c +2 -1
@@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)static int wbcir_tx (struct rc_dev *dev,unsigned *b,unsigned count) { -struct wbcir_data *data = dev->priv; +struct wbcir_data *data;unsigned *buf;unsigned i;unsigned long flags;
@@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)for (i =0 ; i < count; i++) buf[i] =DIV_ROUND_CLOSEST (b[i],10 ); + data = dev->priv;/* Not sure if this is possible, but better safe than sorry */ spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {
Signature · 1 line
2.10.1
David Härdeman
maintainerRe: [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:34:46 +0200Move the assignment for the local variable "data" behind the source code for a memory allocation by this function.
Sorry, I can't see what the point is?
Quoted 28 lines
Signed-off-by Markus Elfring <[email protected]>---
drivers/media/rc/winbond-cir.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/rc/winbond-cir.c +0
-0@@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)static int
wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count){
- structwbcir_data*data =dev->priv;
+ structwbcir_data*data;
unsigned *buf;
unsigned i;
unsigned long flags;drivers/media/rc/winbond-cir.c +1
-0@@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)for (i =0 ; i < count; i++) buf[i] =DIV_ROUND_CLOSEST (b[i],10 ); + data = dev->priv;/* Not sure if this is possible, but better safe than sorry */ spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {Signature · 1 line
2.10.1
Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()
Quoted 4 lines
Quoted 2 lines
Move the assignment for the local variable "data" behind the source code for a memory allocation by this function.
Sorry, I can't see what the point is?
* How do you think about to avoid a variable assignment in case that this memory allocation failed anyhow?
* Do you care for data access locality?
Regards,
Markus
David Härdeman
maintainerRe: [media] winbond-cir: Move a variable assignment in wbcir_tx()
Quoted 7 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
Move the assignment for the local variable "data" behind the source code for a memory allocation by this function.
Sorry, I can't see what the point is?
* How do you think about to avoid a variable assignment in case that this memory allocation failed anyhow?
There is no memory allocation that can fail at this point.
Quoted 1 line
* Do you care for data access locality?
Not unless you can show measurable performance improvements?
Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()
Quoted 4 lines
Quoted 2 lines
* How do you think about to avoid a variable assignment in case that this memory allocation failed anyhow?
There is no memory allocation that can fail at this point.
Do you really know the failure probability for a call of the function "kmalloc" (within the function "wbcir_tx") under all possible run time situations?
Quoted 3 lines
Quoted 1 line
* Do you care for data access locality?
Not unless you can show measurable performance improvements?
Did any software developer (before me) dare anything in this direction?
Regards,
Markus
PATCH 3/5 winbond-cir: Move assignments for three variables in wbcir_shutdown()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 10:40:12 +0200
Move the setting for the local variables "mask", "match" and "rc6_csl" behind the source code for a condition check by this function at the beginning.
--- drivers/media/rc/winbond-cir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/rc/winbond-cir.c +4 -4
@@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)bool do_wake = true;u8 match[11 ];u8 mask[11 ]; -u8 rc6_csl =0 ; +u8 rc6_csl;int i; -memset (match,0 ,sizeof (match)); -memset (mask,0 ,sizeof (mask)); -if (wake_sc =INVALID_SCANCODE || !device_may_wakeup (dev)) { do_wake = false; goto finish; } + rc6_csl =0 ; +memset (match,0 ,sizeof (match)); +memset (mask,0 ,sizeof (mask));switch (protocol) {case IR_PROTOCOL_RC5 :if (wake_sc >0xFFF ) {
Signature · 1 line
2.10.1
David Härdeman
maintainerRe: [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 10:40:12 +0200Move the setting for the local variables "mask", "match" and "
rc6_csl" behind the source code for a condition check by this function at the beginning.
Again, I can't see what the point is?
Quoted 33 lines
Signed-off-by Markus Elfring <[email protected]>---
drivers/media/rc/winbond-cir.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/media/rc/winbond-cir.c +4
-4@@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)bool do_wake = true;u8 match[11 ];u8 mask[11 ]; -u8 rc6_csl =0 ; +u8 rc6_csl;int i; -memset (match,0 ,sizeof (match)); -memset (mask,0 ,sizeof (mask)); -if (wake_sc ==INVALID_SCANCODE || !device_may_wakeup (dev)) { do_wake = false; goto finish; } + rc6_csl =0 ; +memset (match,0 ,sizeof (match)); +memset (mask,0 ,sizeof (mask));switch (protocol) {case
IR_PROTOCOL_RC5:
if (wake_sc>0xFFF) {Signature · 1 line
2.10.1
Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Quoted 5 lines
Quoted 3 lines
Move the setting for the local variables "mask", "match" and "
rc6_csl" behind the source code for a condition check by this function at the beginning.Again, I can't see what the point is?
* How do you think about to set these variables only after the initial check succeded?
* Do you care for data access locality?
Regards,
Markus
David Härdeman
maintainerRe: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Quoted 8 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
Move the setting for the local variables "mask", "match" and "
rc6_csl" behind the source code for a condition check by this function at the beginning.Again, I can't see what the point is?
* How do you think about to set these variables only after the initial check succeded?
I prefer setting variables early so that no thinking about whether they're initialized or not is necessary later.
Quoted 1 line
* Do you care for data access locality?
Not unless you can show measurable performance improvements?
Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Move the setting for the local variables "mask", "match" and "
rc6_csl" behind the source code for a condition check by this function at the beginning.Again, I can't see what the point is?
* How do you think about to set these variables only after the initial check succeded?
I prefer setting variables early so that no thinking about whether they're initialized or not is necessary later.
* How do you think about to reduce the scope for these variables then?
* Would you dare to move the corresponding source code into a separate function?
Regards,
Markus
PATCH 4/5 winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 12:48:41 +0200
The local variable "do_wake" was set to "false" after an invalid system setting was detected so that a bit of error handling was triggered.
* Replace these assignments by direct jumps to the source code with the desired exception handling.
* Delete this status variable and a corresponding check which became unnecessary with this refactoring.
--- drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 44 deletions(-)
drivers/media/rc/winbond-cir.c +34 -44
@@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device) {struct device *dev = &device->dev;struct wbcir_data *data =pnp_get_drvdata (device); -bool do_wake = true;u8 match[11 ];u8 mask[11 ];u8 rc6_csl;int i; -if (wake_sc =INVALID_SCANCODE || !device_may_wakeup (dev)) { - do_wake = false; - goto finish; - } +if (wake_sc =INVALID_SCANCODE || !device_may_wakeup (dev)) + goto clear_bits; rc6_csl =0 ;memset (match,0 ,sizeof (match));
@@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)switch (protocol) {case IR_PROTOCOL_RC5 :if (wake_sc >0xFFF ) { - do_wake = false;dev_err (dev,"RC5 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Mask = 13 bits, ex toggle */
@@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)case IR_PROTOCOL_NEC :if (wake_sc >0xFFFFFF ) { - do_wake = false;dev_err (dev,"NEC - Invalid wake scancode\n" ); -break ; + goto clear_bits; } mask[0 ] = mask[1 ] = mask[2 ] = mask[3 ] =0xFF ;
@@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)if (wake_rc6mode =0 ) {if (wake_sc >0xFFFF ) { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Command */
@@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device) }else if (wake_sc <=0x007FFFFF ) { rc6_csl =60 ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Header */
@@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device) mask[i++] =0x0F ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake mode\n" ); + goto clear_bits; }break ;default : - do_wake = false; -break ; + goto clear_bits; } -finish: -if (do_wake) { -/* Set compare and compare mask */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); - -/* RC6 Compare String Len */ -outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); - -/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); +/* Set compare and compare mask */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); -/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* RC6 Compare String Len */ +outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); -/* Set CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); - - }else { -/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); +/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); -/* Clear CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); - } +/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* Set CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); +set_irqmask:/* * ACPI will set the HW disable bit for SP3 which means that the * output signals are left in an undefined state which may cause
@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/ wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask; } static int
Signature · 1 line
2.10.1
Sean Young
maintainerRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Quoted 156 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 12:48:41 +0200The local variable "
do_wake" was set to "false" after an invalid system setting was detected so that a bit of error handling was triggered.* Replace these assignments by direct jumps to the source code with the desired exception handling.
* Delete this status variable and a corresponding check which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 44 deletions(-)drivers/media/rc/winbond-cir.c +26
-44@@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device) {struct device *dev = &device->dev;struct wbcir_data *data =pnp_get_drvdata (device); -bool do_wake = true;u8 match[11 ];u8 mask[11 ];u8 rc6_csl;int i; -if (wake_sc =INVALID_SCANCODE || !device_may_wakeup (dev)) { - do_wake = false; - goto finish; - } +if (wake_sc =INVALID_SCANCODE || !device_may_wakeup (dev)) + goto clear_bits; rc6_csl =0 ;memset (match,0 ,sizeof (match));@@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)switch (protocol) {case IR_PROTOCOL_RC5 :if (wake_sc >0xFFF ) { - do_wake = false;dev_err (dev,"RC5 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Mask = 13 bits, ex toggle */ @@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)case IR_PROTOCOL_NEC :if (wake_sc >0xFFFFFF ) { - do_wake = false;dev_err (dev,"NEC - Invalid wake scancode\n" ); -break ; + goto clear_bits; } mask[0 ] = mask[1 ] = mask[2 ] = mask[3 ] =0xFF ;@@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)if (wake_rc6mode =0 ) {if (wake_sc >0xFFFF ) { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Command */ @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device) }else if (wake_sc <=0x007FFFFF ) { rc6_csl =60 ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Header */ @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device) mask[i++] =0x0F ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake mode\n" ); + goto clear_bits; }break ;default : - do_wake = false; -break ; + goto clear_bits; } -finish: -if (do_wake) { -/* Set compare and compare mask */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); - -/* RC6 Compare String Len */ -outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); - -/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); +/* Set compare and compare mask */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); -/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* RC6 Compare String Len */ +outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); -/* Set CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); - - }else { -/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); +/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); -/* Clear CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); - } +/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* Set CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); +set_irqmask:/* * ACPI will set the HW disable bit for SP3 which means that the * output signals are left in an undefined state which may cause @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/
drivers/media/rc/winbond-cir.c wbcir_shutdown(struct pnp_dev *device) · line 868
Quoted 10 lines
drivers/media/rc/winbond-cir.c +8
-0wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask;
I'm not convinced that adding a goto which goes backwards is making this code any more readible, just so that a local variable can be dropped.
Sean
Quoted 10 lines
drivers/media/rc/winbond-cir.c +0
-0} static intSignature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Quoted 13 lines
Quoted 13 lines
drivers/media/rc/winbond-cir.c +6
-0+/* Set CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); +set_irqmask:/* * ACPI will set the HW disable bit for SP3 which means that the * output signals are left in an undefined state which may cause @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/ wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
Quoted 8 lines
drivers/media/rc/winbond-cir.c wbcir_shutdown(struct pnp_dev *device) · line 868
Quoted 5 lines
drivers/media/rc/winbond-cir.c +5
-0+wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask;I'm not convinced that adding a goto which goes backwards is making this code any more readible, just so that a local variable can be dropped.
Thanks for your feedback.
Is such a "backward jump" usual and finally required when you would like to move a bit of common error handling code to the end without using extra local variables and a few statements should still be performed after it?
Regards,
Markus
David Härdeman
maintainerRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Quoted 22 lines · SF Markus Elfring
Quoted 13 lines
Quoted 13 lines
+ /* Set
CEIR_EN*/
+wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01); +set_irqmask:
/*
* ACPI will set the HW disable bit for SP3 which means that the
* output signals are left in an undefined state which may causedrivers/media/rc/winbond-cir.c +3
-0@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/ wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ Quoted 8 lines
drivers/media/rc/winbond-cir.c wbcir_shutdown(struct pnp_dev *device) · line 868
Quoted 5 lines
drivers/media/rc/winbond-cir.c +5
-0+wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask;I'm not convinced that adding a goto which goes backwards is making this code any more readible, just so that a local variable can be dropped.
Quoted 6 lines
Thanks for your feedback.
Is such a "backward jump" usual and finally required when you would like to move a bit of common error handling code to the end without using extra local variables and a few statements should still be performed after it?
I'm sorry, I can't parse this.
Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
+ /* Set
CEIR_EN*/
+wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01); +set_irqmask:
/*
* ACPI will set the HW disable bit for SP3 which means that the
* output signals are left in an undefined state which may causedrivers/media/rc/winbond-cir.c +0
-0@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/ drivers/media/rc/winbond-cir.c wbcir_shutdown(struct pnp_dev *device) · line 868
Quoted 10 lines
drivers/media/rc/winbond-cir.c +8
-0wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask;I'm not convinced that adding a goto which goes backwards is making this code any more readible, just so that a local variable can be dropped.
Quoted 8 lines
Quoted 6 lines
Thanks for your feedback.
Is such a "backward jump" usual and finally required when you would like to move a bit of common error handling code to the end without using extra local variables and a few statements should still be performed after it?
I'm sorry, I can't parse this.
Can an other update suggestion like "[PATCH 6/6] crypto-caamhash:
Move common error handling code in two functions" explain this technique a bit better in principle?
https://patchwork.kernel.org/patch/9333861/
https://lkml.kernel.org/r/<[email protected]>
Regards,
Markus
David Härdeman
maintainerRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
In reply to Sean YoungQuoted 163 lines · Sean Young
Quoted 161 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 12:48:41 +0200The local variable "
do_wake" was set to "false" after an invalid system setting was detected so that a bit of error handling was triggered.* Replace these assignments by direct jumps to the source code with the desired exception handling.
* Delete this status variable and a corresponding check which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>---
drivers/media/rc/winbond-cir.c| 78 ++++++++++++++++++------------------------1 file changed, 34 insertions(+), 44 deletions(-)drivers/media/rc/winbond-cir.c +2
-5@@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device) {struct device *dev = &device->dev;struct wbcir_data *data =pnp_get_drvdata (device); -bool do_wake = true;u8 match[11 ];u8 mask[11 ];u8 rc6_csl;int i; -if (wake_sc ==INVALID_SCANCODE || !device_may_wakeup (dev)) { - do_wake = false; - goto finish; - } +if (wake_sc ==INVALID_SCANCODE || !device_may_wakeup (dev)) + goto clear_bits; rc6_csl =0 ;memset (match,0 ,sizeof (match));@@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)switch (protocol) {case
IR_PROTOCOL_RC5:
if (wake_sc>0xFFF) {
-do_wake= false;dev_err(dev, "RC5 - Invalid wake scancode\n");
- break;
+ gotoclear_bits;
}/* Mask = 13 bits, ex toggle */
drivers/media/rc/winbond-cir.c +0
-0@@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)case
IR_PROTOCOL_NEC:
if (wake_sc>0xFFFFFF) {
-do_wake= false;dev_err(dev, "NEC - Invalid wake scancode\n");
- break;
+ gotoclear_bits;
}mask[0] = mask[1] = mask[2] = mask[3] =
0xFF;drivers/media/rc/winbond-cir.c +3
-5@@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)if (wake_rc6mode ==0 ) {if (wake_sc >0xFFFF ) { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Command */ @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device) }else if (wake_sc <=0x007FFFFF ) { rc6_csl =60 ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake scancode\n" ); -break ; + goto clear_bits; }/* Header */ @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device) mask[i++] =0x0F ; }else { - do_wake = false;dev_err (dev,"RC6 - Invalid wake mode\n" ); + goto clear_bits; }break ;default:
-do_wake= false;
- break;
+ gotoclear_bits;
}drivers/media/rc/winbond-cir.c +18
-28-finish: -if (do_wake) { -/* Set compare and compare mask */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , -WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , -0x3F ); -outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); - -/* RC6 Compare String Len */ -outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); - -/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); +/* Set compare and compare mask */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_COMPARE |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , match,11 ); +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_INDEX , +WBCIR_REGSEL_MASK |WBCIR_REG_ADDR0 , +0x3F ); +outsb (data->wbase +WBCIR_REG_WCEIR_DATA , mask,11 ); -/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* RC6 Compare String Len */ +outb (rc6_csl, data->wbase +WBCIR_REG_WCEIR_CSL ); -/* Set CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); - - }else { -/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); +/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_STS ,0x17 ,0x17 ); -/* Clear CEIR_EN */ -wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); - } +/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x01 ,0x07 ); +/* Set CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x01 ,0x01 ); +set_irqmask:/*
* ACPI will set the HW disable bit for SP3 which means that the
* output signals are left in an undefined state which may causedrivers/media/rc/winbond-cir.c +3
-0@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)*/ wbcir_set_irqmask (data,WBCIR_IRQ_NONE );disable_irq (data->irq); +return ; +clear_bits: +/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
Quoted 9 lines
drivers/media/rc/winbond-cir.c wbcir_shutdown(struct pnp_dev *device) · line 868
Quoted 5 lines
drivers/media/rc/winbond-cir.c +5
-0+wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 ); + +/* Clear CEIR_EN */ +wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_CTL ,0x00 ,0x01 ); + goto set_irqmask;I'm not convinced that adding a goto which goes backwards is making this code any more readible, just so that a local variable can be dropped.
Agreed.
PATCH 5/5 winbond-cir: Move a variable assignment in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 13:13:11 +0200
Move the assignment for the local variable "data" behind the source code for condition checks by these functions.
--- drivers/media/rc/winbond-cir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/rc/winbond-cir.c +4 -2
@@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)static int wbcir_txcarrier (struct rc_dev *dev,u32 carrier) { -struct wbcir_data *data = dev->priv; +struct wbcir_data *data;unsigned long flags;u8 val;u32 freq;
@@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)break ; } + data = dev->priv;spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {spin_unlock_irqrestore (&data->spinlock, flags);
@@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)static int wbcir_txmask (struct rc_dev *dev,u32 mask) { -struct wbcir_data *data = dev->priv; +struct wbcir_data *data;unsigned long flags;u8 val;
@@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)return -EINVAL ; } + data = dev->priv;spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {spin_unlock_irqrestore (&data->spinlock, flags);
Signature · 1 line
2.10.1
David Härdeman
maintainerRe: [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 13:13:11 +0200Move the assignment for the local variable "data" behind the source code for condition checks by these functions.
Why?
Quoted 45 lines
Signed-off-by Markus Elfring <[email protected]>---
drivers/media/rc/winbond-cir.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/media/rc/winbond-cir.c +0
-0@@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)static int
wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
{
- structwbcir_data*data =dev->priv;
+ structwbcir_data*data;
unsigned long flags;
u8 val;
u32 freq;drivers/media/rc/winbond-cir.c +1
-0@@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)break ; } + data = dev->priv;spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {spin_unlock_irqrestore (&data->spinlock, flags);@@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)static int
wbcir_txmask(struct rc_dev *dev, u32 mask)
{
- structwbcir_data*data =dev->priv;
+ structwbcir_data*data;
unsigned long flags;
u8 val;drivers/media/rc/winbond-cir.c +1
-0@@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)return -EINVAL ; } + data = dev->priv;spin_lock_irqsave (&data->spinlock, flags);if (data->txstate !=WBCIR_TXSTATE_INACTIVE ) {spin_unlock_irqrestore (&data->spinlock, flags);Signature · 1 line
2.10.1
Re: [media] winbond-cir: Move a variable assignment in two functions
Quoted 4 lines
Quoted 2 lines
Move the assignment for the local variable "data" behind the source code for condition checks by these functions.
Why?
* Would you like to set these variables only after the initial check succeeded?
* Do you care for data access locality also in these cases?
Regards,
Markus