File 0001-powerpc-utils-Suppress-errors-reading-kernel-files.patch of Package powerpc-utils.13919

From 73839d6bab4da24350a60105b7b2c3a6cc7d3a15 Mon Sep 17 00:00:00 2001
From: Michael Bringmann <mwb@linux.vnet.ibm.com>
Date: Fri, 26 Jul 2019 09:10:51 -0500
Subject: [PATCH] powerpc-utils: Suppress errors reading kernel files

A problem was observed with the evaluation of the '${devspec} by
the script 'ofpathname'.  The problem occurred during installation
to an nvme device as follows:

02:29:41,669 INF program: Running... ofpathname /dev/nvme0n1p1
02:29:41,922 INF program: /sbin/ofpathname: line 684: warning: command substitution: ignored null byte in input

Detailed examination showed that instances of the device-tree
property "/namespace/name" within one or more of the PCI devices
contained null bytes which were echoed along with the value e.g.

[root device-tree]# cat /proc/device-tree/pci@800000020000029/pci1014,637@0/namespace/name | hexdump -C
00000000  6e 61 6d 65 73 70 61 63  65 00                    |namespace.|
0000000a
[root device-tree]#

This patch provides improves handling of errors within that script,
and by some of the follow-on uses of the tool by the 'bootlist' script.

* Deal with error messages returned sometimes by evaluation
  of ${devspec} in 'ofpathname'.
* Strip embedded nulls from values provided by kernel files.
* Redirect more error messages to /dev/null

Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
---
 scripts/bootlist   | 8 ++++----
 scripts/ofpathname | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

Index: powerpc-utils-1.3.7/scripts/bootlist
===================================================================
--- powerpc-utils-1.3.7.orig/scripts/bootlist
+++ powerpc-utils-1.3.7/scripts/bootlist
@@ -207,11 +207,11 @@ show_bootlist()
     local devlist=$1
     local i
 
-    for i in `$NVRAM --print-config=${devlist} | sed 's/ /\n/g'`; do
+    for i in `$NVRAM --print-config=${devlist} 2> /dev/null | sed 's/ /\n/g'`; do
 	if [[ $TRANSLATE_NAMES = "yes" ]]; then
 	    name=`get_logical_device_name $i`
 	    if [[ -z $name ]]; then
-	        echo "Could not translate $i to logical device name"
+	        echo "Could not translate $i to logical device name" >&2
 	    else
 		case $name in
 		    eth*)   parse_eth_info $name $i ;;
@@ -230,7 +230,7 @@ show_bootlist()
 
 . $PSERIES_PLATFORM
 if [[ $platform != $PLATFORM_PSERIES_LPAR ]]; then
-    echo "bootlist: is not supported on the $platform_name platform"
+    echo "bootlist: is not supported on the $platform_name platform" >&2
     exit 1
 fi
 
Index: powerpc-utils-1.3.7/scripts/ofpathname
===================================================================
--- powerpc-utils-1.3.7.orig/scripts/ofpathname
+++ powerpc-utils-1.3.7/scripts/ofpathname
@@ -656,7 +656,7 @@ l2of_nvme()
 
         goto_dir $PWD "device/devspec"
 
-        devspec=`$CAT $PWD/device/devspec`
+        devspec=`$CAT $PWD/device/devspec | tr -d '\000'`
         if [[ -n $devspec ]]; then
             found=1
             break
@@ -681,7 +681,7 @@ l2of_nvme()
 
     # Device type is usually 'namespace'.
     # Get it from device-tree just in case.
-    devtype=`$CAT /proc/device-tree${devspec}/namespace/name`
+    devtype=`$CAT /proc/device-tree${devspec}/namespace/name | tr -d '\000'` 2> /dev/null
     if [[ -z $devtype ]]; then
         err $ERR_NO_OFPATH
     fi
openSUSE Build Service is sponsored by