Skip to content

Commit

Permalink
Fix the bug of incorrect use of DEVICE variable in ethernet
Browse files Browse the repository at this point in the history
Part of the code uses DEVICE before assigning a value to DEVICE, which will cause the condition to be judged incorrectly.
For example, if there is another network card NO-CARRIER, it will cause eth0 to be erroneously disabled.
Move this part of the code after assigning a value to the DEVICE.
  • Loading branch information
xinpeng.wang committed Sep 22, 2021
1 parent 9839bd2 commit 4394ca2
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions usr/share/laptop-mode-tools/modules/ethernet
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,6 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
IPTOOL=/bin/false
fi


# Determine speed capability of physical device
speed=`$MIITOOL -v $DEVICE 2>/dev/null | grep capabilities | tr ' ' '\n' |\
sort -n | sed -ne '/^1.*/p' | cut -d "b" -f1`
if [ -z "$speed" ]; then
speed=0;
fi
max_s=0;
min_s=100000;
for s in $speed;
do
if [ $s -gt $max_s ]; then
max_s=$s
fi
if [ $s -lt $min_s ]; then
min_s=$s
fi
done
MAX_SPEED=$max_s;

case "$THROTTLE_SPEED" in
"slowest")
THROTTLE_SPEED=$min_s
;;
"fastest")
THROTTLE_SPEED=$max_s
;;
esac

# Carrier detection
if $IPTOOL link show $DEVICE | grep -q NO-CARRIER; then
carrier="false";
else
carrier="true";
fi


# What state we are in
if [ $ON_AC -eq 1 ]; then
if [ "$ACTIVATE" -eq 1 ]; then
Expand All @@ -76,12 +39,6 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
THROTTLE_ETHERNET="$NOLM_AC_THROTTLE_ETHERNET"
fi

# One off a case.
# So that when back on AC, we can resume the speed back to MAX.
if [ x$THROTTLE_ETHERNET = x0 ]; then
THROTTLE_SPEED=$MAX_SPEED;
fi

if [ x$DISABLE_ETHERNET_ON_BATTERY = x1 ]; then
# We are ON_AC and Disable feature is requested
# So we might be required to re-enable the device.
Expand All @@ -104,6 +61,47 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
for DEVICE in $ETHERNET_DEVICES ; do
log "VERBOSE" "ethernet: $DEVICE"

# Determine speed capability of physical device
speed=`$MIITOOL -v $DEVICE 2>/dev/null | grep capabilities | tr ' ' '\n' |\
sort -n | sed -ne '/^1.*/p' | cut -d "b" -f1`
if [ -z "$speed" ]; then
speed=0;
fi
max_s=0;
min_s=100000;
for s in $speed;
do
if [ $s -gt $max_s ]; then
max_s=$s
fi
if [ $s -lt $min_s ]; then
min_s=$s
fi
done
MAX_SPEED=$max_s;

case "$THROTTLE_SPEED" in
"slowest")
THROTTLE_SPEED=$min_s
;;
"fastest")
THROTTLE_SPEED=$max_s
;;
esac

# Carrier detection
if $IPTOOL link show $DEVICE | grep -q NO-CARRIER; then
carrier="false";
else
carrier="true";
fi

# One off a case.
# So that when back on AC, we can resume the speed back to MAX.
if [ $ON_AC -eq 1 -a x$THROTTLE_ETHERNET = x0 ]; then
THROTTLE_SPEED=$MAX_SPEED;
fi

# Wakeup-on-LAN handling
if [ x$DISABLE_WAKEUP_ON_LAN = x1 ] ; then
ret=`$ETHTOOL -s $DEVICE wol d 2>&1`
Expand Down

1 comment on commit 4394ca2

@wxphaha
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rickysarraf#171 I just found out that my modification and rickysarraf#171 are the same problem, my modification can solve rickysarraf#171

Please sign in to comment.