Commit 09ef2e39 authored by Philippe Teuwen's avatar Philippe Teuwen

nfc_device_new(): replace err() by return

Not a good idea to call exit() from a library...
parent bece73fa
......@@ -280,6 +280,10 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring)
char *pcFirmware;
nfc_device *pnd = nfc_device_new(context, fullconnstring);
if (!pnd) {
perror("malloc");
goto error;
}
pnd->driver_data = malloc(sizeof(struct acr122_pcsc_data));
if (!pnd->driver_data) {
perror("malloc");
......
......@@ -475,6 +475,10 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
data.model = acr122_usb_get_device_model(dev->descriptor.idVendor, dev->descriptor.idProduct);
// Allocate memory for the device info and specification, fill it and return the info
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
goto error;
}
acr122_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pnd->driver_data = malloc(sizeof(struct acr122_usb_data));
......
......@@ -470,6 +470,10 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ACR122S_DRIVER_NAME, acPort, ACR122S_DEFAULT_SPEED);
nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return -1;
}
pnd->driver = &acr122s_driver;
pnd->driver_data = malloc(sizeof(struct acr122s_data));
......@@ -574,6 +578,10 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
uart_set_speed(sp, ndd.speed);
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return NULL;
}
pnd->driver = &acr122s_driver;
strcpy(pnd->name, ACR122S_DRIVER_NAME);
......
......@@ -114,6 +114,10 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return 0;
}
pnd->driver = &arygon_driver;
pnd->driver_data = malloc(sizeof(struct arygon_data));
......@@ -263,6 +267,10 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
// We have a connection
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return NULL;
}
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
pnd->driver_data = malloc(sizeof(struct arygon_data));
......
......@@ -88,6 +88,10 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED);
nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return 0;
}
pnd->driver = &pn532_uart_driver;
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
if (!pnd->driver_data) {
......@@ -240,6 +244,10 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
// We have a connection
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return NULL;
}
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
......
......@@ -360,6 +360,10 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
data.model = pn53x_usb_get_device_model(dev->descriptor.idVendor, dev->descriptor.idProduct);
// Allocate memory for the device info and specification, fill it and return the info
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
goto error;
}
pn53x_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pnd->driver_data = malloc(sizeof(struct pn53x_usb_data));
......
......@@ -38,7 +38,7 @@ nfc_device_new(const nfc_context *context, const nfc_connstring connstring)
nfc_device *res = malloc(sizeof(*res));
if (!res) {
err(EXIT_FAILURE, "nfc_device_new: malloc");
return NULL;
}
// Store associated context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment