Skip to contentSkip to conversation

staging: fbtft: code cleanup patchset - checkpatch

PATCH Superseded Deepak R Varma 2 participants 9 messages Mar 13, 2020 – Mar 15, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover staging: fbtft: code cleanup patchset - checkpatch

Implement code formatting corrections as flagged by checkpatch script. Common issues around lines exceeding 80 column limit and similar formatting issues for the fbtft driver files are considered in the scope of this patchset.

Note that top two patches in the list below were sent to the mailing list for review as individual patches earlier. As I found additional similar issues in the same area, I am requesting to combine these related pathes in this patchset.

Changes from v1:
- Corrections suggested by Julia for [patch 4 /4]:
1. Update commit message - use word "potential" in place of "likely".
2. Update log message - use word "parentheses" in place of "braces".
3. Rephrase log message - make it concise and easy to understand.

Deepak R Varma (4):
staging: fbtft: Reformat line over 80 characters
staging: fbtft: Reformat long macro definitions
staging: fbtft: simplify array index computation
staging: fbtft: Avoid potential precedence issues

 drivers/staging/fbtft/fbtft-core.c  |  4 +++-
 drivers/staging/fbtft/fbtft-sysfs.c |  6 +++++-
 drivers/staging/fbtft/fbtft.h       | 18 +++++++++++++-----
 3 files changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/4 staging: fbtft: Reformat line over 80 characters

A long variable name beyond 80 characters gets exended into the next line. Reformating the line makes it more readable. Also adding an extra line for the next instruction following current if block helps understand it better.

---
 drivers/staging/fbtft/fbtft-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/fbtft/fbtft-core.c +3 -1
index d3e098b41b1a..4f362dad4436 100644
@@ -1186,7 +1186,9 @@ static struct fbtft_platform_data *fbtft_properties_read(struct device *dev)
 	if (device_property_present(dev, "led-gpios"))
 		pdata->display.backlight = 1;
 	if (device_property_present(dev, "init"))
-		pdata->display.fbtftops.init_display = fbtft_init_display_from_property;
+		pdata->display.fbtftops.init_display =
+			fbtft_init_display_from_property;
+
 	pdata->display.fbtftops.request_gpios = fbtft_request_gpios;
 
 	return pdata;
Signature · 1 line
2.17.1
#2 lore raw

Re: [Outreachy kernel] [PATCH v2 1/4] staging: fbtft: Reformat line over 80 characters

Looks good to me, just a few typos I wouldn't normally care about (unless a patch is fixing typos), but as you might re-post this:

Quoted 1 line · On Fri, 13 Mar 2020 19:12:13 +0530 Deepak R Varma <[email protected]> wrote:

A long variable name beyond 80 characters gets exended into the next

extended

Quoted 1 line

line. Reformating the line makes it more readable. Also adding an extra

Reformatting

Signature · 1 line
Stefano
#3 lore raw

PATCH v2 2/4 staging: fbtft: Reformat long macro definitions

In reply to Deepak R Varma

Multiple macro definitions crossings 80 character line length nakes it hard to understand. Reformating the these lines makes the code more readable and easy to understand. Issue flagged by checkpatch script.

---
 drivers/staging/fbtft/fbtft.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fbtft.h +11 -3
index 5f782da51959..81da30f4062e 100644
@@ -348,9 +348,17 @@ module_exit(fbtft_driver_module_exit);
 
 /* shorthand debug levels */
 #define DEBUG_LEVEL_1	DEBUG_REQUEST_GPIOS
-#define DEBUG_LEVEL_2	(DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS | DEBUG_TIME_FIRST_UPDATE)
-#define DEBUG_LEVEL_3	(DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY | DEBUG_BLANK | DEBUG_REQUEST_GPIOS | DEBUG_FREE_GPIOS | DEBUG_VERIFY_GPIOS | DEBUG_BACKLIGHT | DEBUG_SYSFS)
-#define DEBUG_LEVEL_4	(DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE | DEBUG_FB_FILLRECT | DEBUG_FB_COPYAREA | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
+#define DEBUG_LEVEL_2	(DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS        \
+				       | DEBUG_TIME_FIRST_UPDATE)
+#define DEBUG_LEVEL_3	(DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY   \
+				       | DEBUG_BLANK | DEBUG_REQUEST_GPIOS  \
+				       | DEBUG_FREE_GPIOS                   \
+				       | DEBUG_VERIFY_GPIOS                 \
+				       | DEBUG_BACKLIGHT | DEBUG_SYSFS)
+#define DEBUG_LEVEL_4	(DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE     \
+				       | DEBUG_FB_FILLRECT                  \
+				       | DEBUG_FB_COPYAREA                  \
+				       | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
 #define DEBUG_LEVEL_5	(DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY)
 #define DEBUG_LEVEL_6	(DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
 #define DEBUG_LEVEL_7	0xFFFFFFFF
Signature · 1 line
2.17.1
#4 lore raw

Re: [Outreachy kernel] [PATCH v2 2/4] staging: fbtft: Reformat long macro definitions

Same as 1/4, looks good to me,

Quoted 1 line · On Fri, 13 Mar 2020 19:13:12 +0530 Deepak R Varma <[email protected]> wrote:

Multiple macro definitions crossings 80 character line length nakes it

crossing, makes, them

Quoted 1 line

hard to understand. Reformating the these lines makes the code more

Reformatting

Quoted 1 line

readable and easy to understand. Issue flagged by checkpatch script.

easier

Signature · 1 line
Stefano
#5 lore raw

PATCH v2 3/4 staging: fbtft: simplify array index computation

In reply to Deepak R Varma

An array index is being computed by mathematical calculation on the Lvalue side of the expression. This also further results in the staement exceeding 80 character statement length.

A local variable can store the value of the array index computation. The variable can then be used as array index. This improves readability of the code and also address 80 character warning raised by checkpatch.

---
 drivers/staging/fbtft/fbtft-sysfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/fbtft/fbtft-sysfs.c +5 -1
index 2a5c630dab87..4d505a13f7ab 100644
@@ -25,6 +25,7 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
 	unsigned long val = 0;
 	int ret = 0;
 	int curve_counter, value_counter;
+	int counter = 0;
 
 	fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__);
 
@@ -68,7 +69,10 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
 			ret = get_next_ulong(&curve_p, &val, " ", 16);
 			if (ret)
 				goto out;
-			curves[curve_counter * par->gamma.num_values + value_counter] = val;
+
+			counter = curve_counter * par->gamma.num_values +
+					value_counter;
+			curves[counter] = val;
 			value_counter++;
 		}
 		if (value_counter != par->gamma.num_values) {
Signature · 1 line
2.17.1
#6 lore raw

Re: [Outreachy kernel] [PATCH v2 3/4] staging: fbtft: simplify array index computation

Hmm, this isn't exactly simplifying if one looks at the diffstat:

Quoted 4 lines · On Fri, 13 Mar 2020 19:14:02 +0530 Deepak R Varma <[email protected]> wrote:

An array index is being computed by mathematical calculation on the Lvalue side of the expression. This also further results in the staement exceeding 80 character statement length.

Quoted 8 lines

A local variable can store the value of the array index computation. The variable can then be used as array index. This improves readability of the code and also address 80 character warning raised by checkpatch.

---
 drivers/staging/fbtft/fbtft-sysfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

More on that below:

drivers/staging/fbtft/fbtft-sysfs.c int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves, · line 28

Quoted 10 lines
drivers/staging/fbtft/fbtft-sysfs.c +1 -0
index 2a5c630dab87..4d505a13f7ab 100644
@@ -25,6 +25,7 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
 	unsigned long val = 0;
 	int ret = 0;
 	int curve_counter, value_counter;
+	int counter = 0;

...there's no need to initialise this.

drivers/staging/fbtft/fbtft-sysfs.c int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves, · line 74

Quoted 11 lines
drivers/staging/fbtft/fbtft-sysfs.c +3 -1
 	fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__);
 
@@ -68,7 +69,10 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
 			ret = get_next_ulong(&curve_p, &val, " ", 16);
 			if (ret)
 				goto out;
-			curves[curve_counter * par->gamma.num_values + value_counter] = val;
+
+			counter = curve_counter * par->gamma.num_values +
+					value_counter;

value_counter is summed to the whole thing, so it should be aligned under curve_counter.

drivers/staging/fbtft/fbtft-sysfs.c int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves, · line 75

Quoted 1 line
drivers/staging/fbtft/fbtft-sysfs.c +1 -0
+			curves[counter] = val;

And here, I think, the actual problem is variable naming itself. See section "4) Naming" of Documentation/process/coding-style.rst -- this looks a bit like Java. The "_counter" suffix doesn't add much here, I guess those could just be "curve" and "value". I haven't checked for ambiguities (could you have a look?), but if there's any, even "_count" would make this a bit more tolerable.

Signature · 1 line
Stefano
#7 lore raw

PATCH v2 4/4 staging: fbtft: Avoid potential precedence issues

In reply to Deepak R Varma

Put parentheses around uses of macro parameters to avoid possible precedence issues. Problem detected by checkpatch.

---
 drivers/staging/fbtft/fbtft.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/fbtft/fbtft.h +2 -2
index 81da30f4062e..76f8c090a837 100644
@@ -406,8 +406,8 @@ do {                                                         \
 
 #define fbtft_par_dbg(level, par, format, arg...)            \
 do {                                                         \
-	if (unlikely(par->debug & level))                    \
-		dev_info(par->info->device, format, ##arg);  \
+	if (unlikely((par)->debug & (level)))                    \
+		dev_info((par)->info->device, format, ##arg);  \
 } while (0)
 
 #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \
Signature · 1 line
2.17.1
Reviewed-by on v2 4/4
#8 lore raw

Re: [Outreachy kernel] [PATCH v2 4/4] staging: fbtft: Avoid potential precedence issues

Quoted 2 lines · On Fri, 13 Mar 2020 19:14:54 +0530 Deepak R Varma <[email protected]> wrote:

Put parentheses around uses of macro parameters to avoid possible precedence issues. Problem detected by checkpatch.

This one looks good to me. If you re-post, you can carry my:

Signature · 1 line
Stefano