Chrome platform driver development
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER
@ 2023-07-26  7:31 Tzung-Bi Shih
  2023-08-01  3:32 ` Tzung-Bi Shih
  0 siblings, 1 reply; 6+ messages in thread
From: Tzung-Bi Shih @ 2023-07-26  7:31 UTC (permalink / raw)
  To: bleung, groeck
  Cc: chrome-platform, guillaume.tucker, denys.f, ricardo.canuelo,
	tzungbi

`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>
---
 drivers/platform/chrome/chromeos_acpi.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/chromeos_acpi.c b/drivers/platform/chrome/chromeos_acpi.c
index 50d8a4d4352d..a60d344c54e4 100644
--- a/drivers/platform/chrome/chromeos_acpi.c
+++ b/drivers/platform/chrome/chromeos_acpi.c
@@ -90,7 +90,25 @@ 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, n;
+			const int char_per_line = 16;
+
+			for (i = 0, n = 0; i < element->buffer.length; ++i) {
+				n += sysfs_emit_at(buf, n, " %2.2x", element->buffer.pointer[i]);
+
+				if (((i + 1) % char_per_line) == 0)
+					n += sysfs_emit_at(buf, n, "\n");
+			}
+			n += sysfs_emit_at(buf, n, "\n");
+
+			if (n == PAGE_SIZE - 1) {
+				dev_info(dev, "truncating sysfs content for %s\n", name);
+				sysfs_emit_at(buf, n - 3, "..\n");
+			}
+
+			return n;
+		}
 	default:
 		dev_err(dev, "element type %d not supported\n", element->type);
 		return -EINVAL;
-- 
2.41.0.487.g6d72f3e995-goog


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

end of thread, other threads:[~2023-08-03  1:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26  7:31 [PATCH] platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER Tzung-Bi Shih
2023-08-01  3:32 ` Tzung-Bi Shih
2023-08-01 21:53   ` Brian Norris
2023-08-02 10:06     ` Tzung-Bi Shih
2023-08-02 18:59       ` Brian Norris
2023-08-03  1:18         ` 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