Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER

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

Print hex string for ACPI_TYPE_BUFFER. Also update the documentation
to reflect this.

Fixes: 0a4cad9c11ad ("platform/chrome: Add ChromeOS ACPI device driver")
Cc: stable@vger.kernel.org
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20230803011245.3773756-1-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

+31 -2
+1 -1
Documentation/ABI/testing/sysfs-driver-chromeos-acpi
··· 149 149 Description: 150 150 Returns the verified boot data block shared between the 151 151 firmware verification step and the kernel verification step 152 - (binary). 152 + (hex dump).
+30 -1
drivers/platform/chrome/chromeos_acpi.c
··· 90 90 case ACPI_TYPE_STRING: 91 91 return sysfs_emit(buf, "%s\n", element->string.pointer); 92 92 case ACPI_TYPE_BUFFER: 93 - return sysfs_emit(buf, "%s\n", element->buffer.pointer); 93 + { 94 + int i, r, at, room_left; 95 + const int byte_per_line = 16; 96 + 97 + at = 0; 98 + room_left = PAGE_SIZE - 1; 99 + for (i = 0; i < element->buffer.length && room_left; i += byte_per_line) { 100 + r = hex_dump_to_buffer(element->buffer.pointer + i, 101 + element->buffer.length - i, 102 + byte_per_line, 1, buf + at, room_left, 103 + false); 104 + if (r > room_left) 105 + goto truncating; 106 + at += r; 107 + room_left -= r; 108 + 109 + r = sysfs_emit_at(buf, at, "\n"); 110 + if (!r) 111 + goto truncating; 112 + at += r; 113 + room_left -= r; 114 + } 115 + 116 + buf[at] = 0; 117 + return at; 118 + truncating: 119 + dev_info_once(dev, "truncating sysfs content for %s\n", name); 120 + sysfs_emit_at(buf, PAGE_SIZE - 4, "..\n"); 121 + return PAGE_SIZE - 1; 122 + } 94 123 default: 95 124 dev_err(dev, "element type %d not supported\n", element->type); 96 125 return -EINVAL;