All of lore.kernel.org
 help / color / mirror / Atom feed
* Mentorship report first draft
@ 2021-03-12 17:44 Dwaipayan Ray
  2021-03-20 14:03 ` Lukas Bulwahn
  0 siblings, 1 reply; 6+ messages in thread
From: Dwaipayan Ray @ 2021-03-12 17:44 UTC (permalink / raw)
  To: Lukas Bulwahn, linux-kernel-mentees

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

Hello,
As discussed earlier, attached is the initial draft of the mentorship report.

Please let me know in case you have any suggestions.
Also you can view it live at
https://raydwaipayan.github.io/blogs/posts/linux-kernel-mentorship/

Thank you!
Dwaipayan.

[-- Attachment #2: linux-kernel-mentorship.md --]
[-- Type: text/markdown, Size: 5313 bytes --]

---
title: "Linux Kernel checkpatch.pl mentorship"
date: 2021-03-06T02:05:17+05:30
draft: false
---

## Checkpatch - What is it?
[checkpatch.pl](https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl) is a trivial style checker for patches sent to the linux kernel.

Why is it needed you say?</br>
I did an analysis on checkpatch warnings on about 50k commits from v5.4.</br>
(Find the full report {{% link checkpatch_out_50k.txt %}}here{{% /link %}})

The top errors were then generated via the following shell command:
```/bin/bash
cat checkpatch_out_50k.txt | grep -oP "(?:WARNING|ERROR|CHECK):(\w+)" \
| sort | uniq -c | sort -nr  | head -n6
```

Count of errors | Error Types | Error
----------------|-------------|------
41999 | <span style="color:green">CHECK</span> | CAMELCASE
13629 | <span style="color:green">CHECK</span> | PARENTHESIS_ALIGNMENT
11491 | <span style="color:orange">WARNING</span> | LONG_LINE
8106 | <span style="color:green">CHECK</span> | SPACING
6825 | <span style="color:orange">WARNING</span> | LEADING_SPACE
4394 | <span style="color:green">CHECK</span> | OPEN_ENDED_LINE

Hmm...The no. of stylistically incorrect bits still continue to exist and
are still merged into the kernel code. To make the kernel code more
stylistically coherent, we can:

> - Create cleanup patches for the existing code
> - Make sure new patches are stylistically consistent

Both of these are where checkpatch comes handy.

## Checkpatch in the patch submission process

Before sending out the patches to the mailing list, it is recommended to
run checkpatch over the patches.

In general, a Kernel developer would:

> - Create the patch with his proposed changes.
> - Build check the patch, run additional tools like checkstack, sparse etc.
> - Run checkpatch.pl over the patches to eliminate all trivial style violations.
> - Send out the patch to the maintainers and mailing list.


The only catch here is that checkpatch is not always right. It is just a dumb
perl script. If the code looks better with checkpatch errors, let it be.

## Drawbacks of checkpatch

Checkpatch is only a static trivial style checker. It does not have the
capabilities of a full c based parser like [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html). In this sense it is limited in
what it can do. Still, it is highly valuable as a style checker tool and can
ease the work of maintainers and increase the chances of the patch being accepted
by the community.

## What did we do to improve it?

Over the first 3 months of my mentorship period, I primarily focused on
eliminating false-positives from checkpatch as well as adding new rules.

Consider the following patch commit log:

```diff
#include asm/bitsperlong.h avoid further potential userspace pollution
by moving the #define of SHIFT_PER_LONG to bitops.h which is not
exported to userspace.
```

A kernel developer in 2020 would not see any checkpatch warning.

A kernel developer in 2021 would see the following warning:
```\bin\bash
WARNING: Commit log lines starting with '#' are dropped by git as comments
#82: 
#include asm/bitsperlong.h avoid further potential userspace pollution
```

During the last 3 months I worked on two major features:

> - Addition of a verbose mode to checkpatch
> - Addition of an external documentation to checkpatch

For the documentation we decided to document all checkpatch message types,
their meanings and how to resolve them. This is still a work in progress.
Contributions are definitely welcome :-P.

### Verbose Mode

This was one of the new additions we did to checkpatch.

One can run checkpatch like this:

```/bin/bash
./scripts/checkpatch.pl -v test.patch
```

All verbose descriptions can be seen by pairing the verbose option
with --list-types:

```/bin/bash
./scripts/checkpatch.pl --list-types -v
```

### Checkpatch Documentation

The checkpatch documentation can be viewed from the kernel root
at `Documentation/dev-tools/checkpatch.rst`.

To build the documentation make sure you have configured sphynx
either in the system or in a python virtualenv. Next the kernel
doc can be built using:

```/bin/bash
make htmldocs
```

## How to contribute to the documentation?

The documentation is still a work in progress. Feel free to send
the patches to the kernel-doc mailing list, and add me (Dwaipayan
Ray <dwaipayanray1@gmail.com>) and Lukas (Lukas Bulwahn <lukas.bulwahn@gmail.com>) for reviewing it.

The documentation is writted in rst syntax. Refer
[here](http://openalea.gforge.inria.fr/doc/openalea/doc/_build/html/source/sphinx/rest_syntax.html) for a quick guide.

Before sending out the mail, please always:

> - checkpatch.pl your changes
> - build check your patch (in this case check the generated html docs)
> - spell check your patch (this can be easily done through checkpatch
>   using --codespell flag if you already have the codespell dictionary)

## Acknowledgements

During my mentorship period I learned a lot from my mentors. 
I would like to thank Lukas for his constant support as my mentor,
Joe for his guidance with checkpatch and everyone in the community for being such
amazing people.

The kernel contribution process may look old but it works. This is due to the dedication of everyone in the community, which I am glad to be a part of.

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-27 15:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 17:44 Mentorship report first draft Dwaipayan Ray
2021-03-20 14:03 ` Lukas Bulwahn
2021-03-20 16:04   ` Dwaipayan Ray
2021-03-25  6:23     ` Dwaipayan Ray
2021-03-25  7:59     ` Lukas Bulwahn
2021-03-27 15:08       ` Dwaipayan Ray

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.