adapter = adapter_get(opts.adapter_idx);
- if (adapter == NULL) {
+ if (!adapter) {
print_error("Invalid adapter index: %d", opts.adapter_idx);
return -ENODEV;
adapter = adapter_get(adapter_idx);
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
err = nl_get_targets(adapter);
elem = g_slist_find_custom(opts.snl_list, sdres->uri,
(GCompareFunc)g_strcmp0);
- if (elem != NULL) {
+ if (elem) {
g_free(elem->data);
opts.snl_list = g_slist_delete_link(opts.snl_list,
elem);
printf("\n");
- if (opts.snl_list == NULL) {
+ if (!opts.snl_list) {
opts.snl = false;
nfctool_quit(false);
}
opts.poll_mode = POLLING_MODE_INITIATOR;
- if (value != NULL) {
+ if (value) {
if (*value == 't' || *value == 'T')
opts.poll_mode = POLLING_MODE_TARGET;
else if (*value == 'b' || *value == 'B')
params = g_strsplit(value, ",", -1);
i = 0;
- while (params[i] != NULL) {
+ while (params[i]) {
keyval = g_strsplit(params[i], "=", 2);
- if (keyval[0] == NULL || keyval[1] == NULL) {
+ if (!keyval[0] || !keyval[1]) {
result = false;
goto exit;
}
const gchar *value,
gpointer data, GError **error)
{
- if (value != NULL && (*value == 'a' || *value == 'A'))
+ if (value && (*value == 'a' || *value == 'A'))
opts.show_timestamp = SNIFFER_SHOW_TIMESTAMP_ABS;
else
opts.show_timestamp = SNIFFER_SHOW_TIMESTAMP_DELTA;
goto done;
}
- if (opts.device_name != NULL) {
+ if (opts.device_name) {
if (strncmp("nfc", opts.device_name, 3) != 0) {
print_error("Invalid device name: %s",
opts.device_name);
static void nfctool_options_cleanup(void)
{
- if (opts.device_name != NULL)
+ if (opts.device_name)
g_free(opts.device_name);
- if (opts.pcap_filename != NULL)
+ if (opts.pcap_filename)
g_free(opts.pcap_filename);
g_slist_free_full(opts.snl_list, g_free);
static void nfctool_main_loop_clean(void)
{
- if (main_loop != NULL)
+ if (main_loop)
g_main_loop_unref(main_loop);
}
DBG("");
cb = nl_cb_alloc(NL_CB_DEFAULT);
- if (cb == NULL)
+ if (!cb)
return -ENOMEM;
err = nl_send_auto_complete(sock, msg);
nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, nl_finish_handler, &done);
nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, nl_ack_handler, &done);
- if (rx_handler != NULL)
+ if (rx_handler)
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, rx_handler, data);
while (err == 0 && done == 0)
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
ctrlid = genl_ctrl_resolve(sock, "nlctrl");
genlmsg_parse(nlh, 0, attrs, NFC_ATTR_MAX, NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_PARAMS");
return NL_STOP;
}
DBG("");
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
0, NFC_CMD_LLC_GET_PARAMS, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
if (lto < 0 && rw < 0 && miux < 0)
return -EINVAL;
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
0, NFC_CMD_LLC_SET_PARAMS, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_DUMP, NFC_CMD_GET_TARGET, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
genlmsg_parse(nlh, 0, attrs, NFC_ATTR_MAX, NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_DEVICE");
return NL_STOP;
}
idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
- if (attrs[NFC_ATTR_PROTOCOLS] != NULL)
+ if (attrs[NFC_ATTR_PROTOCOLS])
protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
- if (attrs[NFC_ATTR_RF_MODE] != NULL)
+ if (attrs[NFC_ATTR_RF_MODE])
rf_mode = nla_get_u8(attrs[NFC_ATTR_RF_MODE]);
- if (attrs[NFC_ATTR_DEVICE_POWERED] != NULL)
+ if (attrs[NFC_ATTR_DEVICE_POWERED])
powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
adapter_add(idx, protocols, powered, rf_mode);
DBG("");
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_DUMP, NFC_CMD_GET_DEVICE, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto out;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_DEP_LINK_UP, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("IM protos 0x%x TM protos 0x%x", im_protocols, tm_protocols);
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_START_POLL, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
if (powered)
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, cmd, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_LLC_SDREQ, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, adapter->idx);
sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP);
- if (sdp_attr == NULL) {
+ if (!sdp_attr) {
err = -ENOMEM;
goto nla_put_failure;
}
i = 1;
uri = uris;
- while (uri != NULL) {
+ while (uri) {
uri_attr = nla_nest_start(msg, i);
- if (uri_attr == NULL) {
+ if (!uri_attr) {
err = -ENOMEM;
goto nla_put_failure;
}
continue;
}
- if (sdp_attrs[NFC_SDP_ATTR_URI] == NULL ||
- sdp_attrs[NFC_SDP_ATTR_SAP] == NULL) {
+ if (!sdp_attrs[NFC_SDP_ATTR_URI] ||
+ !sdp_attrs[NFC_SDP_ATTR_SAP]) {
print_error("Missing attribute in reply");
continue;
}
nla_parse(attr, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attr[NFC_ATTR_DEVICE_INDEX] != NULL)
+ if (attr[NFC_ATTR_DEVICE_INDEX])
idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
- if (handlers != NULL)
+ if (handlers)
cb = g_hash_table_lookup(handlers, GINT_TO_POINTER(cmd));
- if (cb == NULL)
+ if (!cb)
return NL_SKIP;
switch (cmd) {
return FALSE;
cb = nl_cb_alloc(NL_CB_VERBOSE);
- if (cb == NULL)
+ if (!cb)
return TRUE;
nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, nl_no_seq_check_cb, NULL);
{
guint32 c = cmd;
- if (handlers != NULL)
+ if (handlers)
g_hash_table_replace(handlers, GINT_TO_POINTER(c), cb);
}
nfc_state = NULL;
}
- if (handlers != NULL)
+ if (handlers)
g_hash_table_destroy(handlers);
}
nfc_state = g_malloc0(sizeof(struct nlnfc_state));
nfc_state->cmd_sock = nl_socket_alloc();
- if (nfc_state->cmd_sock == NULL) {
+ if (!nfc_state->cmd_sock) {
print_error("Failed to allocate NFC netlink socket");
err = -ENOMEM;
goto exit_err;
}
nfc_state->event_sock = nl_socket_alloc();
- if (nfc_state->event_sock == NULL) {
+ if (!nfc_state->event_sock) {
print_error("Failed to allocate NFC netlink socket");
err = -ENOMEM;
goto exit_err;