From 6268d342a79d2484ec182078c343bff338c8e125 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 14 Aug 2013 09:27:56 +0200 Subject: [PATCH] plugins: Do not compare expression against NULL This patch generate via coccinelle with: @ disable is_null,isnt_null1 @ expression E; @@ ( - E == NULL + !E | - E != NULL + E ) --- plugins/handover.c | 26 +++++++++++++------------- plugins/llcp-validation.c | 14 +++++++------- plugins/mifare.c | 26 +++++++++++++------------- plugins/nfctype1.c | 42 +++++++++++++++++++++--------------------- plugins/nfctype2.c | 28 ++++++++++++++-------------- plugins/nfctype3.c | 38 +++++++++++++++++++------------------- plugins/nfctype4.c | 46 +++++++++++++++++++++++----------------------- plugins/npp.c | 4 ++-- plugins/p2p.c | 18 +++++++++--------- plugins/snep-validation.c | 10 +++++----- plugins/snep.c | 2 +- 11 files changed, 127 insertions(+), 127 deletions(-) diff --git a/plugins/handover.c b/plugins/handover.c index 8eee61f..dcca9ab 100644 --- a/plugins/handover.c +++ b/plugins/handover.c @@ -89,7 +89,7 @@ static void free_hr_ndef(gpointer data) { struct hr_ndef *ndef = data; - if (ndef != NULL) + if (ndef) g_free(ndef->ndef); g_free(ndef); @@ -102,7 +102,7 @@ static void handover_close(int client_fd, int err) DBG(""); ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); - if (ndef == NULL) + if (!ndef) return; g_hash_table_remove(hr_ndef_hash, GINT_TO_POINTER(client_fd)); @@ -117,7 +117,7 @@ static int handover_ndef_parse(int client_fd, struct hr_ndef *ndef) DBG(""); - if ((ndef->ndef == NULL) || + if ((!ndef->ndef) || (ndef->cur_ptr < NDEF_HR_MSG_MIN_LENGTH)) { err = -EINVAL; goto fail; @@ -125,7 +125,7 @@ static int handover_ndef_parse(int client_fd, struct hr_ndef *ndef) /* call the global parse function */ records = near_ndef_parse_msg(ndef->ndef, ndef->cur_ptr, &msg); - if (records == NULL) { + if (!records) { err = -ENOMEM; goto fail; } @@ -174,7 +174,7 @@ static bool handover_read_cfg_records(int client_fd, int err; ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); - if (ndef == NULL) { + if (!ndef) { near_error("hr_ndef should exist"); return false; } @@ -183,7 +183,7 @@ static bool handover_read_cfg_records(int client_fd, /* Next prepare read to complete the Hr */ new_ndef = g_try_realloc(ndef->ndef, ndef->cur_record_len + NDEF_HR_MSG_MIN_LENGTH); - if (new_ndef == NULL) + if (!new_ndef) return false; ndef->ndef = new_ndef; @@ -206,7 +206,7 @@ static bool handover_read_cfg_records(int client_fd, /* Next prepare read to complete the NDEF */ new_ndef = g_try_realloc(ndef->ndef, ndef->cur_record_len + ndef_size); - if (new_ndef == NULL) + if (!new_ndef) return false; ndef->ndef = new_ndef; @@ -265,7 +265,7 @@ static bool handover_read_hr(int client_fd, DBG(""); ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); - if (ndef == NULL) + if (!ndef) return false; /* Read remaining bytes */ @@ -322,12 +322,12 @@ static bool handover_read_initialize(int client_fd, /* Allocate the ndef structure */ ndef = g_try_malloc0(sizeof(struct hr_ndef)); - if (ndef == NULL) + if (!ndef) goto fail; /* Allocate and read frame header (6 bytes) */ ndef->ndef = g_try_malloc0(NDEF_HR_MSG_MIN_LENGTH); - if (ndef->ndef == NULL) + if (!ndef->ndef) goto fail; /* Initialize default values */ @@ -363,7 +363,7 @@ static bool handover_read_initialize(int client_fd, /* Next prepare read to complete the read */ ndef->ndef = g_try_realloc(ndef->ndef, ndef->cur_record_len); - if (ndef->ndef == NULL) + if (!ndef->ndef) goto fail; return true; @@ -385,7 +385,7 @@ static bool handover_read(int client_fd, struct hr_ndef *ndef; ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); - if (ndef == NULL) { + if (!ndef) { /* First call: allocate and read header bytes */ return handover_read_initialize(client_fd, adapter_idx, target_idx, cb); @@ -452,7 +452,7 @@ static int handover_push(int client_fd, DBG(""); client = g_try_malloc0(sizeof(struct hr_push_client)); - if (client == NULL) + if (!client) return -ENOMEM; channel = g_io_channel_unix_new(client_fd); diff --git a/plugins/llcp-validation.c b/plugins/llcp-validation.c index 4040133..814584e 100644 --- a/plugins/llcp-validation.c +++ b/plugins/llcp-validation.c @@ -69,7 +69,7 @@ static void free_one_sdu(gpointer data) { struct sdu *i_sdu = data; - if (i_sdu == NULL) + if (!i_sdu) return; g_free(i_sdu->data); @@ -97,7 +97,7 @@ static void llcp_send_data(gpointer data, gpointer user_data) struct sdu *i_sdu = data; int err; - if (i_sdu == NULL) + if (!i_sdu) return; /* conn less or oriented ? */ @@ -144,13 +144,13 @@ static bool llcp_add_incoming_sdu(struct co_cl_client_data *clt, int len) struct sdu *i_sdu; i_sdu = g_try_malloc0(sizeof(struct sdu)); - if (i_sdu == NULL) + if (!i_sdu) goto out_error; i_sdu->len = len; if (len > 0) { i_sdu->data = g_try_malloc0(len); - if (i_sdu->data == NULL) + if (!i_sdu->data) goto out_error; memcpy(i_sdu->data, clt->miu_buffer, len); } @@ -231,9 +231,9 @@ static bool llcp_common_read(int client_fd, uint32_t adapter_idx, cx_client = g_hash_table_lookup(llcp_client_hash, GINT_TO_POINTER(client_fd)); - if (cx_client == NULL) { + if (!cx_client) { cx_client = g_try_malloc0(sizeof(struct co_cl_client_data)); - if (cx_client == NULL) + if (!cx_client) goto error; cx_client->fd = client_fd; @@ -248,7 +248,7 @@ static bool llcp_common_read(int client_fd, uint32_t adapter_idx, cx_client->miu_len = LLCP_DEFAULT_MIU; cx_client->miu_buffer = g_try_malloc0(cx_client->miu_len); - if (cx_client->miu_buffer == NULL) { + if (!cx_client->miu_buffer) { DBG("Cannot allocate MIU buffer (size: %d)", cx_client->miu_len); goto error; diff --git a/plugins/mifare.c b/plugins/mifare.c index 4cb7450..3d37652 100644 --- a/plugins/mifare.c +++ b/plugins/mifare.c @@ -208,7 +208,7 @@ static int mifare_release(int err, void *data) DBG("%p", cookie); - if (cookie == NULL) + if (!cookie) return err; if (err < 0 && cookie->cb) { @@ -489,7 +489,7 @@ static int mifare_read_NFC_loop(uint8_t *resp, int length, void *data) /* Additional sectors to read ? */; - if (mf_ck->g_sect_list != NULL && mf_ck->g_sect_list->next != NULL) { + if (mf_ck->g_sect_list && mf_ck->g_sect_list->next) { err = mifare_read_sector(data, /* cookie */ mf_ck->nfc_data, /* where to store */ @@ -512,7 +512,7 @@ static int mifare_read_NFC_loop(uint8_t *resp, int length, void *data) DBG("Done reading"); nfc_data = near_tag_get_data(mf_ck->tag, &nfc_data_length); - if (nfc_data == NULL) { + if (!nfc_data) { err = -ENOMEM; goto out_err; } @@ -568,7 +568,7 @@ static int mifare_process_MADs(void *data) DBG(""); /* Parse MAD entries to get the global size and fill the array */ - if (mf_ck->mad_1 == NULL) { + if (!mf_ck->mad_1) { err = -EINVAL; goto out_err; } @@ -596,7 +596,7 @@ static int mifare_process_MADs(void *data) /* Now MAD 2 */ ioffset = MAD_V1_AIDS_LEN + 1 + 1; /* skip 0x10 */ - if (mf_ck->mad_2 == NULL) + if (!mf_ck->mad_2) goto done_mad; /* @@ -635,14 +635,14 @@ done_mad: DBG("TAG Global size: [%d]", global_tag_size); mf_ck->tag = near_tag_get_tag(mf_ck->adapter_idx, mf_ck->target_idx); - if (mf_ck->tag == NULL) { + if (!mf_ck->tag) { err = -ENOMEM; goto out_err; } /* don't allocate new data before writing */ tag_data = near_tag_get_data(mf_ck->tag, &data_size); - if (tag_data == NULL) { + if (!tag_data) { err = near_tag_add_data(mf_ck->adapter_idx, mf_ck->target_idx, NULL, /* Empty */ @@ -680,7 +680,7 @@ static int mifare_read_MAD2(void *data) /* As auth is ok, allocate Mifare Access Directory v1 */ mf_ck->mad_2 = g_try_malloc0(STD_SECTOR_SIZE); - if (mf_ck->mad_2 == NULL) { + if (!mf_ck->mad_2) { near_error("Memory allocation failed (MAD2)"); err = -ENOMEM; goto out_err; @@ -743,7 +743,7 @@ static int mifare_read_MAD1(uint8_t *resp, int length, void *data) * allocated size is also STD_SECTOR_SIZE */ mf_ck->mad_1 = g_try_malloc0(STD_SECTOR_SIZE); - if (mf_ck->mad_1 == NULL) { + if (!mf_ck->mad_1) { near_error("Memory allocation failed (MAD1)"); err = -ENOMEM; goto out_err; @@ -839,7 +839,7 @@ int mifare_read(uint32_t adapter_idx, uint32_t target_idx, /* Alloc global cookie */ cookie = g_try_malloc0(sizeof(struct mifare_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; /* Get the nfcid1 */ @@ -906,7 +906,7 @@ int mifare_check_presence(uint32_t adapter_idx, uint32_t target_idx, /* Alloc global cookie */ cookie = g_try_malloc0(sizeof(struct mifare_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; /* Get the nfcid1 */ @@ -1161,7 +1161,7 @@ static int mifare_check_rights_loop(uint8_t *resp, int length, void *data) int err; int sector_id; - if (mf_ck->acc_sect->next != NULL) { + if (mf_ck->acc_sect->next) { mf_ck->acc_sect = mf_ck->acc_sect->next; sector_id = GPOINTER_TO_INT(mf_ck->acc_sect->data); @@ -1308,7 +1308,7 @@ int mifare_write(uint32_t adapter_idx, uint32_t target_idx, /* Alloc global cookie */ cookie = g_try_malloc0(sizeof(struct mifare_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; /* Get the nfcid1 */ diff --git a/plugins/nfctype1.c b/plugins/nfctype1.c index f44ae4c..649081c 100644 --- a/plugins/nfctype1.c +++ b/plugins/nfctype1.c @@ -114,7 +114,7 @@ struct t1_cookie { static void t1_init_cmd(struct type1_tag *tag, struct type1_cmd *cmd) { - if (tag == NULL || cmd == NULL) + if (!tag || !cmd) return; memcpy(cmd->uid, tag->uid, UID_LENGTH); @@ -126,10 +126,10 @@ static int t1_cookie_release(int err, void *data) DBG("%p", cookie); - if (cookie == NULL) + if (!cookie) return err; - if (cookie->cb != NULL) + if (cookie->cb) cookie->cb(cookie->adapter_idx, cookie->target_idx, err); if (cookie->ndef) @@ -280,13 +280,13 @@ static int meta_recv(uint8_t *resp, int length, void *data) goto out_err; tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -ENOMEM; goto out_err; } t1_tag = g_try_malloc0(sizeof(struct type1_tag)); - if (t1_tag == NULL) { + if (!t1_tag) { err = -ENOMEM; goto out_err; } @@ -403,14 +403,14 @@ static int nfctype1_read_meta(uint32_t adapter_idx, uint32_t target_idx, memset(&cmd, 0, sizeof(cmd)); cookie = g_try_malloc0(sizeof(struct t1_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; cookie->target_idx = target_idx; cookie->cb = cb; - if (uid != NULL) { + if (uid) { cmd.cmd = CMD_READ_ALL; /* Read ALL cmd give 124 bytes */ memcpy(cmd.uid, uid, UID_LENGTH); memcpy(cookie->uid, uid, UID_LENGTH); @@ -438,8 +438,8 @@ static int nfctype1_read(uint32_t adapter_idx, DBG(""); uid = near_tag_get_nfcid(adapter_idx, target_idx, &uid_length); - if (uid == NULL || uid_length != UID_LENGTH) { - if (uid != NULL) { + if (!uid || uid_length != UID_LENGTH) { + if (uid) { near_error("Invalid UID"); g_free(uid); @@ -548,7 +548,7 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); uid = near_tag_get_nfcid(adapter_idx, target_idx, &uid_length); - if (uid == NULL || uid_length != UID_LENGTH) { + if (!uid || uid_length != UID_LENGTH) { near_error("Invalid type 1 UID"); err = -EINVAL; goto out_err; @@ -560,7 +560,7 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, memcpy(cmd.uid, uid, UID_LENGTH); cookie = g_try_malloc0(sizeof(struct t1_cookie)); - if (cookie == NULL) { + if (!cookie) { g_free(uid); err = -ENOMEM; goto out_err; @@ -580,7 +580,7 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, sizeof(cmd), data_write_resp, cookie, t1_cookie_release); out_err: - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -605,13 +605,13 @@ static int nfctype1_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); - if (ndef == NULL || cb == NULL) { + if (!ndef || !cb) { err = -EINVAL; goto out_err; } tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -635,7 +635,7 @@ static int nfctype1_write(uint32_t adapter_idx, uint32_t target_idx, return 0; out_err: - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -664,7 +664,7 @@ static int nfctype1_check_presence(uint32_t adapter_idx, DBG(""); uid = near_tag_get_nfcid(adapter_idx, target_idx, &uid_length); - if (uid == NULL || uid_length != UID_LENGTH) { + if (!uid || uid_length != UID_LENGTH) { near_error("Invalid type 1 UID"); return -EINVAL; } @@ -677,7 +677,7 @@ static int nfctype1_check_presence(uint32_t adapter_idx, g_free(uid); cookie = g_try_malloc0(sizeof(struct t1_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -717,7 +717,7 @@ static int format_resp(uint8_t *resp, int length, void *data) t1_cookie_release); } else { tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -742,7 +742,7 @@ static int nfctype1_format(uint32_t adapter_idx, uint32_t target_idx, DBG(""); tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) + if (!tag) return -EINVAL; /* TODO: Dynamic tag format */ @@ -750,13 +750,13 @@ static int nfctype1_format(uint32_t adapter_idx, uint32_t target_idx, return -EOPNOTSUPP; uid = near_tag_get_nfcid(adapter_idx, target_idx, &uid_length); - if (uid == NULL || uid_length != UID_LENGTH) { + if (!uid || uid_length != UID_LENGTH) { near_error("Invalid type 1 UID"); return -EINVAL; } cookie = g_try_malloc0(sizeof(struct t1_cookie)); - if (cookie == NULL) { + if (!cookie) { err = -EINVAL; goto out_err; } diff --git a/plugins/nfctype2.c b/plugins/nfctype2.c index 1de571e..1212882 100644 --- a/plugins/nfctype2.c +++ b/plugins/nfctype2.c @@ -111,10 +111,10 @@ static int t2_cookie_release(int err, void *data) DBG("%p", cookie); - if (cookie == NULL) + if (!cookie) return err; - if (cookie->cb != NULL) + if (cookie->cb) cookie->cb(cookie->adapter_idx, cookie->target_idx, err); if (cookie->ndef) @@ -233,13 +233,13 @@ static int meta_recv(uint8_t *resp, int length, void *data) goto out_err; tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -ENOMEM; goto out_err; } t2_tag = g_try_malloc0(sizeof(struct type2_tag)); - if (t2_tag == NULL) { + if (!t2_tag) { err = -ENOMEM; goto out_err; } @@ -293,7 +293,7 @@ static int nfctype2_read_meta(uint32_t adapter_idx, uint32_t target_idx, cmd.block = META_BLOCK_START; cookie = g_try_malloc0(sizeof(struct t2_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -382,9 +382,9 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); cookie = g_try_malloc0(sizeof(struct t2_cookie)); - if (cookie == NULL) { + if (!cookie) { err = -ENOMEM; - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; } @@ -416,13 +416,13 @@ static int nfctype2_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); - if (ndef == NULL || cb == NULL) { + if (!ndef || !cb) { err = -EINVAL; goto out_err; } tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -462,7 +462,7 @@ static int nfctype2_write(uint32_t adapter_idx, uint32_t target_idx, return 0; out_err: - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -498,7 +498,7 @@ static int nfctype2_check_presence(uint32_t adapter_idx, uint32_t target_idx, cmd.block = META_BLOCK_START; cookie = g_try_malloc0(sizeof(struct t2_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -536,7 +536,7 @@ static int format_resp(uint8_t *resp, int length, void *data) } tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -562,7 +562,7 @@ static int nfctype2_format(uint32_t adapter_idx, uint32_t target_idx, DBG(""); tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) + if (!tag) return -EINVAL; @@ -577,7 +577,7 @@ static int nfctype2_format(uint32_t adapter_idx, uint32_t target_idx, cc_ndef = g_try_malloc0(sizeof(struct near_ndef_message)); cookie = g_try_malloc0(sizeof(struct t2_cookie)); - if (t2_cc == NULL || cc_ndef == NULL || cookie == NULL) { + if (!t2_cc || !cc_ndef || !cookie) { err = -ENOMEM; goto out_err; } diff --git a/plugins/nfctype3.c b/plugins/nfctype3.c index e07b881..d4fbed0 100644 --- a/plugins/nfctype3.c +++ b/plugins/nfctype3.c @@ -142,13 +142,13 @@ static int t3_cookie_release(int err, void *data) DBG("%p", cookie); - if (cookie == NULL) + if (!cookie) return err; - if (cookie->cb != NULL) + if (cookie->cb) cookie->cb(cookie->adapter_idx, cookie->target_idx, err); - if (cookie->ndef != NULL) + if (cookie->ndef) g_free(cookie->ndef->data); g_free(cookie->ndef); @@ -337,7 +337,7 @@ static int nfctype3_recv_block_0(uint8_t *resp, int length, void *data) goto out_err; tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -ENOMEM; goto out_err; } @@ -349,7 +349,7 @@ static int nfctype3_recv_block_0(uint8_t *resp, int length, void *data) near_tag_set_ro(tag, FALSE); t3_tag = g_try_malloc0(sizeof(struct type3_tag)); - if (t3_tag == NULL) { + if (!t3_tag) { err = -ENOMEM; goto out_err; } @@ -440,7 +440,7 @@ static int check_sys_op_in_mc_block(uint8_t *resp, int length, void *data) tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -ENOMEM; goto out_err; } @@ -544,7 +544,7 @@ static int nfctype3_read(uint32_t adapter_idx, cmd.len = LEN_CMD + LEN_CMD_LEN + 4; cookie = g_try_malloc0(sizeof(struct t3_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -672,10 +672,10 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, cookie = g_try_malloc0(sizeof(struct t3_cookie)); - if (cookie == NULL) { + if (!cookie) { err = -ENOMEM; - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -688,13 +688,13 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, cookie->current_block = 0; idm = near_tag_get_idm(tag, &len); - if (idm == NULL) + if (!idm) return t3_cookie_release(-EINVAL, cookie); memcpy(cookie->IDm, idm, len); attr = near_tag_get_attr_block(tag, &len); - if (attr == NULL) + if (!attr) return t3_cookie_release(-EINVAL, cookie); memcpy(cookie->attr, attr, len); @@ -733,13 +733,13 @@ static int nfctype3_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); - if (ndef == NULL || cb == NULL) { + if (!ndef || !cb) { err = -EINVAL; goto out_err; } tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -747,7 +747,7 @@ static int nfctype3_write(uint32_t adapter_idx, uint32_t target_idx, err = data_write(adapter_idx, target_idx, ndef, tag, cb); out_err: - if (cb != NULL && err < 0) + if (cb && err < 0) cb(adapter_idx, target_idx, err); return err; @@ -785,7 +785,7 @@ static int nfctype3_check_presence(uint32_t adapter_idx, cmd.len = LEN_CMD + LEN_CMD_LEN + 4 ; cookie = g_try_malloc0(sizeof(struct t3_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -815,7 +815,7 @@ static int format_resp(uint8_t *resp, int length, void *data) goto out_err; tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -ENOMEM; goto out_err; } @@ -938,7 +938,7 @@ static int nfctype3_format(uint32_t adapter_idx, DBG(""); tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) + if (!tag) return -ENOMEM; ic_type = near_tag_get_ic_type(tag); @@ -946,7 +946,7 @@ static int nfctype3_format(uint32_t adapter_idx, return -EOPNOTSUPP; cookie = g_try_malloc0(sizeof(struct t3_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -955,7 +955,7 @@ static int nfctype3_format(uint32_t adapter_idx, cookie->ic_type = ic_type; idm = near_tag_get_idm(tag, &len); - if (idm == NULL) + if (!idm) return t3_cookie_release(-EINVAL, cookie); memcpy(cookie->IDm, idm, len); diff --git a/plugins/nfctype4.c b/plugins/nfctype4.c index 212b4a8..5596c84 100644 --- a/plugins/nfctype4.c +++ b/plugins/nfctype4.c @@ -165,7 +165,7 @@ static int t4_cookie_release(int err, void *data) DBG("%p", cookie); - if (cookie == NULL) + if (!cookie) return err; if (err < 0 && cookie->cb) @@ -209,7 +209,7 @@ static int ISO_send_cmd(uint8_t class, } cmd = g_try_malloc0(total_cmd_length); - if (cmd == NULL) { + if (!cmd) { DBG("Mem alloc failed"); err = -ENOMEM; goto out_err; @@ -371,7 +371,7 @@ static int t4_readbin_NDEF_ID(uint8_t *resp, int length, void *data) return t4_cookie_release(err, cookie); tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) + if (!tag) return t4_cookie_release(-ENOMEM, cookie); near_tag_set_max_ndef_size(tag, cookie->max_ndef_size); @@ -437,7 +437,7 @@ static int t4_readbin_cc(uint8_t *resp, int length, void *data) /* -2 for status word and -1 is for NFC first byte... */ read_cc = g_try_malloc0(length - 2 - NFC_STATUS_BYTE_LEN); - if (read_cc == NULL) { + if (!read_cc) { DBG("Mem alloc failed"); return t4_cookie_release(-ENOMEM, cookie); @@ -487,7 +487,7 @@ static int t4_select_cc(uint8_t *resp, int length, void *data) cookie->tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (cookie->tag == NULL) + if (!cookie->tag) return t4_cookie_release(-ENOMEM, cookie); near_tag_set_blank(cookie->tag, TRUE); @@ -564,7 +564,7 @@ static int nfctype4_read(uint32_t adapter_idx, DBG(""); cookie = g_try_malloc0(sizeof(struct t4_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -635,10 +635,10 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx, cookie = g_try_malloc0(sizeof(struct t4_cookie)); - if (cookie == NULL) { + if (!cookie) { err = -ENOMEM; - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -691,13 +691,13 @@ static int nfctype4_write(uint32_t adapter_idx, uint32_t target_idx, DBG(""); - if (ndef == NULL || cb == NULL) { + if (!ndef || !cb) { err = -EINVAL; goto out_err; } tag = near_tag_get_tag(adapter_idx, target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -705,7 +705,7 @@ static int nfctype4_write(uint32_t adapter_idx, uint32_t target_idx, err = data_write(adapter_idx, target_idx, ndef, tag, cb); out_err: - if (cb != NULL) + if (cb) cb(adapter_idx, target_idx, err); return err; @@ -736,7 +736,7 @@ static int nfctype4_check_presence(uint32_t adapter_idx, DBG(""); cookie = g_try_malloc0(sizeof(struct t4_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; @@ -798,7 +798,7 @@ static int read_cc_file(uint8_t *resp, int length, void *data) /* -2 for status word and -1 is for NFC first byte... */ read_cc = g_try_malloc0(length - 2 - NFC_STATUS_BYTE_LEN); - if (read_cc == NULL) { + if (!read_cc) { err = -ENOMEM; goto out_err; } @@ -808,7 +808,7 @@ static int read_cc_file(uint8_t *resp, int length, void *data) cookie->max_ndef_size = g_ntohs(read_cc->tlv_fc.max_ndef_size); tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) { + if (!tag) { err = -EINVAL; goto out_err; } @@ -920,7 +920,7 @@ static int format_resp(uint8_t *resp, int length, void *data) } tag = near_tag_get_tag(cookie->adapter_idx, cookie->target_idx); - if (tag == NULL) + if (!tag) return t4_cookie_release(-EINVAL, cookie); DBG("Formatting is done"); @@ -978,7 +978,7 @@ static int write_data_to_ndef_file(uint8_t *resp, int length, void *data) + ARRAY_SIZE(ndef_nlen); cmd_data = g_try_malloc0(cmd_data_length); - if (cmd_data == NULL) { + if (!cmd_data) { err = -ENOMEM; goto out_err; } @@ -1029,7 +1029,7 @@ static int create_ndef_file(uint8_t *resp, int length, void *data) } ndef = g_try_malloc0(sizeof(struct desfire_std_file)); - if (ndef == NULL) { + if (!ndef) { err = -ENOMEM; goto out_err; } @@ -1090,7 +1090,7 @@ static int write_data_to_cc_file(uint8_t *resp, int length, void *data) } cc = g_try_malloc0(sizeof(struct desfire_cc_file)); - if (cc == NULL) { + if (!cc) { err = -ENOMEM; goto out_err; } @@ -1150,7 +1150,7 @@ static int create_cc_file(uint8_t *resp, int length, void *data) } cc = g_try_malloc0(sizeof(struct desfire_std_file)); - if (cc == NULL) { + if (!cc) { err = -ENOMEM; goto out_err; } @@ -1206,7 +1206,7 @@ static int select_application_1(uint8_t *resp, int length, void *data) /* Step4 : Select application (which is created just now) */ cmd_data_length = ARRAY_SIZE(desfire_aid_1); cmd_data = g_try_malloc0(cmd_data_length); - if (cmd_data == NULL) { + if (!cmd_data) { err = -ENOMEM; goto out_err; } @@ -1252,7 +1252,7 @@ static int create_application(uint8_t *resp, int length, void *data) } app = g_try_malloc0(sizeof(struct desfire_app)); - if (app == NULL) { + if (!app) { err = -ENOMEM; goto out_err; } @@ -1307,7 +1307,7 @@ static int select_application(uint8_t *resp, int length, void *data) /* AID : 000000h */ cmd_data_length = ARRAY_SIZE(desfire_aid); cmd_data = g_try_malloc0(cmd_data_length); - if (cmd_data == NULL) { + if (!cmd_data) { err = -ENOMEM; goto out_err; } @@ -1435,7 +1435,7 @@ static int nfctype4_format(uint32_t adapter_idx, uint32_t target_idx, DBG(""); cookie = g_try_malloc0(sizeof(struct t4_cookie)); - if (cookie == NULL) + if (!cookie) return -ENOMEM; cookie->adapter_idx = adapter_idx; diff --git a/plugins/npp.c b/plugins/npp.c index 55c391b..3df49eb 100644 --- a/plugins/npp.c +++ b/plugins/npp.c @@ -93,7 +93,7 @@ static bool npp_read(int client_fd, DBG("NDEF %d length %d", i, ndef_length); new_ndefs = g_try_realloc(ndefs, total_ndef_length); - if (new_ndefs == NULL) { + if (!new_ndefs) { near_error("Could not allocate NDEF buffer %d", bytes_recv); err = -ENOMEM; @@ -127,7 +127,7 @@ static bool npp_read(int client_fd, return false; device = near_device_get_device(adapter_idx, target_idx); - if (device == NULL) { + if (!device) { g_free(ndefs); return -ENOMEM; } diff --git a/plugins/p2p.c b/plugins/p2p.c index 2026223..5191926 100644 --- a/plugins/p2p.c +++ b/plugins/p2p.c @@ -146,7 +146,7 @@ static gboolean p2p_client_event(GIOChannel *channel, GIOCondition condition, else err = 0; - if (client_data->driver->close != NULL) + if (client_data->driver->close) client_data->driver->close(client_data->fd, err); near_error("%s client channel closed", @@ -186,7 +186,7 @@ static void free_client_data(gpointer data) client_data = (struct p2p_data *) data; - if (client_data->driver->close != NULL) + if (client_data->driver->close) client_data->driver->close(client_data->fd, 0); if (client_data->watch > 0) @@ -257,7 +257,7 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition, DBG("target idx %d", client_addr.target_idx); client_data = g_try_malloc0(sizeof(struct p2p_data)); - if (client_data == NULL) { + if (!client_data) { close(client_fd); return FALSE; } @@ -382,7 +382,7 @@ static gboolean p2p_connect_event(GIOChannel *channel, GIOCondition condition, DBG("condition 0x%x", condition); - if (conn->driver->push == NULL) { + if (!conn->driver->push) { err = -EOPNOTSUPP; goto out; } @@ -456,7 +456,7 @@ static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx, return -errno; server_data = g_try_malloc0(sizeof(struct p2p_data)); - if (server_data == NULL) { + if (!server_data) { close(fd); return -ENOMEM; } @@ -482,7 +482,7 @@ static int p2p_listen(uint32_t adapter_idx, near_device_io_cb cb) int err = -1, bind_err; GSList *list; - for (list = driver_list; list != NULL; list = list->next) { + for (list = driver_list; list; list = list->next) { struct near_p2p_driver *driver = list->data; bind_err = p2p_bind(driver, adapter_idx, cb); @@ -515,7 +515,7 @@ static int p2p_connect(uint32_t adapter_idx, uint32_t target_idx, return -errno; conn = g_try_malloc0(sizeof(struct p2p_connect)); - if (conn == NULL) { + if (!conn) { close(fd); return -ENOMEM; } @@ -574,7 +574,7 @@ static int p2p_push(uint32_t adapter_idx, uint32_t target_idx, DBG(""); - for (list = driver_list; list != NULL; list = list->next) { + for (list = driver_list; list; list = list->next) { struct near_p2p_driver *driver = list->data; if (strcmp(driver->service_name, service_name) != 0) @@ -588,7 +588,7 @@ static int p2p_push(uint32_t adapter_idx, uint32_t target_idx, if (fd > 0) return fd; - if (driver->fallback_service_name != NULL) + if (driver->fallback_service_name) return p2p_push(adapter_idx, target_idx, ndef, (char *) driver->fallback_service_name, cb); diff --git a/plugins/snep-validation.c b/plugins/snep-validation.c index 1128a32..86c8905 100644 --- a/plugins/snep-validation.c +++ b/plugins/snep-validation.c @@ -51,7 +51,7 @@ static void free_snep_validation_client(gpointer data) { GList *old_ndefs = data; - if (old_ndefs != NULL) + if (old_ndefs) g_list_free(old_ndefs); } @@ -68,7 +68,7 @@ static bool snep_validation_server_req_put(int client_fd, void *data) DBG(""); - if (snep_data->nfc_data == NULL) + if (!snep_data->nfc_data) goto error; /* @@ -85,7 +85,7 @@ static bool snep_validation_server_req_put(int client_fd, void *data) recd = records->data; - if (recd == NULL) { + if (!recd) { g_list_free(records); goto error; } @@ -145,7 +145,7 @@ static bool snep_validation_server_req_get(int client_fd, void *data) } recd = records->data; - if (recd == NULL) { + if (!recd) { g_list_free(records); goto error; } @@ -159,7 +159,7 @@ static bool snep_validation_server_req_get(int client_fd, void *data) incoming_ndefs = g_hash_table_lookup(snep_validation_hash, GINT_TO_POINTER(client_fd)); - if (incoming_ndefs == NULL) + if (!incoming_ndefs) goto done; /* Now, loop to find the the associated record */ diff --git a/plugins/snep.c b/plugins/snep.c index d10f6e2..f77c0a3 100644 --- a/plugins/snep.c +++ b/plugins/snep.c @@ -69,7 +69,7 @@ static bool snep_default_server_req_put(int client_fd, void *data) device = near_device_get_device(snep_data->adapter_idx, snep_data->target_idx); - if (device == NULL) + if (!device) return false; records = near_ndef_parse_msg(snep_data->nfc_data, -- 2.7.4