From cbe1111e4e68702ac3d1b23c4a65b81052f0656c Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sun, 4 Nov 2007 18:57:44 +0000 Subject: [PATCH] uru4000: handle images without headers While testing the new code on my MS keyboard, I found some strange conditions where occasionally, the device will stop providing images headers until it is replugged. Detect and work around this when it happens. --- libfprint/drivers/uru4000.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index ef9746e..0fecfc9 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -305,6 +305,7 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, int r; struct fp_img *img; size_t image_size = DATABLK1_RQLEN + DATABLK2_EXPECT - CAPTURE_HDRLEN; + int hdr_skip = CAPTURE_HDRLEN; r = set_mode(dev, MODE_CAPTURE); if (r < 0) @@ -338,13 +339,20 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, fp_err("part 2 capture failed, error %d", r); goto err; } else if (r != DATABLK2_EXPECT) { - fp_err("unexpected part 2 capture size (%d)", r); - r = -EIO; - goto err; + if (r == DATABLK2_EXPECT - CAPTURE_HDRLEN) { + /* this is rather odd, but it happens sometimes with my MS + * keyboard */ + fp_dbg("got image with no header!"); + hdr_skip = 0; + } else { + fp_err("unexpected part 2 capture size (%d)", r); + r = -EIO; + goto err; + } } /* remove header and shrink allocation */ - g_memmove(img->data, img->data + CAPTURE_HDRLEN, image_size); + g_memmove(img->data, img->data + hdr_skip, image_size); img = fpi_img_resize(img, image_size); img->flags = FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED | FP_IMG_COLORS_INVERTED;