From bacdab259653512e06631075216f090eadc435dc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Oct 2017 17:49:56 +1000 Subject: [PATCH] Sanity-check the list of dpi values and report rates Signed-off-by: Peter Hutterer --- ratbagd/ratbagd-test.c | 4 +++- src/libratbag.c | 26 ++++++++++++++++++++++++++ test/test-device.c | 8 ++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ratbagd/ratbagd-test.c b/ratbagd/ratbagd-test.c index 0db12e49..d93e4c85 100644 --- a/ratbagd/ratbagd-test.c +++ b/ratbagd/ratbagd-test.c @@ -64,7 +64,9 @@ static const struct ratbag_test_device ratbagd_test_device_descr = { } }, .resolutions = { - { .xres = 100, .yres = 200, .hz = 1000, .dpi_min = 50, .dpi_max = 5000 }, + { .xres = 100, .yres = 200, .hz = 1000, + .dpi_min = 50, .dpi_max = 5000, + .report_rates = { 500, 1000 } }, { .xres = 200, .yres = 300, .hz = 1000, .active = true, .dflt = true }, { .xres = 300, .yres = 400, .hz = 1000 }, }, diff --git a/src/libratbag.c b/src/libratbag.c index e2e32bde..53e29eeb 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -247,6 +247,8 @@ ratbag_sanity_check_device(struct ratbag_device *device) } ratbag_device_for_each_profile(device, profile) { + struct ratbag_resolution *resolution; + /* Allow max 1 active profile */ if (profile->is_active) { if (has_active) { @@ -266,6 +268,30 @@ ratbag_sanity_check_device(struct ratbag_device *device) nres); goto out; } + + ratbag_profile_for_each_resolution(profile, resolution) { + unsigned int vals[300]; + unsigned int nvals = ARRAY_LENGTH(vals); + + if (!ratbag_device_has_capability(device, RATBAG_DEVICE_CAP_RESOLUTION)) + break; + + nvals = ratbag_resolution_get_dpi_list(resolution, vals, nvals); + if (nvals == 0) { + log_bug_libratbag(ratbag, + "%s: invalid dpi list\n", + device->name); + goto out; + } + + nvals = ratbag_resolution_get_report_rate_list(resolution, vals, nvals); + if (nvals == 0) { + log_bug_libratbag(ratbag, + "%s: invalid report rate list\n", + device->name); + goto out; + } + } } /* Require 1 active profile */ diff --git a/test/test-device.c b/test/test-device.c index 703f81a4..3524f9b5 100644 --- a/test/test-device.c +++ b/test/test-device.c @@ -59,7 +59,9 @@ const struct ratbag_test_device sane_device = { .profiles = { { .resolutions = { - { .xres = 100, .yres = 200, .hz = 1000 }, + { .xres = 100, .yres = 200, .hz = 1000, + .dpi_min = 100, .dpi_max = 5000, + .report_rates = { 500, 1000 } }, { .xres = 200, .yres = 300, .hz = 1000 }, { .xres = 300, .yres = 400, .hz = 1000 }, }, @@ -354,7 +356,9 @@ START_TEST(device_resolutions) .profiles = { { .resolutions = { - { .xres = 100, .yres = 200, .hz = 1000, .dpi_min = 50, .dpi_max = 5000}, + { .xres = 100, .yres = 200, .hz = 1000, + .dpi_min = 50, .dpi_max = 5000, + .report_rates = { 500, 1000 } }, { .xres = 200, .yres = 300, .hz = 1000, .active = true }, { .xres = 300, .yres = 400, .hz = 1000 }, },