Staging: speakup: Misc cleanups and code reformatting.
cover Staging: speakup: Misc cleanups and code reformatting.
Changes to clear multiple Checkpatch.pl CHECKs of reformatting multiple assignments, proper use of kmalloc(), and adding identifier names to function declaration arguments.
All modifications made to match coding style and
to improve readability.
Sam Muhammed (3):
Staging: speakup: Avoid multiple assignments.
Staging: speakup: Use sizeof(*var) in kmalloc().
Staging: speakup: Add identifier name to function declaration
arguments.
drivers/staging/speakup/main.c | 18 ++++++++++++------ drivers/staging/speakup/spk_ttyio.c | 2 +- drivers/staging/speakup/spk_types.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-)
---
2.20.1
PATCH 1/3 Staging: speakup: Avoid multiple assignments.
Modify the code to avoid multiple assignments by just doing the assignment in two steps.
Checkpatch.pl CHECK: multiple assignments should be avoided.
--- drivers/staging/speakup/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/speakup/main.c +12 -6
@@ -263,9 +263,12 @@ static unsigned char get_attributes(struct vc_data *vc, u16 *pos)static void speakup_date (struct vc_data *vc) { - spk_x = spk_cx = vc->vc_x; - spk_y = spk_cy = vc->vc_y; - spk_pos = spk_cp = vc->vc_pos; + spk_cx = vc->vc_x; + spk_x = spk_cx; + spk_cy = vc->vc_y; + spk_y = spk_cy; + spk_cp = vc->vc_pos; + spk_pos = spk_cp; spk_old_attr = spk_attr; spk_attr =get_attributes (vc, (u_short *)spk_pos); }
@@ -1672,9 +1675,12 @@ static int speak_highlight(struct vc_data *vc)spk_do_flush ();spkup_write (speakup_console[vc_num]->ht.highbuf[hc], speakup_console[vc_num]->ht.highsize[hc]); - spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc]; - spk_x = spk_cx = speakup_console[vc_num]->ht.rx[hc]; - spk_y = spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_cp = speakup_console[vc_num]->ht.rpos[hc]; + spk_pos = spk_cp; + spk_cx = speakup_console[vc_num]->ht.rx[hc]; + spk_x = spk_cx; + spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_y = spk_cy;return 1 ; }return 0 ;
---
2.20.1
PATCH 2/3 Staging: speakup: Use sizeof(*var) in kmalloc().
In reply to Sam MuhammedModifying struct allocation in kmalloc() to match the coding standards.
Checkpatch.pl CHECK: Prefer kmalloc(sizeof(*ldisc_data)...) over kmalloc(sizeof(struct spk_ldisc_data)...)
--- drivers/staging/speakup/spk_ttyio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/spk_ttyio.c +1 -1
@@ -51,7 +51,7 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)return -EOPNOTSUPP ; speakup_tty = tty; - ldisc_data =kmalloc (sizeof (struct spk_ldisc_data ),GFP_KERNEL ); + ldisc_data =kmalloc (sizeof (*ldisc_data),GFP_KERNEL );if (!ldisc_data)return -ENOMEM ;
---
2.20.1
PATCH 3/3 Staging: speakup: Add identifier name to function declaration arguments.
In reply to Sam MuhammedThe void (*read_buff_add) argument didn't have an identifier name, adding an identifier name to match coding style.
Checkpatch.pl CHECK: function definition argument 'u_char' should also have an identifier name.
--- drivers/staging/speakup/spk_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/spk_types.h +1 -1
@@ -189,7 +189,7 @@ struct spk_synth {void (*flush)(struct spk_synth *synth);int (*is_alive)(struct spk_synth *synth);int (*synth_adjust)(struct st_var_header *var); -void (*read_buff_add)(u_char ); +void (*read_buff_add)(u_char c);unsigned char (*get_index)(struct spk_synth *synth);struct synth_indexing indexing;int alive;
---
2.20.1
Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.
In reply to Sam MuhammedHello,
Sam Muhammed, le lun. 23 mars 2020 17:38:43 -0400, a ecrit:
Quoted 2 lines
Modify the code to avoid multiple assignments by just doing the assignment in two steps.
The original version of the code is considered easier to read. Yes, the tools say multiple assignments should be avoided, but that's not a strict rule :)
Quoted 44 lines
Signed-off-by Sam Muhammed <[email protected]>--- drivers/staging/speakup/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/staging/speakup/main.c +12
-7@@ -263,9 +263,12 @@ static unsigned char get_attributes(struct vc_data *vc, u16 *pos)static void speakup_date (struct vc_data *vc) { - spk_x = spk_cx = vc->vc_x; - spk_y = spk_cy = vc->vc_y; - spk_pos = spk_cp = vc->vc_pos; + spk_cx = vc->vc_x; + spk_x = spk_cx; + spk_cy = vc->vc_y; + spk_y = spk_cy; + spk_cp = vc->vc_pos; + spk_pos = spk_cp; spk_old_attr = spk_attr; spk_attr =get_attributes (vc, (u_short *)spk_pos); }@@ -1672,9 +1675,12 @@ static int speak_highlight(struct vc_data *vc)spk_do_flush ();spkup_write (speakup_console[vc_num]->ht.highbuf[hc], speakup_console[vc_num]->ht.highsize[hc]); - spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc]; - spk_x = spk_cx = speakup_console[vc_num]->ht.rx[hc]; - spk_y = spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_cp = speakup_console[vc_num]->ht.rpos[hc]; + spk_pos = spk_cp; + spk_cx = speakup_console[vc_num]->ht.rx[hc]; + spk_x = spk_cx; + spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_y = spk_cy;return 1 ; }return 0 ; ---2.20.1
Re: [PATCH 2/3] Staging: speakup: Use sizeof(*var) in kmalloc().
In reply to Sam MuhammedSam Muhammed, le lun. 23 mars 2020 17:38:44 -0400, a ecrit:
Quoted 7 lines
Modifying struct allocation in
kmalloc()to match the coding standards.Checkpatch.pl CHECK: Prefer kmalloc(sizeof(*ldisc_data)...) over
kmalloc(sizeof(struct spk_ldisc_data)...)Signed-off-by Sam Muhammed <[email protected]>
Thanks!
Quoted 20 lines
--- drivers/staging/speakup/spk_ttyio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/speakup/spk_ttyio.c +1
-2@@ -51,7 +51,7 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)return -EOPNOTSUPP ; speakup_tty = tty; - ldisc_data =kmalloc (sizeof (struct spk_ldisc_data ),GFP_KERNEL ); + ldisc_data =kmalloc (sizeof (*ldisc_data),GFP_KERNEL );if (!ldisc_data)return -ENOMEM ; ---2.20.1
Re: [PATCH 3/3] Staging: speakup: Add identifier name to function declaration arguments.
In reply to Sam MuhammedSam Muhammed, le lun. 23 mars 2020 17:38:45 -0400, a ecrit:
Quoted 7 lines
The void (
*read_buff_add) argument didn't have an identifier name, adding an identifier name to match coding style.Checkpatch.pl CHECK: function definition argument '
u_char' should also have an identifier name.Signed-off-by Sam Muhammed <[email protected]>
Quoted 20 lines
--- drivers/staging/speakup/spk_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/speakup/spk_types.h +1
-2@@ -189,7 +189,7 @@ struct spk_synth {void (*flush)(struct spk_synth *synth);int (*is_alive)(struct spk_synth *synth);int (*synth_adjust)(struct st_var_header *var); -void (*read_buff_add)(u_char ); +void (*read_buff_add)(u_char c);unsigned char (*get_index)(struct spk_synth *synth);struct synth_indexing indexing;int alive; ---2.20.1
Re: [Outreachy kernel] Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.
In reply to Samuel ThibaultQuoted 9 lines · Samuel Thibault
Hello,
Sam Muhammed, le lun. 23 mars 2020 17:38:43 -0400, a ecrit:
Quoted 2 lines
Modify the code to avoid multiple assignments by just doing the assignment in two steps.
The original version of the code is considered easier to read. Yes, the tools say multiple assignments should be avoided, but that's not a strict rule :)
Well yes! this got me a bit hesitant, but what got me encouraged to make this change is that i looked for patches for the same change in this driver and i found this commit:
f23519843b01fdc266dd70ca29ef0f0a54f8b064
which was applied for the same file main.c, so i thought this driver adopted this style, maintaining a common practice?
should i revert this change and drop it from the patchset?
Thank you!
Sam
Quoted 46 lines
Quoted 45 lines
Signed-off-by Sam Muhammed <[email protected]>--- drivers/staging/speakup/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/staging/speakup/main.c +12
-7@@ -263,9 +263,12 @@ static unsigned char get_attributes(struct vc_data *vc, u16 *pos)static void speakup_date (struct vc_data *vc) { - spk_x = spk_cx = vc->vc_x; - spk_y = spk_cy = vc->vc_y; - spk_pos = spk_cp = vc->vc_pos; + spk_cx = vc->vc_x; + spk_x = spk_cx; + spk_cy = vc->vc_y; + spk_y = spk_cy; + spk_cp = vc->vc_pos; + spk_pos = spk_cp; spk_old_attr = spk_attr; spk_attr =get_attributes (vc, (u_short *)spk_pos); }@@ -1672,9 +1675,12 @@ static int speak_highlight(struct vc_data *vc)spk_do_flush ();spkup_write (speakup_console[vc_num]->ht.highbuf[hc], speakup_console[vc_num]->ht.highsize[hc]); - spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc]; - spk_x = spk_cx = speakup_console[vc_num]->ht.rx[hc]; - spk_y = spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_cp = speakup_console[vc_num]->ht.rpos[hc]; + spk_pos = spk_cp; + spk_cx = speakup_console[vc_num]->ht.rx[hc]; + spk_x = spk_cx; + spk_cy = speakup_console[vc_num]->ht.ry[hc]; + spk_y = spk_cy;return 1 ; }return 0 ; ---2.20.1
Re: [Outreachy kernel] Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.
Sam Muhammed, le lun. 23 mars 2020 19:13:16 -0400, a ecrit:
Quoted 11 lines · Samuel Thibault
Quoted 9 lines
Hello,
Sam Muhammed, le lun. 23 mars 2020 17:38:43 -0400, a ecrit:
Quoted 2 lines
Modify the code to avoid multiple assignments by just doing the assignment in two steps.
The original version of the code is considered easier to read. Yes, the tools say multiple assignments should be avoided, but that's not a strict rule :)
Quoted 8 lines
Well yes! this got me a bit hesitant, but what got me encouraged to make this change is that i looked for patches for the same change in this driver and i found this commit:
f23519843b01fdc266dd70ca29ef0f0a54f8b064which was applied for the same file
main.c, so i thought this driver adopted this style, maintaining a common practice?
This is a quite different beast:
- value = spk_lastkey = pad_chars[value]; + value = pad_chars[value]; + spk_lastkey = value;
there is not much in common between "value" and "spk_lastkey", and much more in common between spk_lastkey and the other spk_* assignments below.
Quoted 9 lines
Quoted 9 lines
drivers/staging/speakup/main.c static unsigned char get_attributes(struct vc_data *vc, u16 *pos) · line 271
Quoted 9 lines
drivers/staging/speakup/main.c +6
-3- spk_x = spk_cx = vc->vc_x; - spk_y = spk_cy = vc->vc_y; - spk_pos = spk_cp = vc->vc_pos; + spk_cx = vc->vc_x; + spk_x = spk_cx; + spk_cy = vc->vc_y; + spk_y = spk_cy; + spk_cp = vc->vc_pos; + spk_pos = spk_cp;
Here, there is a lot in common between spk_x and spk_cx, the current form makes it obvious that we are setting two x variables to vc_x. The proposed form make its much less clear.
Quoted 1 line
should i revert this change and drop it from the patchset?
Please drop patch 1 from the 3 yes.
Samuel
Re: [Outreachy kernel] Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.
Quoted 32 lines · Samuel Thibault
Sam Muhammed, le lun. 23 mars 2020 19:13:16 -0400, a ecrit:
Quoted 11 lines · Samuel Thibault
Quoted 9 lines
Hello,
Sam Muhammed, le lun. 23 mars 2020 17:38:43 -0400, a ecrit:
Quoted 2 lines
Modify the code to avoid multiple assignments by just doing the assignment in two steps.
The original version of the code is considered easier to read. Yes, the tools say multiple assignments should be avoided, but that's not a strict rule :)
Quoted 8 lines
Well yes! this got me a bit hesitant, but what got me encouraged to make this change is that i looked for patches for the same change in this driver and i found this commit:
f23519843b01fdc266dd70ca29ef0f0a54f8b064which was applied for the same file
main.c, so i thought this driver adopted this style, maintaining a common practice?This is a quite different beast:
(quoted diff) +2
-1- value = spk_lastkey = pad_chars[value]; + value = pad_chars[value]; + spk_lastkey = value;there is not much in common between "value" and "
spk_lastkey", and much more in common betweenspk_lastkeyand the other spk_* assignments below.
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
drivers/staging/speakup/main.c static unsigned char get_attributes(struct vc_data *vc, u16 *pos) · line 271
Quoted 9 lines
drivers/staging/speakup/main.c +6
-3- spk_x = spk_cx = vc->vc_x; - spk_y = spk_cy = vc->vc_y; - spk_pos = spk_cp = vc->vc_pos; + spk_cx = vc->vc_x; + spk_x = spk_cx; + spk_cy = vc->vc_y; + spk_y = spk_cy; + spk_cp = vc->vc_pos; + spk_pos = spk_cp;Here, there is a lot in common between
spk_xandspk_cx, the current form makes it obvious that we are setting two x variables tovc_x. The proposed form make its much less clear.
Oh, now iam pretty sure about it :)
Thank You!
Sam
Quoted 7 lines
Quoted 2 lines
should i revert this change and drop it from the patchset?
Please drop patch 1 from the 3 yes.
Samuel