Skip to contentSkip to conversation

Staging: speakup: Misc cleanups and code reformatting.

PATCH Superseded Sam Muhammed 2 participants 10 messages Mar 23, 2020 Staging

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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
index 02471d932d71..6efa0b245bef 100644
@@ -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

#6 lore raw

PATCH 2/3 Staging: speakup: Use sizeof(*var) in kmalloc().

In reply to Sam Muhammed

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)...)

---
 drivers/staging/speakup/spk_ttyio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/spk_ttyio.c +1 -1
index 5a9eff08cb96..9b95f77f9265 100644
@@ -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

#8 lore raw

PATCH 3/3 Staging: speakup: Add identifier name to function declaration arguments.

In reply to Sam Muhammed

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.

---
 drivers/staging/speakup/spk_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/spk_types.h +1 -1
index a2fc72c29894..fc6a9416829c 100644
@@ -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

#2 lore raw

Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.

In reply to Sam Muhammed

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 44 lines
---
 drivers/staging/speakup/main.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/speakup/main.c +12 -7
index 02471d932d71..6efa0b245bef 100644
@@ -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

Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] Staging: speakup: Use sizeof(*var) in kmalloc().

In reply to Sam Muhammed

Sam 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)...)

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
index 5a9eff08cb96..9b95f77f9265 100644
@@ -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

Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] Staging: speakup: Add identifier name to function declaration arguments.

In reply to Sam Muhammed

Sam 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.

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
index a2fc72c29894..fc6a9416829c 100644
@@ -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

#3 lore raw

Re: [Outreachy kernel] Re: [PATCH 1/3] Staging: speakup: Avoid multiple assignments.

In reply to Samuel Thibault
Quoted 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
---
 drivers/staging/speakup/main.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/speakup/main.c +12 -7
index 02471d932d71..6efa0b245bef 100644
@@ -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

#4 lore raw

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:

	f23519843b01fdc266dd70ca29ef0f0a54f8b064

which 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

#5 lore raw

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:

	f23519843b01fdc266dd70ca29ef0f0a54f8b064

which 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 between spk_lastkey and 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_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.

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