From 65f9348bee307be999118cd6c7ea8df67f4713cf Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab@kernel.org>
Date: Tue, 2 Apr 2024 10:54:00 +0200
Subject: [PATCH] scripts/doc_to_xls.py: fix spreadsheet generation

The logic which sets the max_length is wrong: it shall always use
sheet[0], as this may be the only row on a table.

Yet, it might be possible that a caller to test_to_xls() would
have been sending a completely empty sheet. While this doesn't
occur currently, it doesn't hurt adding an explicit check,
reporting a warning if this is indeed the case.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
 scripts/doc_to_xls.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/scripts/doc_to_xls.py b/scripts/doc_to_xls.py
index 448ff1842..3b10a6e9a 100755
--- a/scripts/doc_to_xls.py
+++ b/scripts/doc_to_xls.py
@@ -16,6 +16,8 @@ from openpyxl.styles import Font
 from openpyxl.utils import get_column_letter
 from openpyxl import Workbook
 
+from sys import stderr
+
 from test_list import TestList
 
 EPILOG = """
@@ -47,16 +49,20 @@ def tests_to_xls(tests, fname):
         test = tests[row]
         sheet_name = test.title
 
+        sheet = test.get_spreadsheet(expand_fields)
+        # Ignore empty sheets
+        if not len(sheet):
+            print(f"Warning: sheet '{test.title}' is empty!", file=stderr)
+            continue
+
         if not ws:
             ws = wb.active
             ws.title = sheet_name
         else:
             ws = wb.create_sheet(sheet_name)
 
-        sheet = test.get_spreadsheet(expand_fields)
-
         max_length = []
-        for col in range(len(sheet[row])):
+        for col in range(len(sheet[0])):
             max_length.append(0)
 
         for row in range(len(sheet)):
-- 
GitLab