Skip to content

Commit

Permalink
platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER
Browse files Browse the repository at this point in the history
commit 0820deb upstream.

`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: 0a4cad9 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Tzung-Bi Shih authored and gregkh committed Sep 13, 2023
1 parent e6e6a5f commit a3f6c14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Documentation/ABI/testing/sysfs-driver-chromeos-acpi
Expand Up @@ -134,4 +134,4 @@ KernelVersion: 5.19
Description:
Returns the verified boot data block shared between the
firmware verification step and the kernel verification step
(binary).
(hex dump).
31 changes: 30 additions & 1 deletion drivers/platform/chrome/chromeos_acpi.c
Expand Up @@ -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_once(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;
Expand Down

0 comments on commit a3f6c14

Please sign in to comment.