[PATCH v1 0/7] Landlock: Clean up coding style with clang-format

Mickaël Salaün posted 7 patches 4 years ago
include/uapi/linux/landlock.h                 |   4 +
samples/landlock/sandboxer.c                  | 104 ++--
security/landlock/cred.c                      |   4 +-
security/landlock/cred.h                      |   8 +-
security/landlock/fs.c                        |  80 +--
security/landlock/fs.h                        |  11 +-
security/landlock/limits.h                    |   4 +
security/landlock/object.c                    |   6 +-
security/landlock/object.h                    |   6 +-
security/landlock/ptrace.c                    |  10 +-
security/landlock/ruleset.c                   |  80 +--
security/landlock/ruleset.h                   |  15 +-
security/landlock/syscalls.c                  |  60 +-
tools/testing/selftests/landlock/base_test.c  |  80 +--
tools/testing/selftests/landlock/common.h     |  66 ++-
tools/testing/selftests/landlock/fs_test.c    | 532 ++++++++++--------
.../testing/selftests/landlock/ptrace_test.c  |  38 +-
17 files changed, 615 insertions(+), 493 deletions(-)
[PATCH v1 0/7] Landlock: Clean up coding style with clang-format
Posted by Mickaël Salaün 4 years ago
Hi,

I used a simple coding style for the initial Landlock code.  However,
this may be subject to different interpretations.  To avoid relying
on tacit knowledge or text editors for these kind of rules, let's
automate it as much as possible thanks to clang-format.  This makes the
code formatting simple, consistent and impersonal.

Several versions of clang-format can be use but they may have (small)
different behaviors for undefined/new configuration parts.  After
testing different versions, I picked clang-format-14 which is relatively
new and fixes a bug present in version 11 to 13 (visible in the Landlock
formatted code).

I'll backport these patches and enforce this formatting for all the new
Landlock patches.

This series uses a patched clang-format configuration to make it
compatible with checkpatch.pl:
https://lore.kernel.org/r/20220506160106.522341-1-mic@digikod.net

It can be applied on v5.18-rc5 .

Regards,

Mickaël Salaün (7):
  landlock: Add clang-format exceptions
  landlock: Format with clang-format
  selftests/landlock: Add clang-format exceptions
  selftests/landlock: Normalize array assignment
  selftests/landlock: Format with clang-format
  samples/landlock: Add clang-format exceptions
  samples/landlock: Format with clang-format

 include/uapi/linux/landlock.h                 |   4 +
 samples/landlock/sandboxer.c                  | 104 ++--
 security/landlock/cred.c                      |   4 +-
 security/landlock/cred.h                      |   8 +-
 security/landlock/fs.c                        |  80 +--
 security/landlock/fs.h                        |  11 +-
 security/landlock/limits.h                    |   4 +
 security/landlock/object.c                    |   6 +-
 security/landlock/object.h                    |   6 +-
 security/landlock/ptrace.c                    |  10 +-
 security/landlock/ruleset.c                   |  80 +--
 security/landlock/ruleset.h                   |  15 +-
 security/landlock/syscalls.c                  |  60 +-
 tools/testing/selftests/landlock/base_test.c  |  80 +--
 tools/testing/selftests/landlock/common.h     |  66 ++-
 tools/testing/selftests/landlock/fs_test.c    | 532 ++++++++++--------
 .../testing/selftests/landlock/ptrace_test.c  |  38 +-
 17 files changed, 615 insertions(+), 493 deletions(-)


base-commit: 5c22d35e0cc57032edd92df16f530e3c9a33c027
-- 
2.35.1

Re: [PATCH v1 0/7] Landlock: Clean up coding style with clang-format
Posted by Miguel Ojeda 4 years ago
Hi Mickaël,

(Answering in v1 since I want to quote something in this cover letter)

On Fri, May 6, 2022 at 6:03 PM Mickaël Salaün <mic@digikod.net> wrote:
>
> I used a simple coding style for the initial Landlock code.  However,
> this may be subject to different interpretations.  To avoid relying
> on tacit knowledge or text editors for these kind of rules, let's
> automate it as much as possible thanks to clang-format.  This makes the
> code formatting simple, consistent and impersonal.

Thanks for moving your subsystem to `clang-format`. I am glad you
found it useful.

> Several versions of clang-format can be use but they may have (small)
> different behaviors for undefined/new configuration parts.  After
> testing different versions, I picked clang-format-14 which is relatively
> new and fixes a bug present in version 11 to 13 (visible in the Landlock
> formatted code).

Which was the bug?

Cheers,
Miguel
Re: [PATCH v1 0/7] Landlock: Clean up coding style with clang-format
Posted by Mickaël Salaün 4 years ago
On 09/05/2022 11:06, Miguel Ojeda wrote:
> Hi Mickaël,
> 
> (Answering in v1 since I want to quote something in this cover letter)

There is only a v1 for this specific series, but other series (with 
higher versions) are now relying on this one. ;)

> 
> On Fri, May 6, 2022 at 6:03 PM Mickaël Salaün <mic@digikod.net> wrote:
>>
>> I used a simple coding style for the initial Landlock code.  However,
>> this may be subject to different interpretations.  To avoid relying
>> on tacit knowledge or text editors for these kind of rules, let's
>> automate it as much as possible thanks to clang-format.  This makes the
>> code formatting simple, consistent and impersonal.
> 
> Thanks for moving your subsystem to `clang-format`. I am glad you
> found it useful.
> 
>> Several versions of clang-format can be use but they may have (small)
>> different behaviors for undefined/new configuration parts.  After
>> testing different versions, I picked clang-format-14 which is relatively
>> new and fixes a bug present in version 11 to 13 (visible in the Landlock
>> formatted code).
> 
> Which was the bug?

You can check it by running clang-format-X on security/landlock/fs.c [1] 
and you'll get different results for this hunk (only):

--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -688,7 +688,7 @@ static inline access_mask_t maybe_remove(const 
struct dentry *const dentry)
  	if (d_is_negative(dentry))
  		return 0;
  	return d_is_dir(dentry) ? LANDLOCK_ACCESS_FS_REMOVE_DIR :
-				  LANDLOCK_ACCESS_FS_REMOVE_FILE;
+					LANDLOCK_ACCESS_FS_REMOVE_FILE;
  }

  /**


[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/mic/linux.git/log/?h=landlock-wip