[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1033035: hw-detect: trivial patches



Package: src:hw-detect
Version: 1.155
Tags: patch

Dear maintainer,
Please consider merging the attached patches.

- hw-detect.pre-pkgsel.d/50install-firmware: fix path of deleted file

- check-missing-firmware.sh: shift positional parameters after reading
   -n

- check-missing-firmware.sh: define local variables in functions

- check-missing-firmware.sh: get package name from control instead of
   file name

- check-missing-firmware.sh: replace spaces with tabs in indentation
From e9a8ceeaa83fbf43e33cdd3745bbbf5d64c3291c Mon Sep 17 00:00:00 2001
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
Date: Mon, 13 Mar 2023 14:57:52 +0100
Subject: [PATCH 1/5] hw-detect.pre-pkgsel.d/50install-firmware: fix path of
 deleted file

---
 hw-detect.pre-pkgsel.d/50install-firmware | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw-detect.pre-pkgsel.d/50install-firmware b/hw-detect.pre-pkgsel.d/50install-firmware
index 61d23b41..15c145e8 100644
--- a/hw-detect.pre-pkgsel.d/50install-firmware
+++ b/hw-detect.pre-pkgsel.d/50install-firmware
@@ -18,7 +18,7 @@ if [ -d /var/cache/firmware ]; then
 			else
 				n=$((n+1))
 			fi
-			rm -f "/target/tmp/$deb"
+			rm -f "/target/tmp/$(basename "$deb")"
 		fi
 	done
 	if [ $n -gt 0 ]; then
-- 
2.30.2

From 69a30ad764bb3760feae7cf5a7f19dcc34ac886a Mon Sep 17 00:00:00 2001
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
Date: Wed, 8 Mar 2023 19:38:04 +0100
Subject: [PATCH 2/5] check-missing-firmware.sh: shift positional parameters
 after reading -n

---
 check-missing-firmware.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/check-missing-firmware.sh b/check-missing-firmware.sh
index cfb85fb1..44054818 100755
--- a/check-missing-firmware.sh
+++ b/check-missing-firmware.sh
@@ -6,6 +6,7 @@ DENIED=/tmp/missing-firmware-denied
 
 if [ "x$1" = "x-n" ]; then
 	NONINTERACTIVE=1
+	shift
 else
 	NONINTERACTIVE=""
 fi
-- 
2.30.2

From ce221a36cbdae932453fbcc6b037fe4d634e1dce Mon Sep 17 00:00:00 2001
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
Date: Wed, 8 Mar 2023 19:35:49 +0100
Subject: [PATCH 3/5] check-missing-firmware.sh: define local variables in
 functions

---
 check-missing-firmware.sh | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/check-missing-firmware.sh b/check-missing-firmware.sh
index 44054818..0557f7d1 100755
--- a/check-missing-firmware.sh
+++ b/check-missing-firmware.sh
@@ -23,8 +23,9 @@ log_output() {
 
 # USB is special, and we don't want to take it all done:
 get_usb_module() {
-	address="$1"
-	device="/sys/bus/usb/devices/$address"
+	local address="$1"
+	local device="/sys/bus/usb/devices/$address"
+	local subdirs driver
 
 	# Make sure there's a single subdirectory (e.g. 4-1.5:1.0 below 4-1.5):
 	subdirs=$(find -L "$device" -maxdepth 1 -type d -name "$address:*")
@@ -52,7 +53,7 @@ get_usb_module() {
 # The mhi module's holders directory lists ath11k_pci and qrtr_mhi
 # though!
 get_mhi_holders() {
-	holders=$(find -L /sys/module/mhi/holders/ -mindepth 1 -maxdepth 1 -exec basename {} ';')
+	local holders=$(find -L /sys/module/mhi/holders/ -mindepth 1 -maxdepth 1 -exec basename {} ';')
 	if [ "$holders" = "" ]; then
 		log "failed to perform mhi lookup (no holders found)"
 		log "=> sticking with the mhi module"
@@ -66,6 +67,8 @@ get_mhi_holders() {
 # then down any interfaces specified by ethdetect. Don't touch interfaces
 # that users might have configured (manually or via preseeding) though!
 upnics() {
+	local iface sys_iface
+
 	for iface in $IFACES; do
 		# Don't rely on ip's output, it lacks at least state UP/DOWN:
 		sys_iface="/sys/class/net/$iface"
@@ -88,7 +91,8 @@ upnics() {
 # is up and has an IP address. Such modules should not be reloaded,
 # to avoid taking down the network after it's been configured.
 nic_is_configured() {
-	module="$1"
+	local module="$1"
+	local iface dir
 
 	for iface in $(ip -o link show up | cut -d : -f 2); do
 		dir="/sys/class/net/$iface/device/driver"
@@ -103,8 +107,9 @@ nic_is_configured() {
 }
 
 get_fresh_dmesg() {
-	dmesg_file=/tmp/dmesg.txt
-	dmesg_ts=/tmp/dmesg-ts.txt
+	local dmesg_file=/tmp/dmesg.txt
+	local dmesg_ts=/tmp/dmesg-ts.txt
+	local tspattern ln
 
 	# Get current dmesg:
 	dmesg > $dmesg_file
@@ -143,6 +148,8 @@ get_fresh_dmesg() {
 }
 
 check_missing () {
+	local fwlist module address fwfile
+
 	upnics
 
 	# Give modules some time to request firmware.
@@ -264,14 +271,14 @@ list_deb_firmware () {
 }
 
 check_deb_arch () {
-	arch=$(udpkg -f "$1" | grep '^Architecture:' | sed -e 's/Architecture: *//')
+	local arch=$(udpkg -f "$1" | grep '^Architecture:' | sed -e 's/Architecture: *//')
 	[ "$arch" = all ] || [ "$arch" = "$(udpkg --print-architecture)" ]
 }
 
 get_deb_component () {
 	# This trusts the contents of the .deb, but packages in the archive could
 	# have overrides (controlled by ftpmaster):
-	section=$(udpkg -f "$1" | grep '^Section:' | sed -e 's/Section: *//')
+	local section=$(udpkg -f "$1" | grep '^Section:' | sed -e 's/Section: *//')
 	if ! echo "$section" | grep -qs '/'; then
 		echo "main"
 	else
@@ -281,7 +288,9 @@ get_deb_component () {
 
 # Remove non-accepted firmware package
 remove_pkg() {
-	pkgname="$1"
+	local pkgname="$1"
+	local file
+
 	# Remove all files listed in /var/lib/dpkg/info/$pkgname.md5sums
 	for file in $(cut -d" " -f 2- /var/lib/dpkg/info/$pkgname.md5sums) ; do
 		rm /$file
@@ -289,11 +298,13 @@ remove_pkg() {
 }
 
 install_firmware_pkg () {
+	local filename="$(basename "$1")"
+	local pkgname="$(echo $filename |cut -d_ -f1)"
+	local removed
+
 	# cache deb for installation into /target later
 	mkdir -p /var/cache/firmware/
 	cp -aL "$1" /var/cache/firmware/ || true
-	filename="$(basename "$1")"
-	pkgname="$(echo $filename |cut -d_ -f1)"
 	udpkg --unpack "/var/cache/firmware/$filename"
 	if [ -f /var/lib/dpkg/info/$pkgname.preinst ] ; then
 		# Run preinst script to see if the firmware
@@ -317,6 +328,8 @@ install_firmware_pkg () {
 # This does not use anna because debs can have arbitrary
 # dependencies, which anna might try to install.
 check_for_firmware() {
+	local dir fw_file fw_pkg_file component filename
+
 	echo "$files" | sed -e 's/ /\n/g' >/tmp/grepfor
 	for dir in $@; do
 		# An index file might exist, mapping firmware files to firmware
-- 
2.30.2

From b57ec77e63d09f5c715b60f233de3a8d01b4f430 Mon Sep 17 00:00:00 2001
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
Date: Mon, 13 Mar 2023 15:16:14 +0100
Subject: [PATCH 4/5] check-missing-firmware.sh: get package name from control
 instead of file name

The package file name may not follow the standard naming scheme if custom built
or provided by third party. It is more reliable to use the Package: control
field instead, like in hw-detect.pre-pkgsel.d/50install-firmware.
---
 check-missing-firmware.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/check-missing-firmware.sh b/check-missing-firmware.sh
index 0557f7d1..6d088faf 100755
--- a/check-missing-firmware.sh
+++ b/check-missing-firmware.sh
@@ -299,7 +299,7 @@ remove_pkg() {
 
 install_firmware_pkg () {
 	local filename="$(basename "$1")"
-	local pkgname="$(echo $filename |cut -d_ -f1)"
+	local pkgname="$(udpkg -f "$1" | grep '^Package:' | sed -e 's/^Package: *//')"
 	local removed
 
 	# cache deb for installation into /target later
-- 
2.30.2

From 47c682c072b271fd401f5cb9d0e215ca3e1eae28 Mon Sep 17 00:00:00 2001
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
Date: Thu, 16 Mar 2023 00:26:21 +0100
Subject: [PATCH 5/5] check-missing-firmware.sh: replace spaces with tabs in
 indentation

---
 check-missing-firmware.sh | 54 +++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/check-missing-firmware.sh b/check-missing-firmware.sh
index 6d088faf..fe02775d 100755
--- a/check-missing-firmware.sh
+++ b/check-missing-firmware.sh
@@ -163,34 +163,34 @@ check_missing () {
 	fwlist=/tmp/check-missing-firmware-dmesg.list
 	get_fresh_dmesg | sed -rn 's/^(\[[^]]*\] )?([^ ]+) ([^ ]+): firmware: failed to load ([^ ]+) .*/\2 \3 \4/p' > $fwlist
 	while read module address fwfile ; do
-	    # rewrite module is necessary
-	    case "$module" in
-		usb)
-		    module=$(get_usb_module "$address")
-		    log "using module $module instead of usb $address"
-		;;
-		mhi)
-		    module=$(get_mhi_holders)
-		    log "using $module instead of mhi"
-		;;
-	    esac
-
-	    # ignore specific files:
-	    #  - iwlwifi, debug-only (#969264, #966218)
-	    if [ "$fwfile" = "iwl-debug-yoyo.bin" ]; then
-		log "ignoring firmware file $fwfile requested by $module"
-		continue
-	    fi
-
-	    log "looking for firmware file $fwfile requested by $module"
-	    if [ ! -e /lib/firmware/$fwfile ] ; then
-		if grep -q "^$fwfile$" $DENIED 2>/dev/null; then
-		    log "listed in $DENIED"
-		    continue
+		# rewrite module is necessary
+		case "$module" in
+			usb)
+				module=$(get_usb_module "$address")
+				log "using module $module instead of usb $address"
+			;;
+			mhi)
+				module=$(get_mhi_holders)
+				log "using $module instead of mhi"
+			;;
+		esac
+
+		# ignore specific files:
+		#  - iwlwifi, debug-only (#969264, #966218)
+		if [ "$fwfile" = "iwl-debug-yoyo.bin" ]; then
+			log "ignoring firmware file $fwfile requested by $module"
+			continue
+		fi
+
+		log "looking for firmware file $fwfile requested by $module"
+		if [ ! -e /lib/firmware/$fwfile ] ; then
+			if grep -q "^$fwfile$" $DENIED 2>/dev/null; then
+				log "listed in $DENIED"
+				continue
+			fi
+			files="${files:+$files }$fwfile"
+			modules="$module${modules:+ $modules}"
 		fi
-		files="${files:+$files }$fwfile"
-		modules="$module${modules:+ $modules}"
-	    fi
 	done < $fwlist
 
 	if [ -n "$modules" ]; then
-- 
2.30.2


Reply to: