Skip to contentSkip to conversation

checkpatch: relax parenthesis style checks

PATCH Applied Andrea Cervesato 5 participants 9 messages Jul 14 – Jul 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: relax parenthesis style checks

From: Andrea Cervesato <[email protected]>

The PARENTHESIS_ALIGNMENT and OPEN_ENDED_LINE strict checks flag common LTP formatting that is otherwise accepted, so disable them.

---
 .checkpatch.conf | 3 +++
 1 file changed, 3 insertions(+)
.checkpatch.conf +3 -0
index a7b6219adac5fff663c99a4cafaafb7c609233a6..0b22f7811cc891e91c62565edb0663df1e0f2622 100644
@@ -17,3 +17,6 @@
 
 # ENOSYS is used in test error macros
 --ignore ENOSYS
+
+# LTP does not enforce open parenthesis alignment nor forbid a trailing '('
+--ignore PARENTHESIS_ALIGNMENT,OPEN_ENDED_LINE

---
base-commit: 7ca5dc366a558f3666223e6abe579edd90bafd38
change-id: 20260714-checkpatch_remove_rules-e942ef47a23d

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Andrea, Cyril,

I found both rules useful (more readable and more consistent code). Can we put it back? Over the years you will recognise on the code of single test that it was written/modified by several people with a different styles. And that makes it less readable.

* PARENTHESIS_ALIGNMENT check enforces space behind 'while' or 'if'. i.e. instead of:

	while(tst_fzsync_run_b(&fzsync_pair)) {
have:
	while (tst_fzsync_run_b(&fzsync_pair)) {

cve-2014-0196.c mixes 'while()' and 'while ()'. Is it that hard to be consistent on it?

* OPEN_ENDED_LINE asks for not ending line with '(' or '['. i.e. instead of this:

	ruleset_fd = TST_EXP_FD_SILENT(
								   tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
have this:
	ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));

It's just my personal preference but I agree with the author of the rule that enforced style is more readable.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Petr,

Quoted 7 lines

Hi Andrea, Cyril,

I found both rules useful (more readable and more consistent code). Can we put it back? Over the years you will recognise on the code of single test that it was written/modified by several people with a different styles. And that makes it less readable.

Quoted 8 lines

* PARENTHESIS_ALIGNMENT check enforces space behind 'while' or 'if'. i.e. instead of:

	while(tst_fzsync_run_b(&fzsync_pair)) {
have:
	while (tst_fzsync_run_b(&fzsync_pair)) {

cve-2014-0196.c mixes 'while()' and 'while ()'. Is it that hard to be consistent on it?

im not sure that rule is checking for spaces after the statements. that rule is avoiding stuff like:

	ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(ruleset_attr,
																						sizeof(struct tst_landlock_ruleset_attr_abi1), 0);

because parenthesis should allign the attributes of the functions. that is super ugly when functions have really long names. Instead, this would make much more sense:

	ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(ruleset_attr,
							     sizeof(struct tst_landlock_ruleset_attr_abi1), 0);
Quoted 9 lines

* OPEN_ENDED_LINE asks for not ending line with '(' or '['. i.e. instead of this:

	ruleset_fd = TST_EXP_FD_SILENT(
								   tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
have this:
	ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));

you choose the right example, landlock testing suite has been updated to match this rule and now it has stuff like:

	apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

instead of

	apply_landlock_fs_layer(
				ruleset_attr,
				sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr,
				MNTPOINT,
				LANDLOCK_ACCESS_FS_IOCTL_DEV
	);

that is more clear what are the functions attributes.

For the second one, maybe it's more like a personal preference, but the first rule is actually generating a lot of weird code when functions and attributes have long names, forcing to write long lines without staying into the 80-100 chars.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Andrea,

Quoted 15 lines

Hi Petr,

Quoted 12 lines

Hi Andrea, Cyril,

I found both rules useful (more readable and more consistent code). Can we put it back? Over the years you will recognise on the code of single test that it was written/modified by several people with a different styles. And that makes it less readable.

* PARENTHESIS_ALIGNMENT check enforces space behind 'while' or 'if'. i.e. instead of:

	while(tst_fzsync_run_b(&fzsync_pair)) {
have:
	while (tst_fzsync_run_b(&fzsync_pair)) {
Quoted 4 lines
Quoted 2 lines

cve-2014-0196.c mixes 'while()' and 'while ()'. Is it that hard to be consistent on it?

im not sure that rule is checking for spaces after the statements. that

I'm sorry, indeed, that is checked by SPACING which is still on.

Quoted 5 lines

rule is avoiding stuff like:

	ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(ruleset_attr,
																						sizeof(struct tst_landlock_ruleset_attr_abi1), 0);
Quoted 7 lines

because parenthesis should allign the attributes of the functions. that is super ugly when functions have really long names. Instead, this would make much more sense:

	ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(ruleset_attr,
							     sizeof(struct tst_landlock_ruleset_attr_abi1), 0);

Yes, it forces alignment after '('. Example of fix in the kernel:
https://lore.kernel.org/all/[email protected]/

pr_err("Could not register clock provider for node:%s\n",
- np->name);
+ np->name);

I'd say it depends how your displays tabs (if tabs are in the sources, we have .editorconfig, but not all not all developers have their editor set to use it). In certain setup it does not look OK + the problem of inconsistency, but I'm ok to ignore it.

Quoted 9 lines
Quoted 8 lines

* OPEN_ENDED_LINE asks for not ending line with '(' or '['. i.e. instead of this:

	ruleset_fd = TST_EXP_FD_SILENT(
								   tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
have this:
	ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
Quoted 5 lines

you choose the right example, landlock testing suite has been updated to match this rule and now it has stuff like:

	apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

In my personal preference is this above better ...

Quoted 9 lines

instead of

	apply_landlock_fs_layer(
				ruleset_attr,
				sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr,
				MNTPOINT,
				LANDLOCK_ACCESS_FS_IOCTL_DEV
	);

... than this. Why? Instead of 2 lines you have 7 lines. That would be ok, if we all use portrait screens, but most of us code on landscape. (Too much scrolling.)

IMHO you introduced that style, which is still not widely used in the code. Sooner or later we will have mix of 2 styles even in the single source file which will be less readable.

Quoted 1 line

that is more clear what are the functions attributes.

Maybe this is is slightly more readable, but for me it does not pay off the numer of extra lines. And functions with more than 3 parameters are hard to read anyway (specially if passed parameters are just numbers).

Quoted 4 lines

For the second one, maybe it's more like a personal preference, but the first rule is actually generating a lot of weird code when functions and attributes have long names, forcing to write long lines without staying into the 80-100 chars.

I'm ok with ignoring OPEN_ENDED_LINE, but I vote for putting back PARENTHESIS_ALIGNMENT.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 4 lines

I'd say it depends how your displays tabs (if tabs are in the sources, we have .editorconfig, but not all not all developers have their editor set to use it). In certain setup it does not look OK + the problem of inconsistency, but I'm ok to ignore it.

At the moment i use the standard kernel guidelines for TAB (8 spaces)

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

* OPEN_ENDED_LINE asks for not ending line with '(' or '['. i.e. instead of this:

	ruleset_fd = TST_EXP_FD_SILENT(
								   tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
have this:
	ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
Quoted 5 lines
Quoted 5 lines

you choose the right example, landlock testing suite has been updated to match this rule and now it has stuff like:

	apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

For some reason my email client is not showing the correct spaces in the example:

my_ret_val = apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),

                                     path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

or:

my_ret_val = apply_landlock_fs_layer(ruleset_attr,

                                     sizeof(struct tst_landlock_ruleset_attr_abi1),
                                     path_beneath_attr,
                                     MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

to escape the 80-100 lines rule.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
Quoted 32 lines
Quoted 4 lines

I'd say it depends how your displays tabs (if tabs are in the sources, we have .editorconfig, but not all not all developers have their editor set to use it). In certain setup it does not look OK + the problem of inconsistency, but I'm ok to ignore it.

At the moment i use the standard kernel guidelines for TAB (8 spaces)

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

* OPEN_ENDED_LINE asks for not ending line with '(' or '['. i.e. instead of this:

	ruleset_fd = TST_EXP_FD_SILENT(
								   tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
have this:
	ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, ruleset_attr,
						   sizeof(struct tst_landlock_ruleset_attr_abi1), 0));
Quoted 5 lines
Quoted 5 lines

you choose the right example, landlock testing suite has been updated to match this rule and now it has stuff like:

	apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),
				path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

For some reason my email client is not showing the correct spaces in the example:

my_ret_val = apply_landlock_fs_layer(ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1),

                                     path_beneath_attr, MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

or:

Quoted 6 lines

my_ret_val = apply_landlock_fs_layer(ruleset_attr,

                                     sizeof(struct tst_landlock_ruleset_attr_abi1),
                                     path_beneath_attr,
                                     MNTPOINT, LANDLOCK_ACCESS_FS_IOCTL_DEV);

to escape the 80-100 lines rule.

As I wrote, I prefer more arguments in the line than a single one.

Anyway, I tend to send RFC patch to add OPEN_ENDED_LINE, to see what others think about it. But if you're strongly against it, I would not want to enforce you.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw
In reply to Andrea Cervesato

Hi Andrea,

Quoted 1 line · Andrea Cervesato

checkpatch: relax parenthesis style checks

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp