Skip to content

Commit 5885dee

Browse files
authored
Merge pull request #223 from yizhanglinux/kmemleak-fix
check: fix kmemleak scan when DEBUG_KMEMLEAK_DEFAULT_OFF enabled
2 parents ea34d6a + 51f58e9 commit 5885dee

2 files changed

Lines changed: 42 additions & 36 deletions

File tree

check

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,58 @@ _check_dmesg() {
183183
fi
184184
}
185185

186-
_setup_kmemleak() {
187-
local f="/sys/kernel/debug/kmemleak"
186+
# Retrieve the value of kernel option $1.
187+
_get_kernel_option() {
188+
local f opt=$1 result
189+
190+
for f in /proc/config.gz /boot/config-$(uname -r); do
191+
[ -e "$f" ] || continue
192+
if result=$(zgrep "^CONFIG_${opt}=" "$f"); then
193+
echo "${result#*=}"
194+
return 0
195+
fi
196+
done
188197

189-
if [[ ! -e $f || ! -r $f ]]; then
190-
return 0
198+
return 1
199+
}
200+
201+
# Check if kernel option $1 is defined.
202+
_check_kernel_option() {
203+
case "$(_get_kernel_option "$1")" in
204+
y|m)
205+
return 0;;
206+
esac
207+
208+
return 1
209+
}
210+
211+
declare KMEMLEAK=0
212+
declare KMEMLEAK_FILE=/sys/kernel/debug/kmemleak
213+
214+
if _check_kernel_option DEBUG_KMEMLEAK && [[ -e $KMEMLEAK_FILE && -r $KMEMLEAK_FILE ]]; then
215+
if _check_kernel_option DEBUG_KMEMLEAK_DEFAULT_OFF; then
216+
if grep --quiet kmemleak=on /proc/cmdline; then
217+
KMEMLEAK=1
218+
fi
219+
else
220+
KMEMLEAK=1
191221
fi
222+
fi
192223

193-
echo clear > "$f"
224+
_setup_kmemleak() {
225+
if ((KMEMLEAK)) ;then
226+
echo clear > "$KMEMLEAK_FILE"
227+
fi
194228
}
195229

196230
_check_kmemleak() {
197231
local kmemleak
198-
local f="/sys/kernel/debug/kmemleak"
199232

200-
if [[ ! -e $f || ! -r $f ]]; then
201-
return 0
202-
fi
233+
((KMEMLEAK)) || return 0
203234

204-
echo scan > "$f"
235+
echo scan > "$KMEMLEAK_FILE"
205236
sleep 1
206-
kmemleak=$(cat "$f")
237+
kmemleak=$(cat "$KMEMLEAK_FILE")
207238

208239
if [[ -z $kmemleak ]]; then
209240
return 0

common/rc

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,31 +211,6 @@ _have_kernel_config_file() {
211211
return 0
212212
}
213213

214-
# Retrieve the value of kernel option $1.
215-
_get_kernel_option() {
216-
local f opt=$1 result
217-
218-
for f in /proc/config.gz /boot/config-$(uname -r); do
219-
[ -e "$f" ] || continue
220-
if result=$(zgrep "^CONFIG_${opt}=" "$f"); then
221-
echo "${result#*=}"
222-
return 0
223-
fi
224-
done
225-
226-
return 1
227-
}
228-
229-
# Check if kernel option $1 is defined.
230-
_check_kernel_option() {
231-
case "$(_get_kernel_option "$1")" in
232-
y|m)
233-
return 0;;
234-
esac
235-
236-
return 1
237-
}
238-
239214
# Combine _have_kernel_config_file() and _check_kernel_option().
240215
# Set SKIP_REASONS when _check_kernel_option() returns false.
241216
_have_kernel_option() {

0 commit comments

Comments
 (0)