From 4a61dc413b5cf562ecd796b88e19ce80645660e8 Mon Sep 17 00:00:00 2001 From: Ogier Bouvier Date: Mon, 11 Sep 2017 13:15:42 +0200 Subject: [PATCH] support sector size that are not multiple of 16 Signed-off-by: Ogier Bouvier Squashed the comment into this Signed-off-by: Benjamin Tissoires --- src/hidpp20.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hidpp20.c b/src/hidpp20.c index 99917d49..b87e5bef 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -1132,6 +1132,12 @@ hidpp20_onboard_profiles_read_sector(struct hidpp20_device *device, count = sector_size; for (offset = 0; offset < sector_size; offset += 16) { + /* + * the firmware replies with an ERR_INVALID_ARGUMENT error + * if we try to read past sector_size - 16, so when we are left with + * less than 16 bytes to read we need to read from sector_size - 16 + */ + offset = (sector_size - offset < 16) ? sector_size - 16 : offset; hidpp_set_unaligned_be_u16(&msg.msg.parameters[2], offset); buf = msg; rc = hidpp20_request_command(device, &buf);