Skip to content

Commit

Permalink
Do not needlessly reattach device to usbip-host
Browse files Browse the repository at this point in the history
If device is already attached to usbip-host, leave it there. This avoids
any other driver interacting with the device in the short time (if some
module gets loaded at this time for example).

QubesOS/qubes-issues#
  • Loading branch information
marmarek committed May 29, 2024
1 parent 7030f45 commit 4f7fe16
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/usb-export
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,22 @@ modprobe usbip-host
# Request that both IN and OUT be handled on a single (stdin) socket
kill -USR1 "$QREXEC_AGENT_PID" || exit 1

attach_to_usbip=true
# Unbind the device from the driver
if [ -d "$devpath/driver" ]; then
printf %s "$busid" > "$devpath/driver/unbind" || exit 1
old_driver=$(readlink -f "$devpath/driver")
if [ "$old_driver" != "$SYS_USBIP_HOST" ]; then
printf %s "$busid" > "$devpath/driver/unbind" || exit 1
else
attach_to_usbip=
fi
fi

# Bind to the usbip-host driver
printf 'add %s' "$busid" > "$SYS_USBIP_HOST/match_busid" || exit 1
echo "$busid" > "$SYS_USBIP_HOST/bind" || exit 1
if [ -n "$attach_to_usbip" ]; then
echo "$busid" > "$SYS_USBIP_HOST/bind" || exit 1
fi

# One more safety check - make sure the device is available
read status < "$devpath/usbip_status"
Expand Down

0 comments on commit 4f7fe16

Please sign in to comment.