pn53x_data_new() now returns null ptr upon malloc() error
This commit is contained in:
parent
af57df532b
commit
06d5b54308
8 changed files with 55 additions and 12 deletions
|
@ -3122,11 +3122,13 @@ pn53x_current_target_is(const struct nfc_device *pnd, const nfc_target *pnt)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void *
|
||||||
pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io)
|
pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io)
|
||||||
{
|
{
|
||||||
pnd->chip_data = malloc(sizeof(struct pn53x_data));
|
pnd->chip_data = malloc(sizeof(struct pn53x_data));
|
||||||
|
if (!pnd->chip_data) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
// Keep I/O functions
|
// Keep I/O functions
|
||||||
CHIP_DATA(pnd)->io = io;
|
CHIP_DATA(pnd)->io = io;
|
||||||
|
|
||||||
|
@ -3165,6 +3167,8 @@ pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io)
|
||||||
CHIP_DATA(pnd)->supported_modulation_as_initiator = NULL;
|
CHIP_DATA(pnd)->supported_modulation_as_initiator = NULL;
|
||||||
|
|
||||||
CHIP_DATA(pnd)->supported_modulation_as_target = NULL;
|
CHIP_DATA(pnd)->supported_modulation_as_target = NULL;
|
||||||
|
|
||||||
|
return pnd->chip_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -394,7 +394,7 @@ int pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, cons
|
||||||
int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||||
int pn53x_get_information_about(nfc_device *pnd, char **pbuf);
|
int pn53x_get_information_about(nfc_device *pnd, char **pbuf);
|
||||||
|
|
||||||
void pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io);
|
void *pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io);
|
||||||
void pn53x_data_free(struct nfc_device *pnd);
|
void pn53x_data_free(struct nfc_device *pnd);
|
||||||
|
|
||||||
#endif // __NFC_CHIPS_PN53X_H__
|
#endif // __NFC_CHIPS_PN53X_H__
|
||||||
|
|
|
@ -264,7 +264,10 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &acr122_pcsc_io);
|
if (pn53x_data_new(pnd, &acr122_pcsc_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
SCARDCONTEXT *pscc;
|
SCARDCONTEXT *pscc;
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,10 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
*DRIVER_DATA(pnd) = data;
|
*DRIVER_DATA(pnd) = data;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &acr122_usb_io);
|
if (pn53x_data_new(pnd, &acr122_usb_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&(DRIVER_DATA(pnd)->tama_frame), acr122_usb_frame_template, sizeof(acr122_usb_frame_template));
|
memcpy(&(DRIVER_DATA(pnd)->tama_frame), acr122_usb_frame_template, sizeof(acr122_usb_frame_template));
|
||||||
memcpy(&(DRIVER_DATA(pnd)->apdu_frame), acr122_usb_frame_template, sizeof(acr122_usb_frame_template));
|
memcpy(&(DRIVER_DATA(pnd)->apdu_frame), acr122_usb_frame_template, sizeof(acr122_usb_frame_template));
|
||||||
|
|
|
@ -454,7 +454,12 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
||||||
DRIVER_DATA(pnd)->abort_flag = false;
|
DRIVER_DATA(pnd)->abort_flag = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pn53x_data_new(pnd, &acr122s_io);
|
if (pn53x_data_new(pnd, &acr122s_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
CHIP_DATA(pnd)->type = PN532;
|
CHIP_DATA(pnd)->type = PN532;
|
||||||
CHIP_DATA(pnd)->power_mode = NORMAL;
|
CHIP_DATA(pnd)->power_mode = NORMAL;
|
||||||
|
|
||||||
|
@ -583,7 +588,12 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
DRIVER_DATA(pnd)->abort_flag = false;
|
DRIVER_DATA(pnd)->abort_flag = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pn53x_data_new(pnd, &acr122s_io);
|
if (pn53x_data_new(pnd, &acr122s_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
CHIP_DATA(pnd)->type = PN532;
|
CHIP_DATA(pnd)->type = PN532;
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
|
@ -135,7 +135,12 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &arygon_tama_io);
|
if (pn53x_data_new(pnd, &arygon_tama_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// pipe-based abort mecanism
|
// pipe-based abort mecanism
|
||||||
|
@ -259,7 +264,12 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &arygon_tama_io);
|
if (pn53x_data_new(pnd, &arygon_tama_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// The PN53x chip opened to ARYGON MCU doesn't seems to be in LowVBat mode
|
// The PN53x chip opened to ARYGON MCU doesn't seems to be in LowVBat mode
|
||||||
CHIP_DATA(pnd)->power_mode = NORMAL;
|
CHIP_DATA(pnd)->power_mode = NORMAL;
|
||||||
|
|
|
@ -104,7 +104,12 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &pn532_uart_io);
|
if (pn53x_data_new(pnd, &pn532_uart_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||||
CHIP_DATA(pnd)->type = PN532;
|
CHIP_DATA(pnd)->type = PN532;
|
||||||
// This device starts in LowVBat power mode
|
// This device starts in LowVBat power mode
|
||||||
|
@ -231,7 +236,12 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &pn532_uart_io);
|
if (pn53x_data_new(pnd, &pn532_uart_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||||
CHIP_DATA(pnd)->type = PN532;
|
CHIP_DATA(pnd)->type = PN532;
|
||||||
// This device starts in LowVBat mode
|
// This device starts in LowVBat mode
|
||||||
|
|
|
@ -337,7 +337,10 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
*DRIVER_DATA(pnd) = data;
|
*DRIVER_DATA(pnd) = data;
|
||||||
|
|
||||||
// Alloc and init chip's data
|
// Alloc and init chip's data
|
||||||
pn53x_data_new(pnd, &pn53x_usb_io);
|
if (pn53x_data_new(pnd, &pn53x_usb_io) == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
switch (DRIVER_DATA(pnd)->model) {
|
switch (DRIVER_DATA(pnd)->model) {
|
||||||
// empirical tuning
|
// empirical tuning
|
||||||
|
|
Loading…
Add table
Reference in a new issue