RE: [PATCH v2] checkpatch: add command-line option for TAB size

From: Elliott, Robert (Servers)
Date: Wed May 08 2019 - 17:15:37 EST




> -----Original Message-----
> From: linux-kernel-owner@xxxxxxxxxxxxxxx [mailto:linux-kernel-owner@xxxxxxxxxxxxxxx] On Behalf Of
> Antonio Borneo
> Sent: Wednesday, May 8, 2019 12:44 PM
> Subject: [PATCH v2] checkpatch: add command-line option for TAB size
...
> Add a command-line option "--tab-size" to let the user select a
> TAB size value other than 8.
> This makes easy to reuse this script by other projects with
> different requirements in their coding style (e.g. OpenOCD [1]
> requires TAB size of 4 characters [2]).
...
> + --tab-size=n set the number of spaces for tab (default 8)
...
> + 'tab-size=i' => \$tabsize,
...
> - for (; ($n % 8) != 0; $n++) {
> + for (; ($n % $tabsize) != 0; $n++) {
...
> - if ($indent % 8) {
> + if ($indent % $tabsize) {
> - "\t" x ($pos / 8) .
> - " " x ($pos % 8);
> + "\t" x ($pos / $tabsize) .
> + " " x ($pos % $tabsize);
...
> - (($sindent % 8) != 0 ||
> + (($sindent % $tabsize) != 0 ||
...
> - ($sindent > $indent + 8))) {
> + ($sindent > $indent + $tabsize))) {

Checking for 0 before using the value in division and modulo
operations would be prudent.