From: Michael Opdenacker <michael.opdenacker@free-electrons.com>
To: mmarek@suse.cz, yann.morin.1998@free.fr,
akpm@linux-foundation.org, joe@perches.com
Cc: linux-kernel@vger.kernel.org,
Michael Opdenacker <michael.opdenacker@free-electrons.com>
Subject: [PATCH] scripts/checkkconfig.py: find unused Kconfig parameters
Date: Thu, 24 Oct 2013 07:23:29 +0200 [thread overview]
Message-ID: <1382592209-10246-1-git-send-email-michael.opdenacker@free-electrons.com> (raw)
This is the first version of a script to look for
Kconfig parameters which are still defined but no longer
used in the kernel source code.
The script may be extended in the future to perform
more checks. This explains why a rather generic name was chosen.
Several issues have already been reported and fixed
thanks to the use of this script. It is time to share it now!
Signed-off-by: Michael Opdenacker <michael.opdenacker@free-electrons.com>
---
scripts/checkkconfig.py | 131 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
create mode 100755 scripts/checkkconfig.py
diff --git a/scripts/checkkconfig.py b/scripts/checkkconfig.py
new file mode 100755
index 0000000..4155656
--- /dev/null
+++ b/scripts/checkkconfig.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 Free Electrons
+# Michael Opdenacker <michael.opdenacker@free-electrons.com>
+#
+# Look for issues in Kconfig files
+#
+# This first version supports:
+# - Looking for unused Kconfig parameters
+#
+# Usage: scripts/checkkconfig.py
+#
+# Licensed under the terms of the GNU GPL License version 2
+
+import fnmatch
+import os
+import subprocess
+
+########################################################
+# Parse Kconfig files
+########################################################
+
+def parse_kconfig(file):
+
+ global has_select, choice_type, source_file
+
+ current_param = ''
+ in_choice = False
+
+ with open(file, 'r') as f:
+ for line in f:
+ words = line.split()
+
+ if len(words) != 0:
+ key = words[0]
+
+ if len(words) == 1:
+
+ if key == 'choice':
+ in_choice = True
+ elif key == 'endchoice':
+ in_choice = False
+
+ elif len(words) > 1:
+
+ if key == 'config' or key == 'menuconfig':
+ current_param = words[1]
+
+ has_select[current_param] = False
+ choice_type[current_param] = in_choice
+ source_file[current_param] = file
+
+ elif key == 'select' and words[1] != '':
+
+ has_select[current_param] = True
+
+########################################################
+# Find occurrences of a parameter
+########################################################
+
+def count_param(param):
+
+ global source_file, bad_params_in_file
+
+ if os.path.isdir('.git'):
+ # Use git grep when available
+ count = subprocess.check_output('git grep ' + param + '| grep -v defconfig | wc -l', shell=True)
+ else:
+ # Fallback to regular grep
+ count = subprocess.check_output('grep -R ' + param + ' . | grep -v defconfig | wc -l', shell=True)
+
+ num = int(count.strip())
+
+ if num == 1:
+ 'WARNING: parameter ' + param + ' is used nowhere'
+
+ file=source_file[param]
+
+ if bad_params_in_file.has_key(file):
+ bad_params_in_file[file].append(param)
+ else:
+ bad_params_in_file[file]=[param]
+
+
+########################################################
+# Main program
+########################################################
+
+global has_select, choice_type, source_file, bad_params_in_file
+
+has_select = dict()
+choice_type = dict()
+source_file = dict()
+bad_params_in_file = dict()
+
+kconfig_files = []
+
+for root, dirnames, filenames in os.walk('.'):
+ for filename in fnmatch.filter(filenames, 'Kconfig*'):
+ kconfig_files.append(os.path.join(root, filename))
+
+print 'INFO: processing Kconfig files...'
+
+for f in kconfig_files:
+ parse_kconfig(f)
+
+total = len(has_select)
+count = 0
+old_percentage = -1
+
+for param in has_select.keys():
+
+ # Progress information... running the script can take hours!
+
+ count += 1
+ percentage = int((100*count)/total)
+
+ if percentage > old_percentage:
+ print 'INFO: checking kconfig parameter %d / %d (%d %%)' % (count, total, percentage)
+ old_percentage = percentage
+
+ # Ignore parameters with select dependencies
+ # Also ignore parameters inside 'choice ... endchoice'
+ # All of them are valid, even if they have only one instance
+
+ if not(has_select[param]) and not(choice_type[param]):
+ count_param(param)
+
+for file in bad_params_in_file.keys():
+ print 'File: ' + file
+ print bad_params_in_file[file]
--
1.8.1.2
next reply other threads:[~2013-10-24 5:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-24 5:23 Michael Opdenacker [this message]
2013-10-24 7:30 ` Joe Perches
2013-10-25 13:38 ` Michael Opdenacker
2013-10-25 13:45 ` Michal Marek
2013-10-30 3:07 ` Michael Opdenacker
2013-10-24 9:39 ` Michal Marek
2013-10-29 18:06 ` Yann E. MORIN
2013-10-30 3:14 ` Michael Opdenacker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382592209-10246-1-git-send-email-michael.opdenacker@free-electrons.com \
--to=michael.opdenacker@free-electrons.com \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=yann.morin.1998@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®