hwmon.pl remove hwmon entries with no name

It turns out that the MRW XML may have empty HWMON
units, in which case we don't want to show them since
they wouldn't have a label anyway.

Change-Id: If253de98caf4e493ec8112618dc97b43ae911733
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/hwmon.pl b/hwmon.pl
index a708a89..46f7b73 100755
--- a/hwmon.pl
+++ b/hwmon.pl
@@ -54,6 +54,10 @@
                                                       "unit-hwmon-feature",
                                                       $chip);
 
+        #If the MRW doesn't specify a label for a particular hwmon
+        #feature, then we don't want to use it.
+        removeUnusedHwmons(\@hwmonUnits);
+
         #If chip didn't have hwmon units, it isn't hwmon enabled.
         next unless (scalar @hwmonUnits > 0);
 
@@ -68,6 +72,31 @@
 }
 
 
+#Removes entries from the list of hwmon units passed in that have
+#an empty HWMON_NAME or DESCRIPTIVE_NAME attribute.
+sub removeUnusedHwmons
+{
+    my ($units) = @_;
+    my $i = 0;
+
+    while ($i <= $#$units) {
+
+        my $hwmon = $g_targetObj->getAttributeField($$units[$i],
+                                                    "HWMON_FEATURE",
+                                                    "HWMON_NAME");
+        my $name = $g_targetObj->getAttributeField($$units[$i],
+                                                   "HWMON_FEATURE",
+                                                   "DESCRIPTIVE_NAME");
+        if (($hwmon eq "") || ($name eq "")) {
+            splice(@$units, $i, 1);
+        }
+        else {
+            $i++;
+        }
+    }
+}
+
+
 #Reads the hwmon related attributes from the HWMON_FEATURE
 #complex attribute and adds them to the hash.
 sub getHwmonAttributes