Skip to content

Commit fbb76d5

Browse files
joe-lawrencepmladek
authored andcommitted
livepatch/selftests: use "$@" to preserve argument list
The livepatch selftest functions.sh library uses "$*" and an intermediate variable to extract and then pass arguments from function to function call. The effect of this combination is that the argument list is flattened into a single argument. Sometimes this is benign, but in cases like __load_mod(), the modprobe invocation will interpret all the module parameters as a single parameter. Drop the intermediate variable and use the "$@" special parameter as described in the bash manual. Link: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters Signed-off-by: Joe Lawrence <[email protected]> Reviewed-by: Kamalesh Babulal <[email protected]> Acked-by: Miroslav Benes <[email protected]> Signed-off-by: Petr Mladek <[email protected]>
1 parent a087cdd commit fbb76d5

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

tools/testing/selftests/livepatch/functions.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ function is_livepatch_mod() {
5555

5656
function __load_mod() {
5757
local mod="$1"; shift
58-
local args="$*"
5958

60-
local msg="% modprobe $mod $args"
59+
local msg="% modprobe $mod $*"
6160
log "${msg%% }"
62-
ret=$(modprobe "$mod" "$args" 2>&1)
61+
ret=$(modprobe "$mod" "$@" 2>&1)
6362
if [[ "$ret" != "" ]]; then
6463
die "$ret"
6564
fi
@@ -75,12 +74,11 @@ function __load_mod() {
7574
# params - module parameters to pass to modprobe
7675
function load_mod() {
7776
local mod="$1"; shift
78-
local args="$*"
7977

8078
is_livepatch_mod "$mod" &&
8179
die "use load_lp() to load the livepatch module $mod"
8280

83-
__load_mod "$mod" "$args"
81+
__load_mod "$mod" "$@"
8482
}
8583

8684
# load_lp_nowait(modname, params) - load a kernel module with a livepatch
@@ -89,12 +87,11 @@ function load_mod() {
8987
# params - module parameters to pass to modprobe
9088
function load_lp_nowait() {
9189
local mod="$1"; shift
92-
local args="$*"
9390

9491
is_livepatch_mod "$mod" ||
9592
die "module $mod is not a livepatch"
9693

97-
__load_mod "$mod" "$args"
94+
__load_mod "$mod" "$@"
9895

9996
# Wait for livepatch in sysfs ...
10097
loop_until '[[ -e "/sys/kernel/livepatch/$mod" ]]' ||
@@ -106,9 +103,8 @@ function load_lp_nowait() {
106103
# params - module parameters to pass to modprobe
107104
function load_lp() {
108105
local mod="$1"; shift
109-
local args="$*"
110106

111-
load_lp_nowait "$mod" "$args"
107+
load_lp_nowait "$mod" "$@"
112108

113109
# Wait until the transition finishes ...
114110
loop_until 'grep -q '^0$' /sys/kernel/livepatch/$mod/transition' ||
@@ -120,11 +116,10 @@ function load_lp() {
120116
# params - module parameters to pass to modprobe
121117
function load_failing_mod() {
122118
local mod="$1"; shift
123-
local args="$*"
124119

125-
local msg="% modprobe $mod $args"
120+
local msg="% modprobe $mod $*"
126121
log "${msg%% }"
127-
ret=$(modprobe "$mod" "$args" 2>&1)
122+
ret=$(modprobe "$mod" "$@" 2>&1)
128123
if [[ "$ret" == "" ]]; then
129124
die "$mod unexpectedly loaded"
130125
fi

0 commit comments

Comments
 (0)