drivers: Simplify libusb_alloc_transfer(0) calls

By using our new, never-failing, USB allocation wrapper. As it can never
fail, we can also remove all the error paths for the allocations
failing.
This commit is contained in:
Bastien Nocera 2018-09-19 17:06:17 +02:00
parent bdba9990fb
commit 10ae8ffb55
18 changed files with 74 additions and 325 deletions

View file

@ -128,15 +128,10 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result,
* away, then increment the SSM */
static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
data = g_malloc(bytes);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes,
generic_ignore_data_cb, ssm, BULK_TIMEOUT);
@ -224,12 +219,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_da
return;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
data = g_malloc(19);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 19,
finger_det_data_cb, dev, BULK_TIMEOUT);
@ -666,14 +656,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
generic_write_regv_cb, ssm);
break;
case CAPTURE_READ_STRIP: ;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(665);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 665,
capture_read_strip_cb, ssm, BULK_TIMEOUT);

View file

@ -115,12 +115,7 @@ static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data)
if (result != 0)
goto err;
transfer = libusb_alloc_transfer(0);
if (!transfer) {
result = -ENOMEM;
goto err;
}
transfer = fpi_usb_alloc();
data = g_malloc(126);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 126,
read_regs_data_cb, rdata, BULK_TIMEOUT);
@ -207,15 +202,10 @@ static void generic_ignore_data_cb(struct libusb_transfer *transfer)
* away, then increment the SSM */
static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
data = g_malloc(bytes);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes,
generic_ignore_data_cb, ssm, BULK_TIMEOUT);
@ -325,12 +315,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result,
return;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
data = g_malloc(20);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 20,
finger_det_data_cb, dev, BULK_TIMEOUT);
@ -548,14 +533,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
generic_write_regv_cb, ssm);
break;
case CAPTURE_READ_STRIP: ;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(1705);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 1705,
capture_read_strip_cb, ssm, BULK_TIMEOUT);

View file

@ -125,12 +125,7 @@ static void finger_det_reqs_cb(struct libusb_transfer *t)
goto exit_free_transfer;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
goto exit_free_transfer;
}
transfer = fpi_usb_alloc();
/* 2 bytes of result */
data = g_malloc(AES2550_EP_IN_BUF_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE,
@ -158,11 +153,7 @@ static void start_finger_detection(struct fp_img_dev *dev)
return;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, finger_det_reqs,
sizeof(finger_det_reqs), finger_det_reqs_cb, dev, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -330,11 +321,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
switch (fpi_ssm_get_cur_state(ssm)) {
case CAPTURE_WRITE_REQS:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_reqs,
sizeof(capture_reqs), capture_reqs_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -346,14 +334,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
break;
case CAPTURE_READ_DATA:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(AES2550_EP_IN_BUF_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE,
capture_read_data_cb, ssm, BULK_TIMEOUT);
@ -368,11 +351,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
break;
case CAPTURE_SET_IDLE:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_set_idle_reqs,
sizeof(capture_set_idle_reqs), capture_set_idle_reqs_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -489,11 +469,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
switch (fpi_ssm_get_cur_state(ssm)) {
case WRITE_INIT:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, init_reqs,
sizeof(init_reqs), init_reqs_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -505,14 +482,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
break;
case READ_DATA:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(AES2550_EP_IN_BUF_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE,
init_read_data_cb, ssm, BULK_TIMEOUT);
@ -527,11 +499,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
break;
case CALIBRATE:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, calibrate_reqs,
sizeof(calibrate_reqs), init_reqs_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -543,14 +512,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
break;
case READ_CALIB_TABLE:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(AES2550_EP_IN_BUF_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE,
calibrate_read_data_cb, ssm, BULK_TIMEOUT);

View file

@ -116,12 +116,7 @@ static void do_capture(struct fp_img_dev *dev)
unsigned char *data;
int r;
aesdev->img_trf = libusb_alloc_transfer(0);
if (!aesdev->img_trf) {
fpi_imgdev_session_error(dev, -EIO);
return;
}
aesdev->img_trf = fpi_usb_alloc();
data = g_malloc(aesdev->data_buflen);
libusb_fill_bulk_transfer(aesdev->img_trf, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data,
aesdev->data_buflen, img_cb, dev, 0);

View file

@ -24,9 +24,9 @@
#include <errno.h>
#include <string.h>
#include <libusb.h>
#include <glib.h>
#include "fpi-usb.h"
#include "assembling.h"
#include "aeslib.h"
@ -73,14 +73,9 @@ static int do_write_regv(struct write_regv_data *wdata, int upper_bound)
unsigned char *data = g_malloc(alloc_size);
unsigned int i;
size_t data_offset = 0;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
int r;
if (!transfer) {
g_free(data);
return -ENOMEM;
}
for (i = offset; i < offset + num; i++) {
const struct aes_regwrite *regwrite = &wdata->regs[i];
data[data_offset++] = regwrite->reg;

View file

@ -46,14 +46,9 @@ aesX660_send_cmd_timeout(fpi_ssm *ssm,
int timeout)
{
struct fp_img_dev *dev = FP_IMG_DEV(_dev);
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT,
(unsigned char *)cmd, cmd_len,
callback, ssm, timeout);
@ -82,15 +77,10 @@ aesX660_read_response(fpi_ssm *ssm,
libusb_transfer_cb_fn callback)
{
struct fp_img_dev *dev = FP_IMG_DEV(_dev);
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
data = g_malloc(buf_len);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN,
data, buf_len,

View file

@ -380,22 +380,16 @@ static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev)
response_len =
elandev->raw_frame_height * elandev->frame_width * 2;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
elandev->cur_transfer = transfer;
elandev->cur_transfer = fpi_usb_alloc();
g_free(elandev->last_read);
elandev->last_read = g_malloc(response_len);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)),
libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)),
elandev->cmd->response_in,
elandev->last_read, response_len, elan_cmd_cb,
ssm, elandev->cmd_timeout);
transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER;
int r = libusb_submit_transfer(transfer);
elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER;
int r = libusb_submit_transfer(elandev->cur_transfer);
if (r < 0)
fpi_ssm_mark_failed(ssm, r);
}
@ -420,18 +414,12 @@ elan_run_cmd(fpi_ssm *ssm,
return;
}
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
elandev->cur_transfer = transfer;
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT,
elandev->cur_transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT,
(char *) cmd->cmd, ELAN_CMD_LEN, elan_cmd_cb, ssm,
elandev->cmd_timeout);
transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER;
int r = libusb_submit_transfer(transfer);
elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER;
int r = libusb_submit_transfer(elandev->cur_transfer);
if (r < 0)
fpi_ssm_mark_failed(ssm, r);
}

View file

@ -640,13 +640,10 @@ static int async_tx(struct fp_img_dev *idev, unsigned int ep, void *cb,
void *cb_arg)
{
struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev));
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *buffer;
int length;
if (!transfer)
return -ENOMEM;
if (ep == EP_OUT) {
buffer = (unsigned char *)dev->req;
length = dev->req_len;

View file

@ -583,13 +583,7 @@ sm_write_regs(fpi_ssm *ssm,
struct write_regs_data *wrdata = g_malloc(sizeof(*wrdata));
unsigned char *data;
wrdata->transfer = libusb_alloc_transfer(0);
if (!wrdata->transfer) {
g_free(wrdata);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
wrdata->transfer = fpi_usb_alloc();
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1);
libusb_fill_control_transfer(wrdata->transfer,
@ -621,15 +615,10 @@ sm_write_reg(fpi_ssm *ssm,
uint8_t reg,
uint8_t value)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
fp_dbg("set %02x=%02x", reg, value);
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data, 0x40, 0x0c, 0, reg, 1);
@ -671,15 +660,10 @@ sm_read_reg(fpi_ssm *ssm,
struct fp_img_dev *dev,
uint8_t reg)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
fp_dbg("read reg %02x", reg);
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 8);
libusb_fill_control_setup(data, 0xc0, 0x0c, 0, reg, 8);
@ -723,15 +707,10 @@ static void
sm_await_intr(fpi_ssm *ssm,
struct fp_img_dev *dev)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
G_DEBUG_HERE();
data = g_malloc(4);
libusb_fill_interrupt_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)),
@ -1302,11 +1281,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state)
sdev->num_flying = 0;
for (i = 0; i < NUM_BULK_TRANSFERS; i++) {
unsigned char *data;
sdev->img_transfer[i] = libusb_alloc_transfer(0);
if (!sdev->img_transfer[i]) {
free_img_transfers(sdev);
return -ENOMEM;
}
sdev->img_transfer[i] = fpi_usb_alloc();
sdev->img_transfer_data[i].idx = i;
sdev->img_transfer_data[i].dev = dev;
data = g_malloc(4096);

View file

@ -109,11 +109,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
switch (fpi_ssm_get_cur_state(ssm)) {
case WRITE_INIT:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out,
(unsigned char*)upekdev->setup_commands[upekdev->init_idx].cmd,
UPEKTC_CMD_LEN, write_init_cb, ssm, BULK_TIMEOUT);
@ -126,14 +123,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
break;
case READ_DATA:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(upekdev->setup_commands[upekdev->init_idx].response_len);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data,
upekdev->setup_commands[upekdev->init_idx].response_len,
@ -228,12 +220,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t)
goto exit_free_transfer;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
goto exit_free_transfer;
}
transfer = fpi_usb_alloc();
data = g_malloc(IMAGE_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE,
finger_det_data_cb, dev, BULK_TIMEOUT);
@ -260,11 +247,7 @@ static void start_finger_detection(struct fp_img_dev *dev)
return;
}
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out,
(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
finger_det_cmd_cb, dev, BULK_TIMEOUT);
@ -332,11 +315,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
switch (fpi_ssm_get_cur_state(ssm)) {
case CAPTURE_WRITE_CMD:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
struct libusb_transfer *transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out,
(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
capture_cmd_cb, ssm, BULK_TIMEOUT);
@ -349,14 +329,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
break;
case CAPTURE_READ_DATA:
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
data = g_malloc(IMAGE_SIZE);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE,
capture_read_data_cb, ssm, BULK_TIMEOUT);

View file

@ -80,16 +80,11 @@ upektc_img_submit_req(fpi_ssm *ssm,
libusb_transfer_cb_fn cb)
{
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
int r;
BUG_ON(buf_size > MAX_CMD_SIZE);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
memcpy(upekdev->cmd, buf, buf_size);
@ -113,15 +108,10 @@ upektc_img_read_data(fpi_ssm *ssm,
size_t buf_offset,
libusb_transfer_cb_fn cb)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
BUG_ON(buf_size > MAX_RESPONSE_SIZE);
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
@ -518,11 +508,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data
{
unsigned char *data;
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
transfer = fpi_usb_alloc();
transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER |
LIBUSB_TRANSFER_FREE_TRANSFER;

View file

@ -90,7 +90,7 @@ static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev,
unsigned char seq_a, unsigned char seq_b, const unsigned char *data,
uint16_t len, libusb_transfer_cb_fn callback, void *user_data)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
uint16_t crc;
const char *ciao = "Ciao";
@ -99,9 +99,6 @@ static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev,
size_t urblen = len + 9;
unsigned char *buf;
if (!transfer)
return NULL;
if (!data && len > 0) {
fp_err("len>0 but no data?");
return NULL;
@ -367,12 +364,9 @@ static void read_msg_cb(struct libusb_transfer *transfer)
* to read the remainder. This is handled below. */
if (len > MAX_DATA_IN_READ_BUF) {
int needed = len - MAX_DATA_IN_READ_BUF;
struct libusb_transfer *etransfer = libusb_alloc_transfer(0);
struct libusb_transfer *etransfer = fpi_usb_alloc();
int r;
if (!transfer)
goto err;
fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed);
data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed);
@ -407,14 +401,9 @@ out:
static int __read_msg_async(struct read_msg_data *udata)
{
unsigned char *buf = g_malloc(MSG_READ_BUF_SIZE);
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
int r;
if (!transfer) {
g_free(buf);
return -ENOMEM;
}
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(udata->dev), EP_IN, buf,
MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -670,12 +659,7 @@ static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data)
case WRITE_CTRL400: ;
unsigned char *data;
transfer = libusb_alloc_transfer(0);
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
break;
}
transfer = fpi_usb_alloc();
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1);

View file

@ -186,13 +186,10 @@ static int write_regs(struct fp_img_dev *dev, uint16_t first_reg,
void *user_data)
{
struct write_regs_data *wrdata;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer)
return -ENOMEM;
wrdata = g_malloc(sizeof(*wrdata));
wrdata->dev = dev;
wrdata->callback = callback;
@ -253,13 +250,10 @@ static int read_regs(struct fp_img_dev *dev, uint16_t first_reg,
uint16_t num_regs, read_regs_cb_fn callback, void *user_data)
{
struct read_regs_data *rrdata;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer)
return -ENOMEM;
rrdata = g_malloc(sizeof(*rrdata));
rrdata->dev = dev;
rrdata->callback = callback;
@ -428,13 +422,10 @@ out:
static int start_irq_handler(struct fp_img_dev *dev)
{
struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev));
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer)
return -ENOMEM;
data = g_malloc(IRQ_LENGTH);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_INTR, data, IRQ_LENGTH,
irq_handler, dev, 0);
@ -1236,7 +1227,7 @@ static int execute_state_change(struct fp_img_dev *dev)
fp_dbg("starting capture");
urudev->irq_cb = NULL;
urudev->img_transfer = libusb_alloc_transfer(0);
urudev->img_transfer = fpi_usb_alloc();
urudev->img_data = g_malloc(sizeof(struct uru4k_image));
urudev->img_enc_seed = rand();

View file

@ -91,15 +91,10 @@ sm_write_reg(fpi_ssm *ssm,
unsigned char reg,
unsigned char value)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
fp_dbg("set %02x=%02x", reg, value);
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE);
libusb_fill_control_setup(data, CTRL_OUT, reg, value, 0, 0);
@ -132,14 +127,9 @@ sm_exec_cmd(fpi_ssm *ssm,
unsigned char cmd,
unsigned char param)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
fp_dbg("cmd %02x param %02x", cmd, param);
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE);
@ -228,14 +218,9 @@ capture_iterate(fpi_ssm *ssm,
{
struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
int iteration = vdev->capture_iteration;
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
struct libusb_transfer *transfer = fpi_usb_alloc();
int r;
if (!transfer) {
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN,
vdev->capture_img->data + (RQ_SIZE * iteration), RQ_SIZE,
capture_cb, ssm, CTRL_TIMEOUT);

View file

@ -60,7 +60,7 @@ async_write(fpi_ssm *ssm,
struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(dev));
struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
vdev->transfer = libusb_alloc_transfer(0);
vdev->transfer = fpi_usb_alloc();
vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
libusb_fill_bulk_transfer(vdev->transfer, usb_dev, 0x01, data, len,
async_write_callback, ssm, VFS_USB_TIMEOUT);
@ -109,7 +109,7 @@ async_read(fpi_ssm *ssm,
ep |= LIBUSB_ENDPOINT_IN;
vdev->transfer = libusb_alloc_transfer(0);
vdev->transfer = fpi_usb_alloc();
vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
/* 0x83 is the only interrupt endpoint */
@ -166,7 +166,7 @@ static void async_abort(fpi_ssm *ssm, int ep)
ep |= LIBUSB_ENDPOINT_IN;
vdev->transfer = libusb_alloc_transfer(0);
vdev->transfer = fpi_usb_alloc();
vdev->transfer->flags |=
LIBUSB_TRANSFER_FREE_TRANSFER | LIBUSB_TRANSFER_FREE_BUFFER;
@ -578,7 +578,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
}
/* Asyncronously enquire an interrupt */
vdev->transfer = libusb_alloc_transfer(0);
vdev->transfer = fpi_usb_alloc();
vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
libusb_fill_interrupt_transfer(vdev->transfer, usb_dev, 0x83,
vdev->interrupt,
@ -628,7 +628,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
}
/* Receive chunk of data */
vdev->transfer = libusb_alloc_transfer(0);
vdev->transfer = fpi_usb_alloc();
vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
libusb_fill_bulk_transfer(vdev->transfer, usb_dev, 0x82,
(void *)vdev->lines_buffer +

View file

@ -247,15 +247,7 @@ async_send(fpi_ssm *ssm,
int r;
/* Allocation of transfer */
vdev->transfer = libusb_alloc_transfer(0);
if (!vdev->transfer)
{
/* Allocation transfer failed, return no memory error */
fp_err("allocation of usb transfer failed");
fpi_imgdev_session_error(dev, -ENOMEM);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
vdev->transfer = fpi_usb_alloc();
/* Put sequential number into the buffer */
vdev->seqnum++;
@ -335,15 +327,7 @@ async_recv(fpi_ssm *ssm,
int r;
/* Allocation of transfer */
vdev->transfer = libusb_alloc_transfer(0);
if (!vdev->transfer)
{
/* Allocation transfer failed, return no memory error */
fp_err("allocation of usb transfer failed");
fpi_imgdev_session_error(dev, -ENOMEM);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
vdev->transfer = fpi_usb_alloc();
/* Prepare bulk transfer */
libusb_fill_bulk_transfer(vdev->transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN(1), vdev->buffer, 0x0f, async_recv_cb, ssm, BULK_TIMEOUT);
@ -438,15 +422,7 @@ async_load(fpi_ssm *ssm,
int r;
/* Allocation of transfer */
vdev->transfer = libusb_alloc_transfer(0);
if (!vdev->transfer)
{
/* Allocation transfer failed, return no memory error */
fp_err("allocation of usb transfer failed");
fpi_imgdev_session_error(dev, -ENOMEM);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
vdev->transfer = fpi_usb_alloc();
/* Append new data into the buffer */
buffer = vdev->buffer + vdev->length;

View file

@ -33,8 +33,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <glib.h>
#include <libusb-1.0/libusb.h>
#include "fpi-usb.h"
#include "vfs301_proto.h"
#include "vfs301_proto_fragments.h"
@ -499,12 +499,7 @@ void vfs301_proto_process_event_start(
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 64);
/* now read the fingerprint data, while there are some */
transfer = libusb_alloc_transfer(0);
if (!transfer) {
dev->recv_progress = VFS301_FAILURE;
return;
}
transfer = fpi_usb_alloc();
dev->recv_progress = VFS301_ONGOING;
dev->recv_exp_amt = VFS301_FP_RECV_LEN_1;

View file

@ -189,13 +189,7 @@ static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
switch (action->type) {
case ACTION_SEND:
fp_dbg("Sending %s", action->name);
transfer = libusb_alloc_transfer(0);
if (transfer == NULL) {
fp_err("Failed to allocate transfer");
fpi_imgdev_session_error(data->device, -ENOMEM);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)),
action->endpoint, action->data,
action->size, async_send_cb, ssm,
@ -205,13 +199,7 @@ static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
case ACTION_RECEIVE:
fp_dbg("Receiving %d bytes", action->size);
transfer = libusb_alloc_transfer(0);
if (transfer == NULL) {
fp_err("Failed to allocate transfer");
fpi_imgdev_session_error(data->device, -ENOMEM);
fpi_ssm_mark_failed(ssm, -ENOMEM);
return;
}
transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)),
action->endpoint, data->receive_buf,
action->size, async_recv_cb, ssm,
@ -464,7 +452,7 @@ static int capture_chunk_async(struct vfs5011_data *data,
STOP_CHECK_LINES = 50
};
data->flying_transfer = libusb_alloc_transfer(0);
data->flying_transfer = fpi_usb_alloc();
libusb_fill_bulk_transfer(data->flying_transfer, handle, VFS5011_IN_ENDPOINT_DATA,
data->capture_buffer,
nline * VFS5011_LINE_SIZE,