Chrome platform driver development
 help / color / mirror / Atom feed
* [PATCH v2] platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER
@ 2023-08-02  9:57 Tzung-Bi Shih
  2023-08-02 15:15 ` Muhammad Usama Anjum
  2023-08-02 16:04 ` Guenter Roeck
  0 siblings, 2 replies; 8+ messages in thread
From: Tzung-Bi Shih @ 2023-08-02  9:57 UTC (permalink / raw)
  To: bleung, groeck
  Cc: chrome-platform, tzungbi, guillaume.tucker, denys.f,
	ricardo.canuelo, usama.anjum, briannorris

`element->buffer.pointer` should be binary blob.  `%s` doesn't work
perfect for them.

Print hex string for ACPI_TYPE_BUFFER.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
Changes from v1[1]:
- Use hex_dump_to_buffer().
- Rewrite the loop for catching edge cases for truncating.

[1]: https://patchwork.kernel.org/project/chrome-platform/patch/20230726073127.2969387-1-tzungbi@kernel.org/

 drivers/platform/chrome/chromeos_acpi.c | 31 ++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/chromeos_acpi.c b/drivers/platform/chrome/chromeos_acpi.c
index 50d8a4d4352d..761506d307ad 100644
--- a/drivers/platform/chrome/chromeos_acpi.c
+++ b/drivers/platform/chrome/chromeos_acpi.c
@@ -90,7 +90,36 @@ static int chromeos_acpi_handle_package(struct device *dev, union acpi_object *o
 	case ACPI_TYPE_STRING:
 		return sysfs_emit(buf, "%s\n", element->string.pointer);
 	case ACPI_TYPE_BUFFER:
-		return sysfs_emit(buf, "%s\n", element->buffer.pointer);
+		{
+			int i, r, at, room_left;
+			const int byte_per_line = 16;
+
+			at = 0;
+			room_left = PAGE_SIZE - 1;
+			for (i = 0; i < element->buffer.length && room_left; i += byte_per_line) {
+				r = hex_dump_to_buffer(element->buffer.pointer + i,
+						       element->buffer.length - i,
+						       byte_per_line, 1, buf + at, room_left,
+						       false);
+				if (r > room_left)
+					goto truncating;
+				at += r;
+				room_left -= r;
+
+				r = sysfs_emit_at(buf, at, "\n");
+				if (!r)
+					goto truncating;
+				at += r;
+				room_left -= r;
+			}
+
+			buf[at] = 0;
+			return at;
+truncating:
+			dev_info(dev, "truncating sysfs content for %s\n", name);
+			sysfs_emit_at(buf, PAGE_SIZE - 4, "..\n");
+			return PAGE_SIZE - 1;
+		}
 	default:
 		dev_err(dev, "element type %d not supported\n", element->type);
 		return -EINVAL;
-- 
2.41.0.585.gd2178a4bd4-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-10  3:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-02  9:57 [PATCH v2] platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER Tzung-Bi Shih
2023-08-02 15:15 ` Muhammad Usama Anjum
2023-08-03  1:23   ` Tzung-Bi Shih
2023-08-03  4:17     ` Muhammad Usama Anjum
2023-08-07  3:37       ` Tzung-Bi Shih
2023-08-10  3:06         ` Tzung-Bi Shih
2023-08-02 16:04 ` Guenter Roeck
2023-08-03  1:20   ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox