linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] remove duplicate ifdefs
@ 2024-01-18  8:03 Shrikanth Hegde
  2024-01-18  8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-18  8:03 UTC (permalink / raw)
  To: linux-kernel, linux-ntfs-dev, linux-xfs, linuxppc-dev
  Cc: peterz, sshegde, mingo, anton, chandan.babu

When going through the code observed a case in scheduler,
where #ifdef CONFIG_SMP was used to inside an #ifdef CONFIG_SMP.
That didn't make sense since first one is good enough and second
one is a duplicate.

This could improve code readability. No functional change is intended.
Maybe this is not an issue these days as language servers can parse
the config and users can read the code without bothering about
whats true and whats not.

Does this change makes sense?

Since this might be present in other code areas wrote a very basic
python script which helps in finding these cases. It doesn't handle any
complicated #defines or space separated "# if". At some places the
log collected had to be manually corrected due to space separated ifdefs.
Thats why its not a treewide change.
There might be an opportunity for other files as well.

Logic is very simple. If there is #ifdef or #if or #ifndef add that
variable to list. Upon every subsequent #ifdef or #if or #ifndef
check if the same variable is in the list. If yes flag
an error. Verification was done manually later checking for any #undef
or any error due to script. These were the ones that flagged out and
made sense after going through code.

ifdefs were collected using grep in below way and that file was used as
the input to the script.
grep -rIwn --include="*.c*" --include="*.h"  -e "#if" -e "#ifndef" -e "#ifdef" -e "#else" -e "#endif" * > /tmp/input.txt

---------------------------------------------------------------------
script used:
---------------------------------------------------------------------
import os
import argparse

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--file",
                            help="file to input to script",
                            type=str)
    parser.add_argument("--verbose",
                            help="Print additional debugging info, 0 to disable ",
                            type=int)
    args = parser.parse_args()
    return args

def parseFiles(args):
    file_to_parse = open(args.file, "r")
    lines = file_to_parse.readlines()
    check_length = len(lines)
    ifdefs_list = []
    i=0

    while i < check_length:
        line = lines[i]
        last_word = line.strip().split(":")[2]
        last_word = last_word.split("/")[0]

        if (args.verbose):
            print(line)
        last_word_splits = last_word.split()
        if (args.verbose):
            print(last_word_splits)
        if last_word_splits[0] == "#ifdef" or last_word_splits[0] == "#ifndef" or last_word_splits[0] == "#if":
            if last_word_splits[1] in ifdefs_list:
                print("This is duplicate and may be fixed: %s, parent_list:\n" % (line))
                print(ifdefs_list)
            ifdefs_list.append(last_word_splits[1])
        if last_word_splits[0] == "#endif"":
            ifdefs_list.pop()

        i=i+1

if __name__ == "__main__":
    args = parse_args()
    parseFiles(args)
-------------------------------------------------------------------------


Shrikanth Hegde (3):
  sched: remove duplicate ifdefs
  fs: remove depulicate ifdefs
  arch/powerpc: remove duplicate ifdefs

 arch/powerpc/include/asm/paca.h           | 4 ----
 arch/powerpc/kernel/asm-offsets.c         | 2 --
 arch/powerpc/platforms/powermac/feature.c | 2 --
 arch/powerpc/xmon/xmon.c                  | 2 --
 fs/ntfs/inode.c                           | 2 --
 fs/xfs/xfs_sysfs.c                        | 4 ----
 kernel/sched/core.c                       | 4 +---
 kernel/sched/fair.c                       | 2 --
 8 files changed, 1 insertion(+), 21 deletions(-)

--
2.39.3


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

end of thread, other threads:[~2024-01-22 21:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-18  8:03 [RFC PATCH 0/3] remove duplicate ifdefs Shrikanth Hegde
2024-01-18  8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
2024-01-18  8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
2024-01-19  1:35   ` Darrick J. Wong
2024-01-22 12:50   ` Chandan Babu R
2024-01-22 14:37     ` Shrikanth Hegde
2024-01-18  8:03 ` [RFC PATCH 3/3] arch/powerpc: " Shrikanth Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).