From 3cbc9e14b26ab3382998096fe583302b24854a3d Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Sun, 9 Jun 2024 01:34:52 +0100 Subject: [PATCH 1/8] Add support for Chromium OS EC --- src/ioctl.h | 19 +++++++++++++++++++ src/ioctl.vapi | 3 +++ src/ioctl_tree.c | 40 ++++++++++++++++++++++++++++++++-------- src/ioctl_tree.h | 1 + src/ioctl_tree.vapi | 2 ++ src/umockdev-ioctl.vala | 12 ++++++++++-- 6 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/ioctl.h diff --git a/src/ioctl.h b/src/ioctl.h new file mode 100644 index 00000000..8454797d --- /dev/null +++ b/src/ioctl.h @@ -0,0 +1,19 @@ +#ifndef __IOCTL_H +#define __IOCTL_H + +#include + +struct cros_ec_command_v2 { + uint32_t version; + uint32_t command; + uint32_t outsize; + uint32_t insize; + uint32_t result; + uint8_t data[0]; +}; + +#define CROS_EC_DEV_IOC_V2 0xEC +#define CROS_EC_DEV_IOCXCMD_V2 \ + _IOWR(CROS_EC_DEV_IOC_V2, 0, struct cros_ec_command_v2) + +#endif diff --git a/src/ioctl.vapi b/src/ioctl.vapi index 53ba5188..a316b22d 100644 --- a/src/ioctl.vapi +++ b/src/ioctl.vapi @@ -131,5 +131,8 @@ namespace Ioctl { uint32 size; uint8 value[HID_MAX_DESCRIPTOR_SIZE]; } + + [CCode (cheader_filename = "ioctl.h")] + public const int CROS_EC_DEV_IOCXCMD_V2; } diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index 87d7d857..b50772ae 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -29,6 +29,7 @@ #include "debug.h" #include "utils.h" +#include "ioctl.h" #include "ioctl_tree.h" #define TRUE 1 @@ -414,6 +415,18 @@ ioctl_tree_execute(ioctl_tree * tree, ioctl_tree * last, IOCTL_REQUEST_TYPE id, return NULL; } +int +ioctl_tree_next_ret(ioctl_tree * tree, ioctl_tree * last) +{ + const ioctl_tree *i = ioctl_tree_next_wrap(tree, last); + + if (i == NULL) { + return 0; + } + + return i->ret; +} + /*********************************** * * Utility functions for ioctl implementations @@ -555,10 +568,6 @@ ioctl_simplestruct_in_execute(const ioctl_tree * node, IOCTL_REQUEST_TYPE id, vo * ***********************************/ -/* Note, we don't currently have any of those */ - -#if 0 - static void ioctl_varlenstruct_init_from_bin(ioctl_tree * node, const void *data) { @@ -622,8 +631,6 @@ ioctl_varlenstruct_in_execute(const ioctl_tree * node, IOCTL_REQUEST_TYPE id, vo return 0; } -#endif - /*********************************** * * USBDEVFS_REAPURB @@ -872,11 +879,11 @@ ioctl_insertion_parent_stateless(ioctl_tree * tree, UNUSED ioctl_tree *_node) I_NAMED_SIZED_SIMPLE_STRUCT_IN(name, #name, -1, nr_range, insertion_parent_fn) /* input structs with a variable length (but no pointers to substructures) */ -#define I_VARLEN_STRUCT_IN(name, insertion_parent_fn, data_size_fn) \ +#define I_VARLEN_STRUCT_IN(name, equal_fn, insertion_parent_fn, data_size_fn) \ {name, -1, 0, #name, \ ioctl_varlenstruct_init_from_bin, ioctl_varlenstruct_init_from_text, \ ioctl_simplestruct_free_data, \ - ioctl_varlenstruct_write, ioctl_varlenstruct_equal, \ + ioctl_varlenstruct_write, equal_fn, \ ioctl_varlenstruct_in_execute, insertion_parent_fn, data_size_fn} /* data with custom handlers; necessary for structs with pointers to nested @@ -892,6 +899,20 @@ ioctl_insertion_parent_stateless(ioctl_tree * tree, UNUSED ioctl_tree *_node) {name, size, nr_range, #name, \ NULL, NULL, NULL, NULL, NULL, NULL, NULL} \ +static int +cros_ec_ioctl_equal(UNUSED const ioctl_tree *_n1, UNUSED const ioctl_tree *_n2) +{ + return FALSE; +} + +static size_t +cros_ec_ioctl_get_data_size(IOCTL_REQUEST_TYPE _id, const void *data) +{ + const struct cros_ec_command_v2 *s_cmd = (struct cros_ec_command_v2 *)data; + + return sizeof(struct cros_ec_command_v2) + s_cmd->insize; +} + ioctl_type ioctl_db[] = { I_SIMPLE_STRUCT_IN(USBDEVFS_CONNECTINFO, 0, ioctl_insertion_parent_stateless), @@ -960,6 +981,9 @@ ioctl_type ioctl_db[] = { I_NAMED_SIMPLE_STRUCT_IN(HIDIOCGOUTPUT(32), "HIDIOCGOUTPUT", 0, ioctl_insertion_parent_stateless), #endif + /* cros_ec */ + I_VARLEN_STRUCT_IN(CROS_EC_DEV_IOCXCMD_V2, cros_ec_ioctl_equal, ioctl_insertion_parent_stateless, cros_ec_ioctl_get_data_size), + /* terminator */ {0, 0, 0, "", NULL, NULL, NULL, NULL, NULL} }; diff --git a/src/ioctl_tree.h b/src/ioctl_tree.h index 956b07cb..679e6268 100644 --- a/src/ioctl_tree.h +++ b/src/ioctl_tree.h @@ -73,6 +73,7 @@ ioctl_tree *ioctl_tree_insert(ioctl_tree * tree, ioctl_tree * node); ioctl_tree *ioctl_tree_find_equal(ioctl_tree * tree, ioctl_tree * node); ioctl_tree *ioctl_tree_next(const ioctl_tree * node); ioctl_tree *ioctl_tree_execute(ioctl_tree * tree, ioctl_tree * last, IOCTL_REQUEST_TYPE id, void *arg, int *ret); +int ioctl_tree_next_ret(ioctl_tree * tree, ioctl_tree * last); /* node lists */ ioctl_node_list *ioctl_node_list_new(void); diff --git a/src/ioctl_tree.vapi b/src/ioctl_tree.vapi index 930ad653..68e80936 100644 --- a/src/ioctl_tree.vapi +++ b/src/ioctl_tree.vapi @@ -13,6 +13,8 @@ namespace IoctlTree { public void* execute(void* last, ulong id, void* addr, ref int ret); [CCode (instance_pos = -1)] public void write(Posix.FILE f); + + public int next_ret(void* last); } public int data_size_by_id(ulong id); diff --git a/src/umockdev-ioctl.vala b/src/umockdev-ioctl.vala index d0e65e63..302a619f 100644 --- a/src/umockdev-ioctl.vala +++ b/src/umockdev-ioctl.vala @@ -906,7 +906,13 @@ internal class IoctlTreeHandler : IoctlBase { return true; } + last = client.get_data("last"); + try { + if (request == Ioctl.CROS_EC_DEV_IOCXCMD_V2) { + size += tree.next_ret(last); + } + if (size > 0) data = client.arg.resolve(0, size); @@ -927,8 +933,6 @@ internal class IoctlTreeHandler : IoctlBase { return false; } - last = client.get_data("last"); - if ((char) type == 'E') { Posix.errno = Posix.ENOENT; } else { @@ -1030,6 +1034,10 @@ internal class IoctlTreeRecorder : IoctlBase { return true; } + if (request == Ioctl.CROS_EC_DEV_IOCXCMD_V2) { + size += ret; + } + /* Resolve data */ if (size > 0) data = client.arg.resolve(0, size); From 5c5b0f6db452582be2745e0b2159948aa74f2c6b Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Sun, 9 Jun 2024 02:47:37 +0100 Subject: [PATCH 2/8] Add unit tests for cros_ec device --- devices/cros_ec/crosfingerprint.ioctl | 4 + devices/cros_ec/crosfingerprint.umockdev | 93 ++++++++++++++++++++++++ docs/reference/meson.build | 2 +- meson.build | 1 + src/ioctl.vapi | 9 +++ tests/test-umockdev-vala.vala | 52 +++++++++++++ 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 devices/cros_ec/crosfingerprint.ioctl create mode 100644 devices/cros_ec/crosfingerprint.umockdev diff --git a/devices/cros_ec/crosfingerprint.ioctl b/devices/cros_ec/crosfingerprint.ioctl new file mode 100644 index 00000000..20528bca --- /dev/null +++ b/devices/cros_ec/crosfingerprint.ioctl @@ -0,0 +1,4 @@ +@DEV /dev/cros_fp +CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000080000000 +CROS_EC_DEV_IOCXCMD_V2 48 010000000304000000000000300000000000000046504320090000001B020000010000009466000047524559A000A0000800FF0324140000050001000100000004000000 +CROS_EC_DEV_IOCXCMD_V2 22 000000000704000000000000160000000000000065630100B44A020007B30300DC33505A070000000000 diff --git a/devices/cros_ec/crosfingerprint.umockdev b/devices/cros_ec/crosfingerprint.umockdev new file mode 100644 index 00000000..719b38e6 --- /dev/null +++ b/devices/cros_ec/crosfingerprint.umockdev @@ -0,0 +1,93 @@ +P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0/cros-ec-dev.2.auto/misc/cros_fp +N: cros_fp +E: DEVNAME=/dev/cros_fp +E: MAJOR=10 +E: MINOR=122 +E: SUBSYSTEM=misc +A: dev=10:122\n +L: device=../../../cros-ec-dev.2.auto +A: power/control=auto\n +A: power/runtime_active_time=0\n +A: power/runtime_status=unsupported\n +A: power/runtime_suspended_time=0\n + +P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0/cros-ec-dev.2.auto +E: DRIVER=cros-ec-dev +E: ID_PATH=platform-AMDI0020:01-platform-cros-ec-dev.2.auto +E: ID_PATH_TAG=platform-AMDI0020_01-platform-cros-ec-dev_2_auto +E: ID_VENDOR_FROM_DATABASE=Amdek Corporation +E: MODALIAS=platform:cros-ec-dev +E: SUBSYSTEM=platform +L: driver=../../../../../../../../bus/platform/drivers/cros-ec-dev +A: driver_override=(null)\n +A: modalias=platform:cros-ec-dev\n +A: power/control=auto\n +A: power/runtime_active_time=0\n +A: power/runtime_status=unsupported\n +A: power/runtime_suspended_time=0\n + +P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0 +E: DRIVER=cros-ec-uart +E: MODALIAS=of:NcrfpTCgoogle,cros-ec-uart +E: SUBSYSTEM=serial +L: driver=../../../../../../../bus/serial/drivers/cros-ec-uart +L: firmware_node=../../../../../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01/PRP0001:00 +A: modalias=of:NcrfpTCgoogle,cros-ec-uart\n +A: power/control=auto\n +A: power/runtime_active_time=0\n +A: power/runtime_status=unsupported\n +A: power/runtime_suspended_time=0\n + +P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0 +E: SUBSYSTEM=serial +L: firmware_node=../../../../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01 +A: power/wakeup=disabled\n +A: power/wakeup_abort_count=\n +A: power/wakeup_active=\n +A: power/wakeup_active_count=\n +A: power/wakeup_count=\n +A: power/wakeup_expire_count=\n +A: power/wakeup_last_time_ms=\n +A: power/wakeup_max_time_ms=\n +A: power/wakeup_total_time_ms=\n +L: software_node=../../../../../../kernel/software_nodes/node1 +A: waiting_for_supplier=0\n + +P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0 +E: DEVTYPE=port +E: DRIVER=port +E: SUBSYSTEM=serial-base +L: driver=../../../../../bus/serial-base/drivers/port +A: power/autosuspend_delay_ms=500\n +A: power/control=auto\n +A: power/runtime_active_time=31736669\n +A: power/runtime_status=active\n +A: power/runtime_suspended_time=5190\n + +P: /devices/platform/AMDI0020:01/AMDI0020:01:0 +E: DEVTYPE=ctrl +E: DRIVER=ctrl +E: SUBSYSTEM=serial-base +L: driver=../../../../bus/serial-base/drivers/ctrl +A: power/control=auto\n +A: power/runtime_active_time=31736676\n +A: power/runtime_status=active\n +A: power/runtime_suspended_time=5190\n + +P: /devices/platform/AMDI0020:01 +E: DRIVER=dw-apb-uart +E: ID_PATH=platform-AMDI0020:01 +E: ID_PATH_TAG=platform-AMDI0020_01 +E: ID_VENDOR_FROM_DATABASE=Amdek Corporation +E: MODALIAS=acpi:AMDI0020: +E: SUBSYSTEM=platform +L: driver=../../../bus/platform/drivers/dw-apb-uart +A: driver_override=(null)\n +L: firmware_node=../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01 +A: modalias=acpi:AMDI0020:\n +A: power/control=auto\n +A: power/runtime_active_time=31736687\n +A: power/runtime_status=active\n +A: power/runtime_suspended_time=5189\n +L: software_node=../../../kernel/software_nodes/node1 + diff --git a/docs/reference/meson.build b/docs/reference/meson.build index 38033109..c25c385d 100644 --- a/docs/reference/meson.build +++ b/docs/reference/meson.build @@ -10,7 +10,7 @@ gnome.gtkdoc('umockdev', content_files: [version_xml], gobject_typesfile: 'umockdev.types', scan_args: ['--ignore-decorators', 'VALA_EXTERN'], - ignore_headers: ['uevent_sender.h', 'ioctl_tree.h', 'debug.h'], + ignore_headers: ['uevent_sender.h', 'ioctl.h', 'ioctl_tree.h', 'debug.h'], dependencies: [glib, gobject, declare_dependency(link_with : [umockdev_lib])], install: true, ) diff --git a/meson.build b/meson.build index 063b8296..1ef90d8d 100644 --- a/meson.build +++ b/meson.build @@ -278,6 +278,7 @@ if gudev.found() test('umockdev-vala', executable('test-umockdev-vala', 'tests/test-umockdev-vala.vala', + include_directories: include_directories('src'), dependencies: [glib, gobject, gio, gudev, vapi_posix, vapi_assertions, vapi_ioctl, vapi_glibc, vapi_selinux, selinux], link_with: [umockdev_lib, umockdev_utils_lib], vala_args: optional_defines), diff --git a/src/ioctl.vapi b/src/ioctl.vapi index a316b22d..f22827b8 100644 --- a/src/ioctl.vapi +++ b/src/ioctl.vapi @@ -134,5 +134,14 @@ namespace Ioctl { [CCode (cheader_filename = "ioctl.h")] public const int CROS_EC_DEV_IOCXCMD_V2; + [CCode (cname = "struct cros_ec_command_v2", cheader_filename = "ioctl.h")] + public struct cros_ec_command_v2 { + uint32 version; + uint32 command; + uint32 outsize; + uint32 insize; + uint32 result; + uint8 data[0]; + } } diff --git a/tests/test-umockdev-vala.vala b/tests/test-umockdev-vala.vala index 035fd911..cc939f66 100644 --- a/tests/test-umockdev-vala.vala +++ b/tests/test-umockdev-vala.vala @@ -781,6 +781,56 @@ t_hidraw_ioctl () Posix.close (fd); } +void +t_cros_ec_ioctl () +{ + var tb = new UMockdev.Testbed (); + + string device; + checked_file_get_contents (Path.build_filename(rootdir + "/devices/cros_ec/crosfingerprint.umockdev"), out device); + tb_add_from_string (tb, device); + + try { + tb.load_ioctl ("/dev/cros_fp", Path.build_filename(rootdir + "/devices/cros_ec/crosfingerprint.ioctl")); + } catch (Error e) { + error ("Cannot load ioctl file: %s", e.message); + } + + int fd = Posix.open ("/dev/cros_fp", Posix.O_RDWR, 0); + assert_cmpint (fd, CompareOperator.GE, 0); + + Ioctl.cros_ec_command_v2 *s_cmd = malloc (sizeof (Ioctl.cros_ec_command_v2) + 4); + assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 4); + assert_cmpint (Posix.errno, CompareOperator.EQ, 0); + uint8 fpmode_data[] = { + 0x80, 0x00, 0x00, 0x00 + }; + assert_cmpint (Posix.memcmp(s_cmd->data, fpmode_data, 4), CompareOperator.EQ, 0); + + s_cmd = realloc(s_cmd, sizeof (Ioctl.cros_ec_command_v2) + 48); + assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 48); + assert_cmpint (Posix.errno, CompareOperator.EQ, 0); + uint8 fpinfo_data[] = { + 0x46, 0x50, 0x43, 0x20, 0x09, 0x00, 0x00, 0x00, 0x1B, 0x02, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x94, 0x66, 0x00, 0x00, 0x47, 0x52, 0x45, 0x59, + 0xA0, 0x00, 0xA0, 0x00, 0x08, 0x00, 0xFF, 0x03, 0x24, 0x14, 0x00, 0x00, + 0x05, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 + }; + assert_cmpint (Posix.memcmp(s_cmd->data, fpinfo_data, 48), CompareOperator.EQ, 0); + + s_cmd = realloc(s_cmd, sizeof (Ioctl.cros_ec_command_v2) + 22); + assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 22); + assert_cmpint (Posix.errno, CompareOperator.EQ, 0); + uint8 fpstats_data[] = { + 0x65, 0x63, 0x01, 0x00, 0xB4, 0x4A, 0x02, 0x00, 0x07, 0xB3, 0x03, 0x00, + 0xDC, 0x33, 0x50, 0x5A, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + assert_cmpint (Posix.memcmp(s_cmd->data, fpstats_data, 22), CompareOperator.EQ, 0); + + free (s_cmd); + Posix.close (fd); +} + void t_tty_stty () { @@ -1153,6 +1203,8 @@ main (string[] args) Test.add_func ("/umockdev-testbed-vala/hidraw_ioctl", t_hidraw_ioctl); + Test.add_func ("/umockdev-testbed-vala/cros_ec_ioctl", t_cros_ec_ioctl); + /* tests for mocking TTYs */ Test.add_func ("/umockdev-testbed-vala/tty_stty", t_tty_stty); Test.add_func ("/umockdev-testbed-vala/tty_data", t_tty_data); From 7eaf4b4e6021dc27122bbb1760e555d24af0d9b7 Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Sun, 9 Jun 2024 15:43:07 +0100 Subject: [PATCH 3/8] rename ioctl.h to cros_ec.h --- docs/reference/meson.build | 2 +- src/{ioctl.h => cros_ec.h} | 4 ++-- src/ioctl.vapi | 4 ++-- src/ioctl_tree.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/{ioctl.h => cros_ec.h} (88%) diff --git a/docs/reference/meson.build b/docs/reference/meson.build index c25c385d..d30ed8be 100644 --- a/docs/reference/meson.build +++ b/docs/reference/meson.build @@ -10,7 +10,7 @@ gnome.gtkdoc('umockdev', content_files: [version_xml], gobject_typesfile: 'umockdev.types', scan_args: ['--ignore-decorators', 'VALA_EXTERN'], - ignore_headers: ['uevent_sender.h', 'ioctl.h', 'ioctl_tree.h', 'debug.h'], + ignore_headers: ['uevent_sender.h', 'cros_ec.h', 'ioctl_tree.h', 'debug.h'], dependencies: [glib, gobject, declare_dependency(link_with : [umockdev_lib])], install: true, ) diff --git a/src/ioctl.h b/src/cros_ec.h similarity index 88% rename from src/ioctl.h rename to src/cros_ec.h index 8454797d..8b8874c7 100644 --- a/src/ioctl.h +++ b/src/cros_ec.h @@ -1,5 +1,5 @@ -#ifndef __IOCTL_H -#define __IOCTL_H +#ifndef __CROS_EC_H +#define __CROS_EC_H #include diff --git a/src/ioctl.vapi b/src/ioctl.vapi index f22827b8..1fa6dfae 100644 --- a/src/ioctl.vapi +++ b/src/ioctl.vapi @@ -132,9 +132,9 @@ namespace Ioctl { uint8 value[HID_MAX_DESCRIPTOR_SIZE]; } - [CCode (cheader_filename = "ioctl.h")] + [CCode (cheader_filename = "cros_ec.h")] public const int CROS_EC_DEV_IOCXCMD_V2; - [CCode (cname = "struct cros_ec_command_v2", cheader_filename = "ioctl.h")] + [CCode (cname = "struct cros_ec_command_v2", cheader_filename = "cros_ec.h")] public struct cros_ec_command_v2 { uint32 version; uint32 command; diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index b50772ae..fe346641 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -29,7 +29,7 @@ #include "debug.h" #include "utils.h" -#include "ioctl.h" +#include "cros_ec.h" #include "ioctl_tree.h" #define TRUE 1 From 1ab8d591fe06e2607d4398f93bcaa00afaa94b0b Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Sun, 9 Jun 2024 16:12:06 +0100 Subject: [PATCH 4/8] Empty commit to trigger build From f4b126f530b8516408e598f02339ba0d6727dc27 Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Sun, 9 Jun 2024 23:59:06 +0100 Subject: [PATCH 5/8] Add CROS_EC_DEV_IOCEVENTMASK_V2 ioctl --- src/cros_ec.h | 1 + src/ioctl_tree.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cros_ec.h b/src/cros_ec.h index 8b8874c7..96f7725c 100644 --- a/src/cros_ec.h +++ b/src/cros_ec.h @@ -15,5 +15,6 @@ struct cros_ec_command_v2 { #define CROS_EC_DEV_IOC_V2 0xEC #define CROS_EC_DEV_IOCXCMD_V2 \ _IOWR(CROS_EC_DEV_IOC_V2, 0, struct cros_ec_command_v2) +#define CROS_EC_DEV_IOCEVENTMASK_V2 _IO(CROS_EC_DEV_IOC_V2, 2) #endif diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index fe346641..8f993419 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -983,6 +983,7 @@ ioctl_type ioctl_db[] = { /* cros_ec */ I_VARLEN_STRUCT_IN(CROS_EC_DEV_IOCXCMD_V2, cros_ec_ioctl_equal, ioctl_insertion_parent_stateless, cros_ec_ioctl_get_data_size), + I_NOSTATE(CROS_EC_DEV_IOCEVENTMASK_V2, enodata), /* terminator */ {0, 0, 0, "", NULL, NULL, NULL, NULL, NULL} From 222a60a2a20732d1240119ce3c55644b6a86267b Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Mon, 10 Jun 2024 19:48:52 +0100 Subject: [PATCH 6/8] convert insize to host byte order before use in calculating data size --- meson.build | 2 +- src/ioctl_tree.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 1ef90d8d..f8e65432 100644 --- a/meson.build +++ b/meson.build @@ -135,7 +135,7 @@ preload_lib = shared_library('umockdev-preload', 'src/ioctl_tree.c'], c_args: ['-fvisibility=default'], version: '0.0.0', - dependencies: [dl, pthread], + dependencies: [dl, glib, pthread], install: true) # diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index 8f993419..320c20d3 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -32,9 +33,6 @@ #include "cros_ec.h" #include "ioctl_tree.h" -#define TRUE 1 -#define FALSE 0 - #define UNUSED __attribute__ ((unused)) @@ -910,7 +908,7 @@ cros_ec_ioctl_get_data_size(IOCTL_REQUEST_TYPE _id, const void *data) { const struct cros_ec_command_v2 *s_cmd = (struct cros_ec_command_v2 *)data; - return sizeof(struct cros_ec_command_v2) + s_cmd->insize; + return sizeof(struct cros_ec_command_v2) + GUINT32_FROM_LE(s_cmd->insize); } ioctl_type ioctl_db[] = { From ddd2a1c1d4ed455704d3a8b9c3c8f7e3493c142b Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Tue, 11 Jun 2024 21:02:29 +0100 Subject: [PATCH 7/8] Revert "convert insize to host byte order before use in calculating data size" This reverts commit 222a60a2a20732d1240119ce3c55644b6a86267b. --- meson.build | 2 +- src/ioctl_tree.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index f8e65432..1ef90d8d 100644 --- a/meson.build +++ b/meson.build @@ -135,7 +135,7 @@ preload_lib = shared_library('umockdev-preload', 'src/ioctl_tree.c'], c_args: ['-fvisibility=default'], version: '0.0.0', - dependencies: [dl, glib, pthread], + dependencies: [dl, pthread], install: true) # diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index 320c20d3..8f993419 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,9 @@ #include "cros_ec.h" #include "ioctl_tree.h" +#define TRUE 1 +#define FALSE 0 + #define UNUSED __attribute__ ((unused)) @@ -908,7 +910,7 @@ cros_ec_ioctl_get_data_size(IOCTL_REQUEST_TYPE _id, const void *data) { const struct cros_ec_command_v2 *s_cmd = (struct cros_ec_command_v2 *)data; - return sizeof(struct cros_ec_command_v2) + GUINT32_FROM_LE(s_cmd->insize); + return sizeof(struct cros_ec_command_v2) + s_cmd->insize; } ioctl_type ioctl_db[] = { From e68fd6db6b312012a0521f236fd9a2adbc47ac3a Mon Sep 17 00:00:00 2001 From: Abhinav Baid Date: Tue, 11 Jun 2024 21:06:12 +0100 Subject: [PATCH 8/8] convert insize to host byte order before use in calculating data size (using le32toh) --- src/ioctl_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ioctl_tree.c b/src/ioctl_tree.c index 8f993419..d94b6275 100644 --- a/src/ioctl_tree.c +++ b/src/ioctl_tree.c @@ -910,7 +910,7 @@ cros_ec_ioctl_get_data_size(IOCTL_REQUEST_TYPE _id, const void *data) { const struct cros_ec_command_v2 *s_cmd = (struct cros_ec_command_v2 *)data; - return sizeof(struct cros_ec_command_v2) + s_cmd->insize; + return sizeof(struct cros_ec_command_v2) + le32toh(s_cmd->insize); } ioctl_type ioctl_db[] = {