nfc_device_new(): replace err() by return

Not a good idea to call exit() from a library...
This commit is contained in:
Philippe Teuwen 2013-03-05 19:57:36 +01:00
parent bece73faaf
commit 09ef2e3927
7 changed files with 37 additions and 1 deletions

View file

@ -280,6 +280,10 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring)
char *pcFirmware; char *pcFirmware;
nfc_device *pnd = nfc_device_new(context, fullconnstring); nfc_device *pnd = nfc_device_new(context, fullconnstring);
if (!pnd) {
perror("malloc");
goto error;
}
pnd->driver_data = malloc(sizeof(struct acr122_pcsc_data)); pnd->driver_data = malloc(sizeof(struct acr122_pcsc_data));
if (!pnd->driver_data) { if (!pnd->driver_data) {
perror("malloc"); perror("malloc");

View file

@ -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); 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 // Allocate memory for the device info and specification, fill it and return the info
pnd = nfc_device_new(context, connstring); 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)); acr122_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pnd->driver_data = malloc(sizeof(struct acr122_usb_data)); pnd->driver_data = malloc(sizeof(struct acr122_usb_data));

View file

@ -470,6 +470,10 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
nfc_connstring connstring; nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ACR122S_DRIVER_NAME, acPort, ACR122S_DEFAULT_SPEED); snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ACR122S_DRIVER_NAME, acPort, ACR122S_DEFAULT_SPEED);
nfc_device *pnd = nfc_device_new(context, connstring); nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return -1;
}
pnd->driver = &acr122s_driver; pnd->driver = &acr122s_driver;
pnd->driver_data = malloc(sizeof(struct acr122s_data)); 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); uart_set_speed(sp, ndd.speed);
pnd = nfc_device_new(context, connstring); pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return NULL;
}
pnd->driver = &acr122s_driver; pnd->driver = &acr122s_driver;
strcpy(pnd->name, ACR122S_DRIVER_NAME); strcpy(pnd->name, ACR122S_DRIVER_NAME);

View file

@ -114,6 +114,10 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
nfc_connstring connstring; nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED); snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
nfc_device *pnd = nfc_device_new(context, connstring); nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return 0;
}
pnd->driver = &arygon_driver; pnd->driver = &arygon_driver;
pnd->driver_data = malloc(sizeof(struct arygon_data)); 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 // We have a connection
pnd = nfc_device_new(context, connstring); 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); snprintf(pnd->name, sizeof(pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
pnd->driver_data = malloc(sizeof(struct arygon_data)); pnd->driver_data = malloc(sizeof(struct arygon_data));

View file

@ -88,6 +88,10 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
nfc_connstring connstring; nfc_connstring connstring;
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED); 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); nfc_device *pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return 0;
}
pnd->driver = &pn532_uart_driver; pnd->driver = &pn532_uart_driver;
pnd->driver_data = malloc(sizeof(struct pn532_uart_data)); pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
if (!pnd->driver_data) { if (!pnd->driver_data) {
@ -240,6 +244,10 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
// We have a connection // We have a connection
pnd = nfc_device_new(context, connstring); 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); snprintf(pnd->name, sizeof(pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
pnd->driver_data = malloc(sizeof(struct pn532_uart_data)); pnd->driver_data = malloc(sizeof(struct pn532_uart_data));

View file

@ -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); 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 // Allocate memory for the device info and specification, fill it and return the info
pnd = nfc_device_new(context, connstring); 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)); pn53x_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pnd->driver_data = malloc(sizeof(struct pn53x_usb_data)); pnd->driver_data = malloc(sizeof(struct pn53x_usb_data));

View file

@ -38,7 +38,7 @@ nfc_device_new(const nfc_context *context, const nfc_connstring connstring)
nfc_device *res = malloc(sizeof(*res)); nfc_device *res = malloc(sizeof(*res));
if (!res) { if (!res) {
err(EXIT_FAILURE, "nfc_device_new: malloc"); return NULL;
} }
// Store associated context // Store associated context