core: Do not compare expression against NULL
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 14 Aug 2013 07:27:57 +0000 (09:27 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 20 Aug 2013 09:05:31 +0000 (11:05 +0200)
This patch generate via coccinelle with:

@ disable is_null,isnt_null1 @
expression E;
@@

(
- E == NULL
+ !E
|
- E != NULL
+ E
)

13 files changed:
src/adapter.c
src/agent.c
src/bluetooth.c
src/dbus.c
src/device.c
src/log.c
src/main.c
src/manager.c
src/ndef.c
src/netlink.c
src/plugin.c
src/snep.c
src/tag.c

index 53d76cf..0b85ef5 100644 (file)
@@ -154,7 +154,7 @@ static void rf_mode_changed(struct near_adapter *adapter)
 {
        const char *rf_mode = rf_mode_to_string(adapter);
 
-       if (rf_mode == NULL)
+       if (!rf_mode)
                return;
 
        near_dbus_property_changed_basic(adapter->path,
@@ -209,7 +209,7 @@ static void append_path(gpointer key, gpointer value, gpointer user_data)
 
        DBG("%s", adapter->path);
 
-       if (adapter->path == NULL)
+       if (!adapter->path)
                return;
 
        dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
@@ -266,7 +266,7 @@ static void append_tag_path(gpointer key, gpointer value, gpointer user_data)
        const char *tag_path;
 
        tag_path = __near_tag_get_path(tag);
-       if (tag_path == NULL)
+       if (!tag_path)
                return;
 
        DBG("%s", tag_path);
@@ -290,7 +290,7 @@ static void append_device_path(gpointer key, gpointer value, gpointer user_data)
        const char *device_path;
 
        device_path = __near_device_get_path(device);
-       if (device_path == NULL)
+       if (!device_path)
                return;
 
        DBG("%s", device_path);
@@ -316,7 +316,7 @@ void __near_adapter_tags_changed(uint32_t adapter_idx)
 
        adapter = g_hash_table_lookup(adapter_hash,
                                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        near_dbus_property_changed_array(adapter->path,
@@ -333,7 +333,7 @@ void __near_adapter_devices_changed(uint32_t adapter_idx)
 
        adapter = g_hash_table_lookup(adapter_hash,
                                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        near_dbus_property_changed_array(adapter->path,
@@ -354,7 +354,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBG("conn %p", conn);
 
        reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
+       if (!reply)
                return NULL;
 
        dbus_message_iter_init_append(reply, &array);
@@ -370,7 +370,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
                                    DBUS_TYPE_BOOLEAN, &val);
 
        rf_mode = rf_mode_to_string(adapter);
-       if (rf_mode != NULL)
+       if (rf_mode)
                near_dbus_dict_append_basic(&dict, "Mode",
                                                DBUS_TYPE_STRING, &rf_mode);
 
@@ -498,11 +498,11 @@ static gboolean check_presence(gpointer user_data)
 
        DBG("");
 
-       if (adapter == NULL)
+       if (!adapter)
                return FALSE;
 
        tag = adapter->tag_link;
-       if (tag == NULL)
+       if (!tag)
                goto out_err;
 
        err = __near_tag_check_presence(tag, tag_present_cb);
@@ -527,7 +527,7 @@ static gboolean dep_timer(gpointer user_data)
 
        DBG("");
 
-       if (adapter == NULL)
+       if (!adapter)
                return FALSE;
 
        adapter_start_poll(adapter);
@@ -544,7 +544,7 @@ static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
 
        adapter = g_hash_table_lookup(adapter_hash,
                                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        if (status < 0) {
@@ -571,7 +571,7 @@ void __near_adapter_start_check_presence(uint32_t adapter_idx,
 
        adapter = g_hash_table_lookup(adapter_hash,
                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        adapter->presence_timeout =
@@ -588,7 +588,7 @@ void __near_adapter_stop_check_presence(uint32_t adapter_idx,
 
        adapter = g_hash_table_lookup(adapter_hash,
                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        if (adapter->presence_timeout > 0)
@@ -623,11 +623,11 @@ struct near_adapter *__near_adapter_create(uint32_t idx,
        bool powered_setting;
 
        adapter = g_try_malloc0(sizeof(struct near_adapter));
-       if (adapter == NULL)
+       if (!adapter)
                return NULL;
 
        adapter->name = g_strdup(name);
-       if (adapter->name == NULL) {
+       if (!adapter->name) {
                g_free(adapter);
                return NULL;
        }
@@ -681,7 +681,7 @@ int __near_adapter_set_dep_state(uint32_t idx, bool dep)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        adapter->dep_up = dep;
@@ -711,7 +711,7 @@ bool __near_adapter_get_dep_state(uint32_t idx)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return false;
 
        return adapter->dep_up;
@@ -723,7 +723,7 @@ int __near_adapter_add(struct near_adapter *adapter)
 
        DBG("%s", adapter->path);
 
-       if (g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)) != NULL)
+       if (g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)))
                return -EEXIST;
 
        g_hash_table_insert(adapter_hash, GINT_TO_POINTER(idx), adapter);
@@ -756,7 +756,7 @@ static void tag_read_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
 
        adapter = g_hash_table_lookup(adapter_hash,
                                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        if (status < 0) {
@@ -783,11 +783,11 @@ static void device_read_cb(uint32_t adapter_idx, uint32_t target_idx,
 
        adapter = g_hash_table_lookup(adapter_hash,
                                        GINT_TO_POINTER(adapter_idx));
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        if (status < 0) {
-               if (adapter->device_link != NULL) {
+               if (adapter->device_link) {
                        __near_netlink_dep_link_down(adapter->idx);
                        adapter->device_link = NULL;
                }
@@ -811,7 +811,7 @@ static int adapter_add_tag(struct near_adapter *adapter, uint32_t target_idx,
        tag = __near_tag_add(adapter->idx, target_idx, protocols,
                                sens_res, sel_res,
                                nfcid, nfcid_len);
-       if (tag == NULL)
+       if (!tag)
                return -ENODEV;
 
        g_hash_table_insert(adapter->tags, GINT_TO_POINTER(target_idx), tag);
@@ -843,7 +843,7 @@ static int adapter_add_device(struct near_adapter *adapter,
        int err;
 
        device = __near_device_add(adapter->idx, target_idx, nfcid, nfcid_len);
-       if (device == NULL)
+       if (!device)
                return -ENODEV;
 
        g_hash_table_insert(adapter->devices, GINT_TO_POINTER(target_idx),
@@ -884,7 +884,7 @@ int __near_adapter_add_target(uint32_t idx, uint32_t target_idx,
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        adapter->polling = false;
@@ -913,7 +913,7 @@ int __near_adapter_remove_target(uint32_t idx, uint32_t target_idx)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        adapter->rf_mode = NEAR_ADAPTER_RF_MODE_IDLE;
@@ -944,7 +944,7 @@ int __near_adapter_add_device(uint32_t idx, uint8_t *nfcid, uint8_t nfcid_len)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        adapter->polling = false;
@@ -970,7 +970,7 @@ int __near_adapter_remove_device(uint32_t idx)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        if (!g_hash_table_remove(adapter->devices, GINT_TO_POINTER(device_idx)))
@@ -995,7 +995,7 @@ static void adapter_flush_rx(struct near_adapter *adapter, int error)
        for (list = adapter->ioreq_list; list; list = list->next) {
                struct near_adapter_ioreq *req = list->data;
 
-               if (req == NULL)
+               if (!req)
                        continue;
 
                req->cb(NULL, error, req->data);
@@ -1044,7 +1044,7 @@ static gboolean adapter_recv_event(GIOChannel *channel, GIOCondition condition,
 
        sk = g_io_channel_unix_get_fd(channel);
        first = g_list_first(adapter->ioreq_list);
-       if (first == NULL)
+       if (!first)
                return TRUE;
 
        req = first->data;
@@ -1067,7 +1067,7 @@ int near_adapter_connect(uint32_t idx, uint32_t target_idx, uint8_t protocol)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        if (adapter->tag_sock != -1)
@@ -1075,7 +1075,7 @@ int near_adapter_connect(uint32_t idx, uint32_t target_idx, uint8_t protocol)
 
        tag = g_hash_table_lookup(adapter->tags,
                                GINT_TO_POINTER(target_idx));
-       if (tag == NULL)
+       if (!tag)
                return -ENOLINK;
 
        sock = socket(AF_NFC, SOCK_SEQPACKET, NFC_SOCKPROTO_RAW);
@@ -1096,7 +1096,7 @@ int near_adapter_connect(uint32_t idx, uint32_t target_idx, uint8_t protocol)
        adapter->tag_sock = sock;
        adapter->tag_link = tag;
 
-       if (adapter->channel == NULL)
+       if (!adapter->channel)
                adapter->channel = g_io_channel_unix_new(adapter->tag_sock);
 
        g_io_channel_set_flags(adapter->channel, G_IO_FLAG_NONBLOCK, NULL);
@@ -1119,12 +1119,12 @@ int near_adapter_disconnect(uint32_t idx)
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        DBG("link %p", adapter->tag_link);
 
-       if (adapter->tag_link == NULL)
+       if (!adapter->tag_link)
                return -ENOLINK;
 
        tag_type = __near_tag_get_type(adapter->tag_link);
@@ -1160,19 +1160,19 @@ int near_adapter_send(uint32_t idx, uint8_t *buf, size_t length,
        DBG("idx %d", idx);
 
        adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
-       if (adapter == NULL) {
+       if (!adapter) {
                err = -ENODEV;
                goto out_err;
        }
 
-       if (adapter->tag_sock == -1 || adapter->tag_link == NULL) {
+       if (adapter->tag_sock == -1 || !adapter->tag_link) {
                err = -ENOLINK;
                goto out_err;
        }
 
-       if (cb != NULL && adapter->watch != 0) {
+       if (cb && adapter->watch != 0) {
                req = g_try_malloc0(sizeof(*req));
-               if (req == NULL) {
+               if (!req) {
                        err = -ENOMEM;
                        goto out_err;
                }
@@ -1194,7 +1194,7 @@ int near_adapter_send(uint32_t idx, uint8_t *buf, size_t length,
        return err;
 
 out_err:
-       if (req != NULL) {
+       if (req) {
                GList *last = g_list_last(adapter->ioreq_list);
 
                g_free(req);
@@ -1202,7 +1202,7 @@ out_err:
                                g_list_delete_link(adapter->ioreq_list, last);
        }
 
-       if (data_rel != NULL)
+       if (data_rel)
                return (*data_rel)(err, data);
 
        return err;
@@ -1215,7 +1215,7 @@ static void adapter_listen(gpointer key, gpointer value, gpointer user_data)
 
        DBG("%s", adapter->path);
 
-       if (adapter->path == NULL)
+       if (!adapter->path)
                return;
 
        driver->listen(adapter->idx, device_read_cb);
index cbbf45e..a521cb8 100644 (file)
@@ -62,7 +62,7 @@ static void ndef_agent_free(gpointer data)
 
        DBG("");
 
-       if (agent == NULL || agent->watch == 0)
+       if (!agent || agent->watch == 0)
                return;
 
        g_dbus_remove_watch(connection, agent->watch);
@@ -76,14 +76,14 @@ static void ndef_agent_release(gpointer key, gpointer data, gpointer user_data)
        struct near_ndef_agent *agent = data;
        DBusMessage *message;
 
-       if (agent == NULL)
+       if (!agent)
                return;
 
        DBG("%s %s", agent->sender, agent->path);
 
        message = dbus_message_new_method_call(agent->sender, agent->path,
                                        NFC_NDEF_AGENT_INTERFACE, "Release");
-       if (message == NULL)
+       if (!message)
                return;
 
        dbus_message_set_no_reply(message, TRUE);
@@ -110,7 +110,7 @@ static void append_record_path(DBusMessageIter *iter, void *user_data)
                record = list->data;
 
                path = __near_ndef_record_get_path(record);
-               if (path == NULL)
+               if (!path)
                        continue;
 
                dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &path);
@@ -132,7 +132,7 @@ static void ndef_agent_push_records(struct near_ndef_agent *agent,
 
        DBG("");
 
-       if (agent->sender == NULL || agent->path == NULL)
+       if (!agent->sender || !agent->path)
                return;
 
        DBG("Sending NDEF to %s %s", agent->path, agent->sender);
@@ -140,7 +140,7 @@ static void ndef_agent_push_records(struct near_ndef_agent *agent,
        message = dbus_message_new_method_call(agent->sender, agent->path,
                                        NFC_NDEF_AGENT_INTERFACE,
                                        "GetNDEF");
-       if (message == NULL)
+       if (!message)
                return;
 
        dbus_message_iter_init_append(message, &iter);
@@ -172,17 +172,17 @@ void __near_agent_ndef_parse_records(GList *records)
                record = list->data;
                type  = __near_ndef_record_get_type(record);
 
-               if (type == NULL)
+               if (!type)
                        continue;
 
                DBG("Looking for type %s", type);
 
                agent = g_hash_table_lookup(ndef_app_hash, type);
-               if (agent != NULL)
+               if (agent)
                        break;
        }
 
-       if (agent == NULL)
+       if (!agent)
                return;
 
        ndef_agent_push_records(agent, records);
@@ -195,19 +195,19 @@ int __near_agent_ndef_register(const char *sender, const char *path,
 
        DBG("%s registers path %s for %s", sender, path, record_type);
 
-       if (g_hash_table_lookup(ndef_app_hash, record_type) != NULL)
+       if (g_hash_table_lookup(ndef_app_hash, record_type))
                return -EEXIST;
 
        agent = g_try_malloc0(sizeof(struct near_ndef_agent));
-       if (agent == NULL)
+       if (!agent)
                return -ENOMEM;
 
        agent->sender = g_strdup(sender);
        agent->path = g_strdup(path);
        agent->record_type = g_strdup(record_type);
 
-       if (agent->sender == NULL || agent->path == NULL ||
-           agent->record_type == NULL) {
+       if (!agent->sender || !agent->path ||
+           !agent->record_type) {
                g_free(agent);
                return -ENOMEM;
        }
@@ -228,7 +228,7 @@ int __near_agent_ndef_unregister(const char *sender, const char *path,
        DBG("sender %s path %s type %s", sender, path, record_type);
 
        agent = g_hash_table_lookup(ndef_app_hash, record_type);
-       if (agent == NULL)
+       if (!agent)
                return -EINVAL;
 
        if (strcmp(agent->path, path) != 0 || strcmp(agent->sender, sender) != 0)
@@ -271,7 +271,7 @@ static struct carrier_data *parse_reply(DBusMessage *reply)
        struct carrier_data *c_data;
 
        c_data = g_try_new0(struct carrier_data, 1);
-       if (c_data == NULL)
+       if (!c_data)
                return NULL;
 
        c_data->state = CPS_UNKNOWN;
@@ -387,7 +387,7 @@ static void prepare_data(DBusMessage *message, struct carrier_data *data)
 
        near_dbus_dict_open(&iter, &dict);
 
-       if (data != NULL) {
+       if (data) {
                void *pdata = data->data;
 
                switch (data->type) {
@@ -430,13 +430,13 @@ struct carrier_data *__near_agent_handover_request_data(
 
        agent = g_hash_table_lookup(ho_agent_hash,
                                GINT_TO_POINTER(carrier));
-       if (agent == NULL)
+       if (!agent)
                return NULL;
 
        message = dbus_message_new_method_call(agent->sender,
                        agent->path, NFC_HANDOVER_AGENT_INTERFACE,
                        "RequestOOB");
-       if (message == NULL)
+       if (!message)
                return NULL;
 
        prepare_data(message, data);
@@ -448,7 +448,7 @@ struct carrier_data *__near_agent_handover_request_data(
 
        dbus_message_unref(message);
 
-       if (reply == NULL) {
+       if (!reply) {
                if (dbus_error_is_set(&error)) {
                        near_error("RequestOOB failed: %s", error.message);
                        dbus_error_free(&error);
@@ -476,13 +476,13 @@ int __near_agent_handover_push_data(enum ho_agent_carrier carrier,
        struct near_handover_agent *agent = NULL;
 
        agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(carrier));
-       if (agent == NULL)
+       if (!agent)
                return -ESRCH;
 
        message = dbus_message_new_method_call(agent->sender,
                        agent->path, NFC_HANDOVER_AGENT_INTERFACE,
                        "PushOOB");
-       if (message == NULL)
+       if (!message)
                return -ENOMEM;
 
        prepare_data(message, data);
@@ -494,7 +494,7 @@ int __near_agent_handover_push_data(enum ho_agent_carrier carrier,
 
        dbus_message_unref(message);
 
-       if (reply != NULL) {
+       if (reply) {
                dbus_message_unref(reply);
                return 0;
        }
@@ -513,7 +513,7 @@ static void handover_agent_free(gpointer data)
 {
        struct near_handover_agent *agent = data;
 
-       if (agent == NULL)
+       if (!agent)
                return;
 
        g_free(agent->sender);
@@ -535,7 +535,7 @@ static void handover_agent_disconnect(DBusConnection *conn, void *data)
 
        DBG("data %p", data);
 
-       if (agent == NULL)
+       if (!agent)
                return;
 
        switch (agent->carrier) {
@@ -558,13 +558,13 @@ static void handover_agent_release(gpointer key, gpointer data,
        struct near_handover_agent *agent = data;
        DBusMessage *message;
 
-       if (agent == NULL || agent->watch == 0)
+       if (!agent || agent->watch == 0)
                return;
 
        message = dbus_message_new_method_call(agent->sender, agent->path,
                                        "org.neard.HandoverAgent",
                                        "Release");
-       if (message != NULL)
+       if (message)
                g_dbus_send_message(connection, message);
 }
 
@@ -574,7 +574,7 @@ static int create_handover_agent(const char *sender, const char *path,
        struct near_handover_agent *agent;
 
        agent = g_try_malloc0(sizeof(struct near_handover_agent));
-       if (agent == NULL)
+       if (!agent)
                return -ENOMEM;
 
        agent->sender = g_strdup(sender);
@@ -615,7 +615,7 @@ int __near_agent_handover_register(const char *sender, const char *path,
                return -EINVAL;
 
        agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(ho_carrier));
-       if (agent != NULL)
+       if (agent)
                return -EEXIST;
 
        return create_handover_agent(sender, path, ho_carrier);
@@ -631,7 +631,7 @@ int __near_agent_handover_unregister(const char *sender, const char *path,
 
        ho_carrier = string2carrier(carrier);
        agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(ho_carrier));
-       if (agent == NULL)
+       if (!agent)
                return -ESRCH;
 
        if (strcmp(agent->path, path) != 0 ||
@@ -649,7 +649,7 @@ bool __near_agent_handover_registered(enum ho_agent_carrier carrier)
 
        agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(carrier));
 
-       return agent != NULL ? TRUE : FALSE;
+       return agent ? TRUE : FALSE;
 }
 
 int __near_agent_init(void)
@@ -657,7 +657,7 @@ int __near_agent_init(void)
        DBG("");
 
        connection = near_dbus_get_connection();
-       if (connection == NULL)
+       if (!connection)
                return -1;
 
        ndef_app_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
index 30a2008..7cf4efc 100644 (file)
@@ -103,27 +103,27 @@ static void __bt_eir_free(struct near_oob_data *oob)
 {
        DBG("");
 
-       if (oob->def_adapter != NULL) {
+       if (oob->def_adapter) {
                g_free(oob->def_adapter);
                oob->def_adapter = NULL;
        }
 
-       if (oob->bd_addr != NULL) {
+       if (oob->bd_addr) {
                g_free(oob->bd_addr);
                oob->bd_addr = NULL;
        }
 
-       if (oob->bt_name != NULL) {
+       if (oob->bt_name) {
                g_free(oob->bt_name);
                oob->bt_name = NULL;
        }
 
-       if (oob->spair_hash != NULL) {
+       if (oob->spair_hash) {
                g_free(oob->spair_hash);
                oob->spair_hash = NULL;
        }
 
-       if (oob->spair_randomizer != NULL) {
+       if (oob->spair_randomizer) {
                g_free(oob->spair_randomizer);
                oob->spair_randomizer = NULL;
        }
@@ -155,7 +155,7 @@ static int bt_generic_call(DBusConnection *conn,
 
        msg = dbus_message_new_method_call(dest, path, interface, method);
 
-       if (msg == NULL) {
+       if (!msg) {
                near_error("Unable to allocate new D-Bus %s message", method);
                return -ENOMEM;
        }
@@ -175,7 +175,7 @@ static int bt_generic_call(DBusConnection *conn,
                goto error_done;
        }
 
-       if (pending == NULL) {
+       if (!pending) {
                near_error("D-Bus connection not available");
                err = -EIO;
                goto error_done;
@@ -200,7 +200,7 @@ static void bt_create_paired_device_cb(DBusPendingCall *pending,
        DBG("");
 
        reply = dbus_pending_call_steal_reply(pending);
-       if (reply == NULL)
+       if (!reply)
                return;
 
        dbus_error_init(&error);
@@ -246,7 +246,7 @@ static void bt_oob_add_remote_data_cb(DBusPendingCall *pending, void *user_data)
        DBG("");
 
        reply = dbus_pending_call_steal_reply(pending);
-       if (reply == NULL)
+       if (!reply)
                return;
 
        dbus_error_init(&error);
@@ -345,7 +345,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob)
 
                        /* Now, fill the local struct */
                        oob->bd_addr = g_try_malloc0(BT_ADDRESS_SIZE);
-                       if (oob->bd_addr == NULL)
+                       if (!oob->bd_addr)
                                return -ENOMEM;
 
                        /* Address is like: "ff:ee:dd:cc:bb:aa" */
@@ -356,7 +356,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob)
                } else if (g_str_equal(key, "Name")) {
                        dbus_message_iter_get_basic(&value, &data);
                        oob->bt_name = g_strdup(data);
-                       if (oob->bt_name != NULL) {
+                       if (oob->bt_name) {
                                oob->bt_name_len = strlen(oob->bt_name);
                                DBG("local name: %s", oob->bt_name);
                        }
@@ -380,7 +380,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob)
                } else if (g_str_equal(key, "UUIDs")) {
                        oob->uuids_len = sizeof(value);
                        oob->uuids = g_try_malloc0(oob->uuids_len);
-                       if (oob->uuids == NULL)
+                       if (!oob->uuids)
                                return -ENOMEM;
                        memcpy(oob->uuids, &value, oob->uuids_len);
                }
@@ -447,7 +447,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn,
                g_free(bt_def_oob_data.bt_name);
                bt_def_oob_data.bt_name = g_strdup(name);
 
-               if (bt_def_oob_data.bt_name != NULL)
+               if (bt_def_oob_data.bt_name)
                        bt_def_oob_data.bt_name_len = strlen(name);
                else
                        bt_def_oob_data.bt_name_len = 0;
@@ -489,7 +489,7 @@ static void bt_get_properties_cb(DBusPendingCall *pending, void *user_data)
        DBG("");
 
        reply = dbus_pending_call_steal_reply(pending);
-       if (reply == NULL)
+       if (!reply)
                return;
 
        dbus_error_init(&error);
@@ -532,7 +532,7 @@ static void bt_get_default_adapter_cb(DBusPendingCall *pending, void *user_data)
        DBG("");
 
        reply = dbus_pending_call_steal_reply(pending);
-       if (reply == NULL)
+       if (!reply)
                return;
 
        dbus_error_init(&error);
@@ -627,7 +627,7 @@ static void bt_parse_eir(uint8_t *eir_data, uint16_t eir_data_len,
                case EIR_CLASS_OF_DEVICE:
                        tmp = g_strdup_printf("%02X%02X%02X",
                                        *data, *(data + 1), *(data + 2));
-                       if (tmp != NULL) {
+                       if (tmp) {
                                oob->class_of_device = strtol(tmp, NULL, 16);
                                *props |= OOB_PROPS_COD;
                        }
@@ -730,7 +730,7 @@ int __near_bluetooth_parse_oob_record(struct carrier_data *data,
                /* Class of device */
                tmp = g_strdup_printf("%02X%02X%02X",
                                *ptr, *(ptr + 1), *(ptr + 2));
-               if (tmp != NULL)
+               if (tmp)
                        oob->class_of_device = strtol(tmp, NULL, 16);
                g_free(tmp);
 
@@ -767,7 +767,7 @@ int __near_bluetooth_parse_oob_record(struct carrier_data *data,
 
        /* check and get the default adapter */
        oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
-       if (oob->def_adapter == NULL) {
+       if (!oob->def_adapter) {
                near_error("bt_get_default_adapter failed");
                bt_eir_free(oob);
                return -EIO;
@@ -782,7 +782,7 @@ int __near_bluetooth_pair(void *data)
 
        /* check and get the default adapter */
        oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
-       if (oob->bt_name == NULL) {
+       if (!oob->bt_name) {
                near_error("bt_get_default_adapter failed: %d", -EIO);
                bt_eir_free(oob);
                return -EIO;
@@ -858,13 +858,13 @@ struct carrier_data *__near_bluetooth_local_get_properties(uint16_t mime_props)
        char random[OOB_SP_SIZE];
 
        /* Check adapter datas */
-       if (bt_def_oob_data.def_adapter == NULL) {
+       if (!bt_def_oob_data.def_adapter) {
                near_error("No bt adapter info");
                goto fail;
        }
 
        data = g_try_malloc0(sizeof(*data));
-       if (data == NULL)
+       if (!data)
                goto fail;
 
        data->size = sizeof(uint16_t)   /* stored oob size */
@@ -897,23 +897,19 @@ struct carrier_data *__near_bluetooth_local_get_properties(uint16_t mime_props)
                data->size += 2 * (OOB_SP_SIZE + EIR_HEADER_LEN);
 
                /* OOB datas */
-               if (hash != NULL) {
-                       data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
-                       data->data[offset++] = EIR_SP_HASH;
-                       memcpy(data->data + offset, hash, OOB_SP_SIZE);
-                       offset += OOB_SP_SIZE;
-               }
-
-               if (random != NULL) {
-                       data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
-                       data->data[offset++] = EIR_SP_RANDOMIZER;
-                       memcpy(data->data + offset, random, OOB_SP_SIZE);
-                       offset += OOB_SP_SIZE;
-               }
+               data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
+               data->data[offset++] = EIR_SP_HASH;
+               memcpy(data->data + offset, hash, OOB_SP_SIZE);
+               offset += OOB_SP_SIZE;
+
+               data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
+               data->data[offset++] = EIR_SP_RANDOMIZER;
+               memcpy(data->data + offset, random, OOB_SP_SIZE);
+               offset += OOB_SP_SIZE;
        }
 
        /* bt name */
-       if (bt_def_oob_data.bt_name != NULL) {
+       if (bt_def_oob_data.bt_name) {
                int name_len;
 
                data->size += EIR_HEADER_LEN;
@@ -960,7 +956,7 @@ static gboolean bt_adapter_removed(DBusConnection *conn, DBusMessage *message,
 
        DBG("");
 
-       if (bt_props->def_adapter == NULL)
+       if (!bt_props->def_adapter)
                return TRUE;
 
        g_dbus_remove_watch(bt_conn, adapter_props_watch);
@@ -1130,7 +1126,7 @@ void __near_bluetooth_cleanup(void)
 {
        DBG("");
 
-       if (bt_conn == NULL)
+       if (!bt_conn)
                return;
 
        __near_bluetooth_legacy_stop();
@@ -1153,7 +1149,7 @@ int __near_bluetooth_init(void)
 
        /* save the dbus connection */
        bt_conn = near_dbus_get_connection();
-       if (bt_conn == NULL) {
+       if (!bt_conn) {
                if (dbus_error_is_set(&err)) {
                        near_error("%s", err.message);
                        dbus_error_free(&err);
index ad65544..9c67a9e 100644 (file)
@@ -34,7 +34,7 @@ dbus_bool_t near_dbus_validate_ident(const char *ident)
 {
        unsigned int i;
 
-       if (ident == NULL)
+       if (!ident)
                return FALSE;
 
        for (i = 0; i < strlen(ident); i++) {
@@ -55,13 +55,13 @@ char *near_dbus_encode_string(const char *value)
        GString *str;
        unsigned int i, size;
 
-       if (value == NULL)
+       if (!value)
                return NULL;
 
        size = strlen(value);
 
        str = g_string_new(NULL);
-       if (str == NULL)
+       if (!str)
                return NULL;
 
        for (i = 0; i < size; i++) {
@@ -216,11 +216,11 @@ dbus_bool_t near_dbus_property_changed_basic(const char *path,
        DBusMessage *signal;
        DBusMessageIter iter;
 
-       if (path == NULL)
+       if (!path)
                return FALSE;
 
        signal = dbus_message_new_signal(path, interface, "PropertyChanged");
-       if (signal == NULL)
+       if (!signal)
                return FALSE;
 
        dbus_message_iter_init_append(signal, &iter);
@@ -238,11 +238,11 @@ dbus_bool_t near_dbus_property_changed_dict(const char *path,
        DBusMessage *signal;
        DBusMessageIter iter;
 
-       if (path == NULL)
+       if (!path)
                return FALSE;
 
        signal = dbus_message_new_signal(path, interface, "PropertyChanged");
-       if (signal == NULL)
+       if (!signal)
                return FALSE;
 
        dbus_message_iter_init_append(signal, &iter);
@@ -260,11 +260,11 @@ dbus_bool_t near_dbus_property_changed_array(const char *path,
        DBusMessage *signal;
        DBusMessageIter iter;
 
-       if (path == NULL)
+       if (!path)
                return FALSE;
 
        signal = dbus_message_new_signal(path, interface, "PropertyChanged");
-       if (signal == NULL)
+       if (!signal)
                return FALSE;
 
        dbus_message_iter_init_append(signal, &iter);
index e992fa0..cac1ed3 100644 (file)
@@ -81,7 +81,7 @@ struct near_device *near_device_get_device(uint32_t adapter_idx,
 
        path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
                                        adapter_idx, target_idx);
-       if (path == NULL)
+       if (!path)
                return NULL;
 
        device = g_hash_table_lookup(device_hash, path);
@@ -113,7 +113,7 @@ static void append_records(DBusMessageIter *iter, void *user_data)
                char *path;
 
                path = __near_ndef_record_get_path(record);
-               if (path == NULL)
+               if (!path)
                        continue;
 
                dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
@@ -131,7 +131,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBG("conn %p", conn);
 
        reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
+       if (!reply)
                return NULL;
 
        dbus_message_iter_init_append(reply, &array);
@@ -165,12 +165,12 @@ static void push_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
        conn = near_dbus_get_connection();
        device = near_device_get_device(adapter_idx, target_idx);
 
-       if (conn == NULL || device == NULL)
+       if (!conn || !device)
                return;
 
        if (status != 0) {
                reply = __near_error_failed(device->push_msg, -status);
-               if (reply != NULL)
+               if (reply)
                        g_dbus_send_message(conn, reply);
        } else {
                g_dbus_send_reply(conn, device->push_msg, DBUS_TYPE_INVALID);
@@ -251,13 +251,13 @@ static DBusMessage *push_ndef(DBusConnection *conn,
        device->push_msg = dbus_message_ref(msg);
 
        service_name = sn_from_message(msg);
-       if (service_name == NULL) {
+       if (!service_name) {
                err = -EINVAL;
                goto error;
        }
 
        ndef = __ndef_build_from_message(msg);
-       if (ndef == NULL) {
+       if (!ndef) {
                err = -EINVAL;
                goto error;
        }
@@ -299,10 +299,10 @@ void __near_device_remove(struct near_device *device)
 
        DBG("path %s", device->path);
 
-       if (g_hash_table_lookup(device_hash, device->path) == NULL)
+       if (!g_hash_table_lookup(device_hash, device->path))
                return;
 
-       if (device->push_msg != NULL)
+       if (device->push_msg)
                push_cb(device->adapter_idx, device->target_idx, EIO);
 
        g_dbus_unregister_interface(connection, device->path,
@@ -317,15 +317,15 @@ int near_device_add_data(uint32_t adapter_idx, uint32_t target_idx,
        struct near_device *device;
 
        device = near_device_get_device(adapter_idx, target_idx);
-       if (device == NULL)
+       if (!device)
                return -ENODEV;
 
        device->data_length = data_length;
        device->data = g_try_malloc0(data_length);
-       if (device->data == NULL)
+       if (!device->data)
                return -ENOMEM;
 
-       if (data != NULL)
+       if (data)
                memcpy(device->data, data, data_length);
 
        return 0;
@@ -350,7 +350,7 @@ int near_device_add_records(struct near_device *device, GList *records,
                                        NFC_PATH, device->adapter_idx,
                                        device->target_idx, device->n_records);
 
-               if (path == NULL)
+               if (!path)
                        continue;
 
                __near_ndef_record_register(record, path);
@@ -366,7 +366,7 @@ int near_device_add_records(struct near_device *device, GList *records,
                                        DBUS_TYPE_OBJECT_PATH, append_records,
                                        device);
 
-       if (cb != NULL)
+       if (cb)
                cb(device->adapter_idx, device->target_idx, status);
 
        g_list_free(records);
@@ -381,16 +381,16 @@ struct near_device *__near_device_add(uint32_t adapter_idx, uint32_t target_idx,
        char *path;
 
        device = near_device_get_device(adapter_idx, target_idx);
-       if (device != NULL)
+       if (device)
                return NULL;
 
        device = g_try_malloc0(sizeof(struct near_device));
-       if (device == NULL)
+       if (!device)
                return NULL;
 
        device->path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
                                        adapter_idx, target_idx);
-       if (device->path == NULL) {
+       if (!device->path) {
                g_free(device);
                return NULL;
        }
@@ -404,7 +404,7 @@ struct near_device *__near_device_add(uint32_t adapter_idx, uint32_t target_idx,
        }
 
        path = g_strdup(device->path);
-       if (path == NULL) {
+       if (!path) {
                g_free(device);
                return NULL;
        }
@@ -471,7 +471,7 @@ int near_device_driver_register(struct near_device_driver *driver)
 {
        DBG("");
 
-       if (driver->listen == NULL)
+       if (!driver->listen)
                return -EINVAL;
 
        driver_list = g_slist_insert_sorted(driver_list, driver, cmp_prio);
index 9aa49ea..0b6c136 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -81,14 +81,14 @@ static bool is_enabled(struct near_debug_desc *desc)
 {
        int i;
 
-       if (enabled == NULL)
+       if (!enabled)
                return false;
 
-       for (i = 0; enabled[i] != NULL; i++) {
-               if (desc->name != NULL && g_pattern_match_simple(enabled[i],
+       for (i = 0; enabled[i]; i++) {
+               if (desc->name && g_pattern_match_simple(enabled[i],
                                                        desc->name))
                        return true;
-               if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+               if (desc->file && g_pattern_match_simple(enabled[i],
                                                        desc->file))
                        return true;
        }
@@ -102,13 +102,13 @@ int __near_log_init(const char *debug, bool detach)
        struct near_debug_desc *desc;
        const char *name = NULL, *file = NULL;
 
-       if (debug != NULL)
+       if (debug)
                enabled = g_strsplit_set(debug, ":, ", 0);
 
        for (desc = __start___debug; desc < __stop___debug; desc++) {
-               if (file != NULL || name != NULL) {
+               if (file || name) {
                        if (g_strcmp0(desc->file, file) == 0) {
-                               if (desc->name == NULL)
+                               if (!desc->name)
                                        desc->name = name;
                        } else
                                file = NULL;
index 3689beb..46dba44 100644 (file)
@@ -70,19 +70,19 @@ static void parse_config(GKeyFile *config)
        GError *error = NULL;
        bool boolean;
 
-       if (config == NULL)
+       if (!config)
                return;
 
        DBG("parsing main.conf");
 
        boolean = g_key_file_get_boolean(config, "General",
                                                "ConstantPoll", &error);
-       if (error == NULL)
+       if (!error)
                near_settings.constant_poll = boolean;
 
        boolean = g_key_file_get_boolean(config, "General",
                                                "DefaultPowered", &error);
-       if (error == NULL)
+       if (!error)
                near_settings.default_powered = boolean;
 
        g_clear_error(&error);
@@ -224,7 +224,7 @@ int main(int argc, char *argv[])
        g_option_context_add_main_entries(context, options, NULL);
 
        if (!g_option_context_parse(context, &argc, &argv, &error)) {
-               if (error != NULL) {
+               if (error) {
                        g_printerr("%s\n", error->message);
                        g_error_free(error);
                } else
@@ -246,7 +246,7 @@ int main(int argc, char *argv[])
        dbus_error_init(&err);
 
        conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NFC_SERVICE, &err);
-       if (conn == NULL) {
+       if (!conn) {
                if (dbus_error_is_set(&err)) {
                        fprintf(stderr, "%s\n", err.message);
                        dbus_error_free(&err);
index 0f6c4ae..94593a2 100644 (file)
@@ -44,7 +44,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBG("conn %p", conn);
 
        reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
+       if (!reply)
                return NULL;
 
        dbus_message_iter_init_append(reply, &array);
@@ -69,11 +69,11 @@ int __near_manager_adapter_add(uint32_t idx, const char *name,
        DBG("idx %d", idx);
 
        adapter = __near_adapter_create(idx, name, protocols, powered);
-       if (adapter == NULL)
+       if (!adapter)
                return -ENOMEM;
 
        path = __near_adapter_get_path(adapter);
-       if (path == NULL) {
+       if (!path) {
                __near_adapter_destroy(adapter);
                return -EINVAL;
        }
@@ -104,11 +104,11 @@ void __near_manager_adapter_remove(uint32_t idx)
        DBG("idx %d", idx);
 
        adapter = __near_adapter_get(idx);
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        path = __near_adapter_get_path(adapter);
-       if (path == NULL)
+       if (!path)
                return;
 
 
index 370d196..af2b883 100644 (file)
@@ -260,7 +260,7 @@ void __near_ndef_append_records(DBusMessageIter *iter, GList *records)
                size_t data_len;
 
                data = __near_ndef_record_get_data(record, &data_len);
-               if (data == NULL)
+               if (!data)
                        continue;
 
                dbus_message_iter_append_fixed_array(iter, DBUS_TYPE_BYTE,
@@ -273,20 +273,20 @@ static void append_text_payload(struct near_ndef_text_payload *text,
 {
        DBG("");
 
-       if (text == NULL || dict == NULL)
+       if (!text || !dict)
                return;
 
-       if (text->encoding != NULL)
+       if (text->encoding)
                near_dbus_dict_append_basic(dict, "Encoding",
                                                DBUS_TYPE_STRING,
                                                &(text->encoding));
 
-       if (text->language_code != NULL)
+       if (text->language_code)
                near_dbus_dict_append_basic(dict, "Language",
                                                DBUS_TYPE_STRING,
                                                &(text->language_code));
 
-       if (text->data != NULL)
+       if (text->data)
                near_dbus_dict_append_basic(dict, "Representation",
                                                DBUS_TYPE_STRING,
                                                &(text->data));
@@ -297,10 +297,10 @@ static void append_aar_payload(struct near_ndef_aar_payload *aar,
 {
        DBG("");
 
-       if (aar == NULL || dict == NULL)
+       if (!aar || !dict)
                return;
 
-       if (aar->package != NULL)
+       if (aar->package)
                near_dbus_dict_append_basic(dict, "AndroidPackage",
                                                DBUS_TYPE_STRING,
                                                &(aar->package));
@@ -361,7 +361,7 @@ static void append_uri_payload(struct near_ndef_uri_payload *uri,
 
        DBG("");
 
-       if (uri == NULL || dict == NULL)
+       if (!uri || !dict)
                return;
 
        if (uri->identifier > NFC_MAX_URI_ID) {
@@ -388,23 +388,23 @@ static void append_sp_payload(struct near_ndef_sp_payload *sp,
 
        DBG("");
 
-       if (sp == NULL || dict == NULL)
+       if (!sp || !dict)
                return;
 
-       if (sp->action != NULL)
+       if (sp->action)
                near_dbus_dict_append_basic(dict, "Action", DBUS_TYPE_STRING,
                                                        &(sp->action));
 
-       if (sp->uri != NULL)
+       if (sp->uri)
                append_uri_payload(sp->uri, dict);
 
-       if (sp->title_records != NULL &&
+       if (sp->title_records &&
                        sp->number_of_title_records > 0) {
                for (i = 0; i < sp->number_of_title_records; i++)
                        append_text_payload(sp->title_records[i], dict);
        }
 
-       if (sp->type != NULL)
+       if (sp->type)
                near_dbus_dict_append_basic(dict, "MIMEType", DBUS_TYPE_STRING,
                                                                &(sp->type));
 
@@ -418,10 +418,10 @@ static void append_mime_payload(struct near_ndef_mime_payload *mime,
 {
        DBG("");
 
-       if (mime == NULL || dict == NULL)
+       if (!mime || !dict)
                return;
 
-       if (mime->type != NULL)
+       if (mime->type)
                near_dbus_dict_append_basic(dict, "MIME",
                                                DBUS_TYPE_STRING,
                                                &(mime->type));
@@ -434,7 +434,7 @@ static void append_record(struct near_ndef_record *record,
 
        DBG("");
 
-       if (record == NULL || dict == NULL)
+       if (!record || !dict)
                return;
 
        switch (record->header->rec_type) {
@@ -512,12 +512,12 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
        DBG("conn %p", conn);
 
-       if (conn == NULL || msg == NULL ||
-               data == NULL)
+       if (!conn || !msg ||
+               !data)
                return NULL;
 
        reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
+       if (!reply)
                return NULL;
 
        dbus_message_iter_init_append(reply, &array);
@@ -540,7 +540,7 @@ static const GDBusMethodTable record_methods[] = {
 
 static void free_text_payload(struct near_ndef_text_payload *text)
 {
-       if (text == NULL)
+       if (!text)
                return;
 
        g_free(text->encoding);
@@ -551,7 +551,7 @@ static void free_text_payload(struct near_ndef_text_payload *text)
 
 static void free_uri_payload(struct near_ndef_uri_payload *uri)
 {
-       if (uri == NULL)
+       if (!uri)
                return;
 
        g_free(uri->field);
@@ -562,12 +562,12 @@ static void free_sp_payload(struct near_ndef_sp_payload *sp)
 {
        uint8_t i;
 
-       if (sp == NULL)
+       if (!sp)
                return;
 
        free_uri_payload(sp->uri);
 
-       if (sp->title_records != NULL) {
+       if (sp->title_records) {
                for (i = 0; i < sp->number_of_title_records; i++)
                        free_text_payload(sp->title_records[i]);
        }
@@ -580,7 +580,7 @@ static void free_sp_payload(struct near_ndef_sp_payload *sp)
 
 static void free_mime_payload(struct near_ndef_mime_payload *mime)
 {
-       if (mime == NULL)
+       if (!mime)
                return;
 
        g_free(mime->type);
@@ -589,7 +589,7 @@ static void free_mime_payload(struct near_ndef_mime_payload *mime)
 
 static void free_ac_payload(struct near_ndef_ac_payload *ac)
 {
-       if (ac == NULL)
+       if (!ac)
                return;
 
        g_free(ac->cdr);
@@ -601,10 +601,10 @@ static void free_ho_payload(struct near_ndef_ho_payload *ho)
 {
        int i;
 
-       if (ho == NULL)
+       if (!ho)
                return;
 
-       if (ho->ac_payloads != NULL) {
+       if (ho->ac_payloads) {
                for (i = 0; i < ho->number_of_ac_payloads; i++)
                        free_ac_payload(ho->ac_payloads[i]);
        }
@@ -615,7 +615,7 @@ static void free_ho_payload(struct near_ndef_ho_payload *ho)
 
 static void free_aar_payload(struct near_ndef_aar_payload *aar)
 {
-       if (aar == NULL)
+       if (!aar)
                return;
 
        g_free(aar->package);
@@ -624,12 +624,12 @@ static void free_aar_payload(struct near_ndef_aar_payload *aar)
 
 static void free_ndef_record(struct near_ndef_record *record)
 {
-       if (record == NULL)
+       if (!record)
                return;
 
        g_free(record->path);
 
-       if (record->header != NULL) {
+       if (record->header) {
 
                switch (record->header->rec_type) {
                case RECORD_TYPE_WKT_SIZE:
@@ -681,7 +681,7 @@ static void free_ndef_record(struct near_ndef_record *record)
 
 static void free_ndef_message(struct near_ndef_message *msg)
 {
-       if (msg == NULL)
+       if (!msg)
                return;
 
        g_free(msg->data);
@@ -794,7 +794,7 @@ static int build_record_type_string(struct near_ndef_record *rec)
 
        DBG("");
 
-       if (rec == NULL || rec->header == NULL)
+       if (!rec || !rec->header)
                return -EINVAL;
 
        tnf = rec->header->tnf;
@@ -836,7 +836,7 @@ static uint8_t validate_record_begin_and_end_bits(uint8_t *msg_mb,
 {
        DBG("");
 
-       if (msg_mb == NULL || msg_me == NULL)
+       if (!msg_mb || !msg_me)
                return 0;
 
        /* Validating record header begin and end bits
@@ -884,7 +884,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
 
        DBG("length %d", length);
 
-       if (rec == NULL || offset >= length)
+       if (!rec || offset >= length)
                return NULL;
 
        /* This check is for empty record. */
@@ -892,7 +892,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
                return NULL;
 
        rec_header = g_try_malloc0(sizeof(struct near_ndef_record_header));
-       if (rec_header == NULL)
+       if (!rec_header)
                return NULL;
 
        rec_header->mb = RECORD_MB_BIT(rec[offset]);
@@ -936,7 +936,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
                        goto fail;
 
                type = g_try_malloc0(rec_header->type_len);
-               if (type == NULL)
+               if (!type)
                        goto fail;
 
                memcpy(type, rec + offset, rec_header->type_len);
@@ -952,7 +952,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
                        goto fail;
 
                rec_header->il_field = g_try_malloc0(rec_header->il_length);
-               if (rec_header->il_field == NULL)
+               if (!rec_header->il_field)
                        goto fail;
 
                memcpy(rec_header->il_field, rec + offset,
@@ -994,12 +994,12 @@ parse_text_payload(uint8_t *payload, uint32_t length)
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
 
        offset = 0;
        text_payload = g_try_malloc0(sizeof(struct near_ndef_text_payload));
-       if (text_payload == NULL)
+       if (!text_payload)
                return NULL;
 
        /* 0x80 is used to get 7th bit value (0th bit is LSB) */
@@ -1056,12 +1056,12 @@ parse_uri_payload(uint8_t *payload, uint32_t length)
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
 
        offset = 0;
        uri_payload = g_try_malloc0(sizeof(struct near_ndef_uri_payload));
-       if (uri_payload == NULL)
+       if (!uri_payload)
                return NULL;
 
        uri_payload->identifier = payload[offset];
@@ -1071,7 +1071,7 @@ parse_uri_payload(uint8_t *payload, uint32_t length)
 
        if (uri_payload->field_length > 0) {
                uri_payload->field = g_try_malloc0(uri_payload->field_length);
-               if (uri_payload->field == NULL)
+               if (!uri_payload->field)
                        goto fail;
 
                memcpy(uri_payload->field, payload + offset,
@@ -1111,7 +1111,7 @@ static int8_t validate_language_code_in_sp_record(GSList *titles)
 
        DBG("");
 
-       if (titles == NULL)
+       if (!titles)
                return -EINVAL;
 
        length = g_slist_length(titles);
@@ -1122,8 +1122,8 @@ static int8_t validate_language_code_in_sp_record(GSList *titles)
                for (j = i + 1; j < length; j++) {
                        title2 = g_slist_nth_data(titles, j);
 
-                       if ((title1->language_code == NULL) &&
-                                       (title2->language_code == NULL))
+                       if ((!title1->language_code) &&
+                                       (!title2->language_code))
                                continue;
 
                        if (g_strcmp0(title1->language_code,
@@ -1146,12 +1146,12 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
 
        offset = 0;
        sp_payload = g_try_malloc0(sizeof(struct near_ndef_sp_payload));
-       if (sp_payload == NULL)
+       if (!sp_payload)
                return NULL;
 
        while (offset < length) {
@@ -1159,7 +1159,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
                DBG("Record header : 0x%x", payload[offset]);
 
                rec_header = parse_record_header(payload, offset, length);
-               if (rec_header == NULL)
+               if (!rec_header)
                        goto fail;
 
                if (validate_record_begin_and_end_bits(&mb, &me,
@@ -1186,12 +1186,12 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
 
                case RECORD_TYPE_WKT_URI:
                        /* URI record should be only one. */
-                       if (sp_payload->uri != NULL)
+                       if (sp_payload->uri)
                                goto fail;
 
                        sp_payload->uri = parse_uri_payload(payload + offset,
                                                rec_header->payload_len);
-                       if (sp_payload->uri == NULL)
+                       if (!sp_payload->uri)
                                goto fail;
 
                        break;
@@ -1206,7 +1206,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
                        struct near_ndef_text_payload *title;
                        title = parse_text_payload(payload + offset,
                                                rec_header->payload_len);
-                       if (title == NULL)
+                       if (!title)
                                goto fail;
 
                        titles = g_slist_append(titles, title);
@@ -1229,7 +1229,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
                        if (rec_header->payload_len > 0) {
                                sp_payload->type = g_try_malloc0(
                                                rec_header->payload_len);
-                               if (sp_payload->type == NULL)
+                               if (!sp_payload->type)
                                        goto fail;
 
                                sp_payload->type = g_strndup(
@@ -1264,7 +1264,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
         * Code to fill smart poster record structure from
         * 'titles' list.
         */
-       if (titles == NULL)
+       if (!titles)
                return sp_payload;
 
        if (validate_language_code_in_sp_record(titles) != 0) {
@@ -1277,7 +1277,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
        sp_payload->title_records = g_try_malloc0(
                                sp_payload->number_of_title_records *
                                 sizeof(struct near_ndef_text_payload *));
-       if (sp_payload->title_records == NULL)
+       if (!sp_payload->title_records)
                goto fail;
 
        for (i = 0; i < sp_payload->number_of_title_records; i++) {
@@ -1293,7 +1293,7 @@ parse_sp_payload(uint8_t *payload, uint32_t length)
 fail:
        near_error("smart poster payload parsing failed");
 
-       if (rec_header != NULL) {
+       if (rec_header) {
                g_free(rec_header->type_name);
                g_free(rec_header->il_field);
                g_free(rec_header);
@@ -1335,7 +1335,7 @@ static int process_mime_type(struct near_ndef_mime_payload *mime,
 
        DBG("");
 
-       if (mime == NULL || c_data == NULL)
+       if (!mime || !c_data)
                return -EINVAL;
 
        switch (mime->handover.carrier_type) {
@@ -1368,16 +1368,16 @@ static struct near_ndef_mime_payload *parse_mime_type(
 
        DBG("");
 
-       if (c_data == NULL || ndef_data == NULL ||
+       if (!c_data || !ndef_data ||
                        ((offset + payload_length) > ndef_length))
                return NULL;
 
        mime = g_try_malloc0(sizeof(struct near_ndef_mime_payload));
-       if (mime == NULL)
+       if (!mime)
                return NULL;
 
        c_temp = g_try_malloc0(sizeof(struct carrier_data));
-       if (c_temp == NULL) {
+       if (!c_temp) {
                g_free(mime);
                return NULL;
        }
@@ -1460,7 +1460,7 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name,
        uint8_t hdr = 0, type_len, sr_bit, il_bit, id_len;
 
        msg = g_try_malloc0(sizeof(struct near_ndef_message));
-       if (msg == NULL)
+       if (!msg)
                return NULL;
 
        msg->length = 0;
@@ -1468,12 +1468,12 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name,
        msg->length++; /* record header*/
        msg->length++; /* type name length byte*/
 
-       type_len = (type_name != NULL) ? strlen(type_name) : 0;
-       id_len = (payload_id != NULL) ? payload_id_len : 0;
+       type_len = (type_name) ? strlen(type_name) : 0;
+       id_len = (payload_id) ? payload_id_len : 0;
        sr_bit =  (payload_len <= NDEF_MSG_SHORT_RECORD_MAX_LENGTH)
                                        ? TRUE : FALSE;
 
-       il_bit = (payload_id != NULL) ? TRUE : FALSE;
+       il_bit = (payload_id) ? TRUE : FALSE;
 
        msg->length += (sr_bit) ? 1 : 4;
        msg->length += (il_bit) ? 1 : 0;
@@ -1482,7 +1482,7 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name,
        msg->length += id_len;
 
        msg->data = g_try_malloc0(msg->length);
-       if (msg->data == NULL)
+       if (!msg->data)
                goto fail;
 
        /* Set MB ME bits */
@@ -1537,7 +1537,7 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name,
        if (il_bit)
                msg->data[msg->offset++] = payload_id_len;
 
-       if (type_name != NULL) {
+       if (type_name) {
                memcpy(msg->data + msg->offset, type_name, type_len);
                msg->offset += type_len;
        }
@@ -1585,12 +1585,12 @@ static struct near_ndef_ac_payload *parse_ac_payload(uint8_t *payload,
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
 
        offset = 0;
        ac_payload = g_try_malloc0(sizeof(struct near_ndef_ac_payload));
-       if (ac_payload == NULL)
+       if (!ac_payload)
                goto fail;
 
        /* Carrier flag */
@@ -1606,7 +1606,7 @@ static struct near_ndef_ac_payload *parse_ac_payload(uint8_t *payload,
 
        /* Carrier data reference */
        ac_payload->cdr = g_try_malloc0(ac_payload->cdr_len + 1);
-       if (ac_payload->cdr == NULL)
+       if (!ac_payload->cdr)
                goto fail;
 
        memcpy(ac_payload->cdr, payload + offset, ac_payload->cdr_len);
@@ -1622,7 +1622,7 @@ static struct near_ndef_ac_payload *parse_ac_payload(uint8_t *payload,
        /* save the auxiliary data reference */
        ac_payload->adata = g_try_malloc0(
                        ac_payload->adata_refcount * sizeof(uint16_t));
-       if (ac_payload->adata == NULL)
+       if (!ac_payload->adata)
                goto fail;
 
        memcpy(ac_payload->adata, payload + offset,
@@ -1651,7 +1651,7 @@ static struct near_ndef_message *near_ndef_prepare_ac_message(uint8_t cps,
                                                NULL, 0,
                                                RECORD_TNF_WELLKNOWN,
                                                true, true);
-       if (ac_msg == NULL)
+       if (!ac_msg)
                return NULL;
 
        /* Prepare ac message */
@@ -1679,7 +1679,7 @@ static struct near_ndef_message *near_ndef_prepare_cr_message(uint16_t cr_id)
                                                NULL, 0,
                                                RECORD_TNF_WELLKNOWN,
                                                true, true);
-       if (cr_msg == NULL)
+       if (!cr_msg)
                return NULL;
 
        /* Prepare ac message */
@@ -1696,12 +1696,12 @@ static struct near_ndef_message *near_ndef_prepare_cfg_message(char *mime_type,
 
        DBG(" %s", mime_type);
 
-       if (mime_type == NULL)
+       if (!mime_type)
                return NULL;
 
        msg = ndef_message_alloc_complete(mime_type, data_len, cdr, cdr_len,
                                                RECORD_TNF_MIME, true, true);
-       if (msg == NULL)
+       if (!msg)
                return NULL;
 
        /* store data */
@@ -1729,7 +1729,7 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
 
        DBG("");
 
-       if (ac == NULL || cfg == NULL)
+       if (!ac || !cfg)
                return -EINVAL;
 
        switch (carrier) {
@@ -1739,10 +1739,10 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
                mime_type = BT_MIME_STRING_2_1;
                local_carrier = __near_agent_handover_request_data(
                                        HO_AGENT_BT, remote_carrier);
-               if (local_carrier != NULL)
+               if (local_carrier)
                        break;
 
-               prop = (mime != NULL) ? mime->handover.properties :
+               prop = (mime) ? mime->handover.properties :
                                                        OOB_PROPS_EMPTY;
                local_carrier = __near_bluetooth_local_get_properties(prop);
 
@@ -1777,18 +1777,18 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
         * Handover Select.
         * In those 2 cases we return an error.
         */
-       if (carrier == NEAR_CARRIER_WIFI && remote_carrier == NULL) {
-               if (local_carrier != NULL &&
+       if (carrier == NEAR_CARRIER_WIFI && !remote_carrier) {
+               if (local_carrier &&
                                type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
                        g_free(local_carrier);
                        return -EINVAL;
                }
 
-               if (local_carrier == NULL &&
+               if (!local_carrier &&
                                type == RECORD_TYPE_WKT_HANDOVER_SELECT)
                        return -EINVAL;
 
-               if (local_carrier == NULL &&
+               if (!local_carrier &&
                                type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
                        *cfg = near_ndef_prepare_cfg_message(mime_type,
                                                        NULL, 0,
@@ -1800,7 +1800,7 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
                }
        }
 
-       if (local_carrier == NULL) {
+       if (!local_carrier) {
                DBG("Unable to retrieve local carrier %s data", carrier_string);
                return -ESRCH;
        }
@@ -1813,7 +1813,7 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
 
        g_free(local_carrier);
 
-       if (*cfg == NULL || *ac == NULL) {
+       if (!*cfg || !*ac) {
                free_ndef_message(*ac);
                free_ndef_message(*cfg);
 
@@ -1836,7 +1836,7 @@ static struct near_ndef_message *prepare_handover_message_header(char *type,
        struct near_ndef_message *ho_msg;
 
        ho_msg = ndef_message_alloc(type, msg_len);
-       if (ho_msg == NULL)
+       if (!ho_msg)
                return NULL;
 
        /*
@@ -1858,7 +1858,7 @@ static uint32_t ndef_message_list_length(GList *list)
        struct near_ndef_message *msg;
        uint32_t length = 0;
 
-       if (list == NULL)
+       if (!list)
                return 0;
 
        while (list) {
@@ -1875,7 +1875,7 @@ static void copy_ac_records(struct near_ndef_message *ho, GList *acs)
        GList *temp = acs;
        struct near_ndef_message *ac;
 
-       if (ho == NULL || temp == NULL)
+       if (!ho || !temp)
                return;
 
        while (temp) {
@@ -1896,7 +1896,7 @@ static void copy_cfg_records(struct near_ndef_message *ho, GList *cfgs)
        struct near_ndef_message *cfg;
        uint32_t offset;
 
-       if (ho == NULL || temp == NULL)
+       if (!ho || !temp)
                return;
 
        offset = ho->offset;
@@ -1931,14 +1931,14 @@ static struct near_ndef_message *near_ndef_prepare_empty_hs_message(void)
        DBG("");
 
        ac_msg = near_ndef_prepare_ac_message(CPS_UNKNOWN, &cdr, sizeof(cdr));
-       if (ac_msg == NULL)
+       if (!ac_msg)
                return NULL;
 
        hs_length = 1;
        hs_length += ac_msg->length;
 
        hs_msg = prepare_handover_message_header("Hs", hs_length, hs_length);
-       if (hs_msg == NULL)
+       if (!hs_msg)
                goto fail;
 
        near_ndef_set_mb_me(hs_msg->data, true, true);
@@ -1980,7 +1980,7 @@ static struct near_ndef_message *near_ndef_prepare_hs_reply(
         * alternative carries or unknown mime types or unknown
         * configuration data.
         */
-       if ((remote_mimes == NULL || remote_cfgs == NULL))
+       if ((!remote_mimes || !remote_cfgs))
                return near_ndef_prepare_empty_hs_message();
 
        mime_iter = remote_mimes;
@@ -1989,7 +1989,7 @@ static struct near_ndef_message *near_ndef_prepare_hs_reply(
        while (mime_iter) {
                remote_mime = mime_iter->data;
                remote_cfg  = cfg_iter->data;
-               if (remote_mime == NULL || remote_cfg == NULL)
+               if (!remote_mime || !remote_cfg)
                        goto fail;
 
                ret = near_ndef_prepare_ac_and_cfg_records(
@@ -2021,7 +2021,7 @@ static struct near_ndef_message *near_ndef_prepare_hs_reply(
        hs_length += ndef_message_list_length(cfg_msgs);
 
        hs_msg = prepare_handover_message_header("Hs", hs_length, hs_pl_length);
-       if (hs_msg == NULL)
+       if (!hs_msg)
                goto fail;
 
        num_of_carriers = g_list_length(ac_msgs);
@@ -2141,7 +2141,7 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers)
        if (type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
                collision = GUINT16_TO_BE(g_random_int_range(0, G_MAXUINT16 + 1));
                cr_msg = near_ndef_prepare_cr_message(collision);
-               if (cr_msg == NULL)
+               if (!cr_msg)
                        goto fail;
 
                near_ndef_set_mb_me(cr_msg->data, true, false);
@@ -2158,7 +2158,7 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers)
 
        ho_msg = prepare_handover_message_header(str_type,
                                                ho_length, ho_pl_length);
-       if (ho_msg == NULL)
+       if (!ho_msg)
                goto fail;
 
        g_list_foreach(ac_msgs, set_mb_me_to_false, NULL);
@@ -2233,7 +2233,7 @@ static int near_fill_ho_payload(struct near_ndef_ho_payload *ho,
        rec_count = g_slist_length(acs);
        ho->ac_payloads = g_try_malloc0(rec_count *
                        sizeof(struct near_ndef_ac_payload *));
-       if (ho->ac_payloads == NULL)
+       if (!ho->ac_payloads)
                goto fail;
        temp = acs;
        for (i = 0; i < rec_count; i++) {
@@ -2247,7 +2247,7 @@ static int near_fill_ho_payload(struct near_ndef_ho_payload *ho,
        rec_count = g_slist_length(mimes);
        ho->cfg_payloads = g_try_malloc0(rec_count *
                        sizeof(struct near_ndef_mime_payload *));
-       if (ho->cfg_payloads == NULL)
+       if (!ho->cfg_payloads)
                goto fail;
        temp = mimes;
        for (i = 0; i < rec_count; i++) {
@@ -2294,13 +2294,13 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
        offset = 0;
 
        /* Create the handover record payload */
        ho_payload = g_try_malloc0(sizeof(struct near_ndef_ho_payload));
-       if (ho_payload == NULL)
+       if (!ho_payload)
                return NULL;
 
        /* Version is the first mandatory field of hr payload */
@@ -2311,7 +2311,7 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
            HANDOVER_MAJOR(HANDOVER_VERSION)) {
                near_error("Unsupported version (%d)", ho_payload->version);
                /* Skip parsing and return an empty record */
-               if (reply != NULL)
+               if (reply)
                        *reply = near_ndef_prepare_empty_hs_message();
 
                return ho_payload;
@@ -2325,12 +2325,12 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
        while (offset < ho_length) {
                /* Create local record for mime parsing */
                trec = g_try_malloc0(sizeof(struct near_ndef_record));
-               if (trec == NULL)
+               if (!trec)
                        return NULL;
 
                trec->header = parse_record_header(payload, offset, ho_length);
 
-               if (trec->header == NULL)
+               if (!trec->header)
                        goto fail;
 
                offset = trec->header->offset;
@@ -2387,7 +2387,7 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
                                        &c_data);
                        trec->ho = NULL;
 
-                       if (mime == NULL || c_data == NULL)
+                       if (!mime || !c_data)
                                goto fail;
 
                        /* add the mime to the list */
@@ -2427,7 +2427,7 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
 
                        ac = parse_ac_payload(payload + offset,
                                        trec->header->payload_len);
-                       if (ac == NULL)
+                       if (!ac)
                                goto fail;
 
                        acs = g_slist_append(acs, ac);
@@ -2467,7 +2467,7 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
                        DBG("could not process alternative carriers");
                        goto fail;
                }
-       } else if (reply != NULL) {
+       } else if (reply) {
                /* This is a Hs with no cfg and no Ac: No reply and fail */
                if (rec_type == RECORD_TYPE_WKT_HANDOVER_SELECT &&
                                        g_slist_length(acs) == 0) {
@@ -2477,13 +2477,13 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
 
                /* Prepare Hs, it depends upon Hr message carrier types */
                *reply = near_ndef_prepare_hs_reply(mimes, c_datas);
-               if (*reply == NULL) {
+               if (!*reply) {
                        DBG("error in preparing in HS record");
                        goto fail;
                }
        }
 
-       if ((acs == NULL) || (mimes == NULL))
+       if ((!acs) || (!mimes))
                return ho_payload;
 
        /* Save the records */
@@ -2499,8 +2499,8 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type,
 fail:
        near_error("handover payload parsing failed");
 
-       if (trec != NULL) {
-               if (trec->header != NULL) {
+       if (trec) {
+               if (trec->header) {
                        g_free(trec->header->type_name);
                        g_free(trec->header->il_field);
                        g_free(trec->header);
@@ -2521,15 +2521,15 @@ parse_aar_payload(uint8_t *payload, uint32_t length)
 
        DBG("");
 
-       if (payload == NULL)
+       if (!payload)
                return NULL;
 
        aar_payload = g_try_malloc0(sizeof(struct near_ndef_uri_payload));
-       if (aar_payload == NULL)
+       if (!aar_payload)
                return NULL;
 
        aar_payload->package = g_strndup((char *)payload, length);
-       if (aar_payload->package == NULL) {
+       if (!aar_payload->package) {
                near_error("AAR payload parsing failed");
                free_aar_payload(aar_payload);
                return NULL;
@@ -2562,15 +2562,15 @@ bool near_ndef_record_cmp_id(struct near_ndef_record *rec1,
 {
        DBG("");
 
-       if ((rec1 == NULL) || (rec2 == NULL))
+       if ((!rec1) || (!rec2))
                return false;
 
-       if ((rec1->header == NULL) || (rec2->header == NULL))
+       if ((!rec1->header) || (!rec2->header))
                return false;
 
        /* usual checks */
-       if ((rec1->header->il_field == NULL) ||
-                       (rec2->header->il_field == NULL))
+       if ((!rec1->header->il_field) ||
+                       (!rec2->header->il_field))
                return false;
 
        if (memcmp(rec1->header->il_field, rec2->header->il_field,
@@ -2588,16 +2588,16 @@ bool near_ndef_record_cmp_mime(struct near_ndef_record *rec1,
 
        DBG("");
 
-       if ((rec1 == NULL) || (rec2 == NULL))
+       if ((!rec1) || (!rec2))
                return false;
 
-       if ((rec1->header == NULL) || (rec2->header == NULL))
+       if ((!rec1->header) || (!rec2->header))
                return false;
        /* usual checks */
-       if ((rec1->mime == NULL) || (rec2->mime == NULL))
+       if ((!rec1->mime) || (!rec2->mime))
                return false;
 
-       if ((rec1->mime->type == NULL) || (rec2->mime->type == NULL))
+       if ((!rec1->mime->type) || (!rec2->mime->type))
                return false;
 
        if (strlen(rec1->mime->type) != strlen(rec2->mime->type))
@@ -2612,7 +2612,7 @@ bool near_ndef_record_cmp_mime(struct near_ndef_record *rec1,
 /* helper to get the record data length */
 size_t near_ndef_data_length(struct near_ndef_record *rec)
 {
-       if (rec == NULL)
+       if (!rec)
                return 0;
        else
                return rec->data_len;
@@ -2621,7 +2621,7 @@ size_t near_ndef_data_length(struct near_ndef_record *rec)
 /* helper to get the record data pointer */
 uint8_t *near_ndef_data_ptr(struct near_ndef_record *rec)
 {
-       if (rec == NULL)
+       if (!rec)
                return NULL;
        else
                return rec->data;
@@ -2640,7 +2640,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
 
        records = NULL;
 
-       if (ndef_data == NULL ||
+       if (!ndef_data ||
                ndef_length < NDEF_MSG_MIN_LENGTH)
                        goto fail;
 
@@ -2649,12 +2649,12 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                DBG("Record Header : 0x%X", ndef_data[offset]);
 
                record = g_try_malloc0(sizeof(struct near_ndef_record));
-               if (record == NULL)
+               if (!record)
                        goto fail;
 
                record->header = parse_record_header(ndef_data, offset,
                                                        ndef_length);
-               if (record->header == NULL)
+               if (!record->header)
                        goto fail;
 
                if (validate_record_begin_and_end_bits(&p_mb, &p_me,
@@ -2693,7 +2693,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                                        ndef_length - offset,
                                        record->header->mb, record->header->me,
                                        reply);
-                       if (record->ho == NULL)
+                       if (!record->ho)
                                goto fail;
 
                        /* the complete frame is processed, break the loop */
@@ -2704,7 +2704,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                        record->text = parse_text_payload(ndef_data + offset,
                                                record->header->payload_len);
 
-                       if (record->text == NULL)
+                       if (!record->text)
                                goto fail;
 
                        break;
@@ -2713,7 +2713,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                        record->uri = parse_uri_payload(ndef_data + offset,
                                                record->header->payload_len);
 
-                       if (record->uri == NULL)
+                       if (!record->uri)
                                goto fail;
 
                        break;
@@ -2723,7 +2723,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                                                ndef_data + offset,
                                                record->header->payload_len);
 
-                       if (record->sp == NULL)
+                       if (!record->sp)
                                goto fail;
 
                        break;
@@ -2733,11 +2733,11 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                                                ndef_length, offset,
                                                record->header->payload_len,
                                                &c_data);
-                       if (record->mime == NULL)
+                       if (!record->mime)
                                goto fail;
 
                        /* No carrier data, move on */
-                       if (c_data == NULL)
+                       if (!c_data)
                                break;
 
                        if (process_mime_type(record->mime, c_data) < 0) {
@@ -2754,7 +2754,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                        record->aar = parse_aar_payload(ndef_data + offset,
                                                record->header->payload_len);
 
-                       if (record->aar == NULL)
+                       if (!record->aar)
                                goto fail;
 
                        break;
@@ -2764,7 +2764,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
                                        record->header->payload_len;
 
                record->data = g_try_malloc0(record->data_len);
-               if (record->data == NULL)
+               if (!record->data)
                        goto fail;
 
                memcpy(record->data, record_start, record->data_len);
@@ -2867,14 +2867,14 @@ int near_ndef_count_records(uint8_t *ndef_in, size_t ndef_in_length,
 
        offset = 0;
 
-       if (ndef_in == NULL ||  ndef_in_length < NDEF_MSG_MIN_LENGTH) {
+       if (!ndef_in || ndef_in_length < NDEF_MSG_MIN_LENGTH) {
                err = -EINVAL;
                goto fail;
        }
 
        while (offset < ndef_in_length) {
                record = g_try_malloc0(sizeof(struct near_ndef_record));
-               if (record == NULL) {
+               if (!record) {
                        err = -ENOMEM;
                        goto fail;
                }
@@ -2882,7 +2882,7 @@ int near_ndef_count_records(uint8_t *ndef_in, size_t ndef_in_length,
                /* Create a record */
                record->header = parse_record_header(ndef_in, offset,
                                                        ndef_in_length);
-               if (record->header == NULL) {
+               if (!record->header) {
                        err = -EINVAL;
                        goto fail;
                }
@@ -2929,8 +2929,8 @@ struct near_ndef_message *near_ndef_prepare_text_record(char *encoding,
        /* Validate input parameters*/
        if (((g_strcmp0(encoding, "UTF-8") != 0) &&
                 (g_strcmp0(encoding, "UTF-16") != 0)) ||
-                (language_code == NULL) ||
-                (text == NULL)) {
+                (!language_code) ||
+                (!text)) {
                return NULL;
        }
 
@@ -2939,7 +2939,7 @@ struct near_ndef_message *near_ndef_prepare_text_record(char *encoding,
        payload_length = 1 + code_len + text_len;
 
        msg = ndef_message_alloc("T", payload_length);
-       if (msg == NULL)
+       if (!msg)
                return NULL;
 
        if (g_strcmp0(encoding, "UTF-16") == 0)
@@ -2979,15 +2979,15 @@ struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier,
        DBG("");
 
        /* Validate input parameters*/
-       if ((field_length == 0 && field != NULL) ||
-               (field_length != 0 && field == NULL)) {
+       if ((field_length == 0 && field) ||
+               (field_length != 0 && !field)) {
                return NULL;
        }
 
        payload_length = field_length + 1;
 
        msg = ndef_message_alloc("U", payload_length);
-       if (msg == NULL)
+       if (!msg)
                return NULL;
 
        msg->data[msg->offset++] = identifier;
@@ -3019,12 +3019,12 @@ near_ndef_prepare_smartposter_record(uint8_t uri_identifier,
        /* URI is mandatory in Smartposter */
        uri = near_ndef_prepare_uri_record(uri_identifier, uri_field_length,
                                                                uri_field);
-       if (uri == NULL)
+       if (!uri)
                goto fail;
 
        /* URI record length is equal to payload length of Sp record */
        msg = ndef_message_alloc("Sp", uri->length);
-       if (msg == NULL)
+       if (!msg)
                goto fail;
 
        memcpy(msg->data + msg->offset, uri->data, uri->length);
@@ -3053,7 +3053,7 @@ static char *get_text_field(DBusMessage *msg, char *text)
 
        DBG("");
 
-       if (text == NULL)
+       if (!text)
                return NULL;
 
        dbus_message_iter_init(msg, &iter);
@@ -3099,7 +3099,7 @@ static GSList *get_carrier_field(DBusMessage *msg)
        DBG("");
 
        carrier = get_text_field(msg, "Carrier");
-       if (carrier == NULL)
+       if (!carrier)
                return NULL;
 
        arr = g_strsplit(carrier, ",", NEAR_CARRIER_MAX);
@@ -3162,7 +3162,7 @@ static struct near_ndef_message *build_uri_record(DBusMessage *msg)
        DBG("");
 
        uri = get_uri_field(msg);
-       if (uri == NULL)
+       if (!uri)
                return NULL;
 
        id = 0;
@@ -3171,7 +3171,7 @@ static struct near_ndef_message *build_uri_record(DBusMessage *msg)
        for (i = 1; i <= NFC_MAX_URI_ID; i++) {
                uri_prefix = __near_ndef_get_uri_prefix(i);
 
-               if (uri_prefix != NULL &&
+               if (uri_prefix &&
                    g_str_has_prefix(uri, uri_prefix)) {
                        id = i;
                        id_len = strlen(uri_prefix);
@@ -3200,18 +3200,18 @@ static struct near_ndef_message *build_sp_record(DBusMessage *msg)
         * TODO: Other records support.
         */
        uri = get_uri_field(msg);
-       if (uri == NULL)
+       if (!uri)
                return NULL;
 
        for (i = 1; i <= NFC_MAX_URI_ID; i++) {
                uri_prefix = __near_ndef_get_uri_prefix(i);
 
-               if (uri_prefix != NULL &&
+               if (uri_prefix &&
                                g_str_has_prefix(uri, uri_prefix))
                        break;
        }
 
-       if (uri_prefix == NULL) {
+       if (!uri_prefix) {
                i = 0;
                id_len = 0;
        } else
@@ -3242,7 +3242,7 @@ static int fill_wifi_wsc_data(uint8_t *tlv, uint16_t id,
 {
        int offset = 0;
 
-       if (tlv == NULL || data == NULL)
+       if (!tlv || !data)
                return 0;
 
        fillb16(tlv, id);
@@ -3299,7 +3299,7 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid,
        struct near_ndef_message *mime;
 
        /* At least SSID is required in case of open network */
-       if (ssid == NULL)
+       if (!ssid)
                return NULL;
 
        DBG("SSID %s Passphrase %s", ssid, passphrase);
@@ -3307,7 +3307,7 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid,
        /* Prepare TLV from ssid and passphrasse */
        ssid_len = strlen(ssid);
 
-       if (passphrase != NULL) {
+       if (passphrase) {
                pass_len = strlen(passphrase);
                key_type = WIFI_WSC_KEY_PSK;
        } else {
@@ -3320,12 +3320,12 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid,
        /* add authentication type length */
        tlv_len += WIFI_WSC_ID_LENGTH + WIFI_WSC_ID_DATA_LENGTH + 2;
        /* add network key length */
-       if (passphrase != NULL)
+       if (passphrase)
                tlv_len += WIFI_WSC_ID_LENGTH +
                                WIFI_WSC_ID_DATA_LENGTH + pass_len;
 
        tlv = g_try_malloc0(tlv_len);
-       if (tlv ==  NULL)
+       if (!tlv)
                return NULL;
 
        offset = 0;
@@ -3344,7 +3344,7 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid,
                                                (uint8_t *) temp_key);
 
        /* copy Network Key */
-       if (passphrase != NULL)
+       if (passphrase)
                offset += fill_wifi_wsc_data(tlv + offset, WIFI_WSC_ID_KEY,
                                                pass_len,
                                                (uint8_t *) passphrase);
@@ -3352,7 +3352,7 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid,
        mime = ndef_message_alloc_complete(WIFI_WSC_MIME_STRING, tlv_len, NULL,
                                                0, RECORD_TNF_MIME, true,
                                           true);
-       if (mime == NULL) {
+       if (!mime) {
                g_free(tlv);
                return NULL;
        }
@@ -3368,7 +3368,7 @@ static char *get_mime_payload_data(DBusMessageIter iter,
 {
        DBG("");
 
-       if (payload == NULL || payload_len == NULL) {
+       if (!payload || !payload_len) {
                near_error("Payload %p payload_len %p", payload, payload_len);
                return NULL;
        }
@@ -3413,7 +3413,7 @@ static struct near_ndef_message *near_ndef_prepare_mime_payload_record(
        DBG("Payload %*s", payload_len, payload);
        mime = ndef_message_alloc_complete(type, payload_len, NULL, 0,
                                                RECORD_TNF_MIME, true, true);
-       if (mime == NULL) {
+       if (!mime) {
                near_error("Failed to alloc NDEF message");
                return NULL;
        }
@@ -3451,7 +3451,7 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg)
                                struct carrier_data *carrier;
 
                                get_wsc_data(arr_iter, &ssid, &passphrase);
-                               if (ssid != NULL)
+                               if (ssid)
                                        return near_ndef_prepare_wsc_record(
                                                        ssid, passphrase);
 
@@ -3462,13 +3462,13 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg)
                                 */
                                carrier = __near_agent_handover_request_data(
                                                        HO_AGENT_WIFI, NULL);
-                               if (carrier == NULL)
+                               if (!carrier)
                                        return NULL;
 
                                mime = ndef_message_alloc_complete(
                                        WIFI_WSC_MIME_STRING, carrier->size,
                                        NULL, 0, RECORD_TNF_MIME, true, true);
-                               if (mime == NULL) {
+                               if (!mime) {
                                        g_free(carrier);
                                        return NULL;
                                }
@@ -3490,8 +3490,8 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg)
 
                                DBG("mime string %s", mime_str);
                                dbus_message_iter_recurse(&iter, &payload_iter);
-                               if (get_mime_payload_data(payload_iter,
-                                               &payload, &payload_len) == NULL)
+                               if (!get_mime_payload_data(payload_iter,
+                                                       &payload, &payload_len))
                                        return NULL;
 
                                return near_ndef_prepare_mime_payload_record(
index c6028c0..38d66d6 100644 (file)
@@ -112,7 +112,7 @@ static int nl_send_msg(struct nl_sock *sock, struct nl_msg *msg,
        DBG("");
 
        cb = nl_cb_alloc(NL_CB_DEFAULT);
-       if (cb == NULL)
+       if (!cb)
                return -ENOMEM;
 
        err = nl_send_auto_complete(sock, msg);
@@ -129,7 +129,7 @@ static int nl_send_msg(struct nl_sock *sock, struct nl_msg *msg,
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &done);
        nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, 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)
@@ -152,9 +152,9 @@ static int get_devices_handler(struct nl_msg *n, void *arg)
 
        genlmsg_parse(nlh, 0, attrs, NFC_ATTR_MAX, NULL);
 
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL ||
-           attrs[NFC_ATTR_DEVICE_NAME] == NULL ||
-           attrs[NFC_ATTR_PROTOCOLS] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX] ||
+           !attrs[NFC_ATTR_DEVICE_NAME] ||
+           !attrs[NFC_ATTR_PROTOCOLS]) {
                nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_DEVICE");
                return NL_STOP;
        }
@@ -163,7 +163,7 @@ static int get_devices_handler(struct nl_msg *n, void *arg)
        name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
        protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
 
-       if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL)
+       if (!attrs[NFC_ATTR_DEVICE_POWERED])
                powered = false;
        else
                powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
@@ -181,16 +181,16 @@ int __near_netlink_get_adapters(void)
 
        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;
        }
@@ -213,12 +213,12 @@ int __near_netlink_start_poll(int idx,
        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;
        }
@@ -250,12 +250,12 @@ int __near_netlink_stop_poll(int idx)
        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_STOP_POLL, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -282,12 +282,12 @@ int __near_netlink_dep_link_up(uint32_t idx, uint32_t target_idx,
        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;
        }
@@ -316,12 +316,12 @@ int __near_netlink_dep_link_down(uint32_t idx)
        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_DOWN, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -348,7 +348,7 @@ int __near_netlink_adapter_enable(int idx, bool enable)
        DBG("");
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        if (enable)
@@ -358,7 +358,7 @@ int __near_netlink_adapter_enable(int idx, bool enable)
 
        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;
        }
@@ -392,7 +392,7 @@ static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, bool add)
 
        nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                near_error("Missing device index");
                return -ENODEV;
        }
@@ -400,8 +400,8 @@ static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, bool add)
        idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
 
        if (add &&
-               (attrs[NFC_ATTR_DEVICE_NAME] == NULL ||
-                       attrs[NFC_ATTR_PROTOCOLS] == NULL)) {
+               (!attrs[NFC_ATTR_DEVICE_NAME] ||
+                       !attrs[NFC_ATTR_PROTOCOLS])) {
                near_error("Missing attributes");
                return -EINVAL;
        }
@@ -413,7 +413,7 @@ static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, bool add)
 
                name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
                protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
-               if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL)
+               if (!attrs[NFC_ATTR_DEVICE_POWERED])
                        powered = false;
                else
                        powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
@@ -444,15 +444,15 @@ static int get_targets_handler(struct nl_msg *n, void *arg)
        target_idx = nla_get_u32(attrs[NFC_ATTR_TARGET_INDEX]);
        protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
 
-       if (attrs[NFC_ATTR_TARGET_SENS_RES] != NULL)
+       if (attrs[NFC_ATTR_TARGET_SENS_RES])
                sens_res =
                        nla_get_u16(attrs[NFC_ATTR_TARGET_SENS_RES]);
 
-       if (attrs[NFC_ATTR_TARGET_SEL_RES] != NULL)
+       if (attrs[NFC_ATTR_TARGET_SEL_RES])
                sel_res =
                        nla_get_u16(attrs[NFC_ATTR_TARGET_SEL_RES]);
 
-       if (attrs[NFC_ATTR_TARGET_NFCID1] != NULL) {
+       if (attrs[NFC_ATTR_TARGET_NFCID1]) {
                nfcid_len = nla_len(attrs[NFC_ATTR_TARGET_NFCID1]);
                if (nfcid_len <= NFC_MAX_NFCID1_LEN)
                        memcpy(nfcid, nla_data(attrs[NFC_ATTR_TARGET_NFCID1]),
@@ -482,7 +482,7 @@ static int nfc_netlink_event_targets_found(struct genlmsghdr *gnlh)
 
        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])
                return -ENODEV;
 
        adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
@@ -490,12 +490,12 @@ static int nfc_netlink_event_targets_found(struct genlmsghdr *gnlh)
        DBG("adapter %d", adapter_idx);
 
        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;
        }
@@ -523,10 +523,10 @@ static int nfc_netlink_event_target_lost(struct genlmsghdr *gnlh)
        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])
                return -ENODEV;
 
-       if (attr[NFC_ATTR_TARGET_INDEX] == NULL)
+       if (!attr[NFC_ATTR_TARGET_INDEX])
                return -ENODEV;
 
        adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
@@ -547,13 +547,13 @@ static int nfc_netlink_event_dep_up(struct genlmsghdr *gnlh)
 
        nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                near_error("Missing device index");
                return -ENODEV;
        }
 
-       if (attrs[NFC_ATTR_COMM_MODE] == NULL ||
-                       attrs[NFC_ATTR_RF_MODE] == NULL) {
+       if (!attrs[NFC_ATTR_COMM_MODE] ||
+                       !attrs[NFC_ATTR_RF_MODE]) {
                near_error("Missing rf or comm modes");
                return -ENODEV;
        }
@@ -562,7 +562,7 @@ static int nfc_netlink_event_dep_up(struct genlmsghdr *gnlh)
        rf_mode = nla_get_u8(attrs[NFC_ATTR_RF_MODE]);
 
        if (rf_mode == NFC_RF_INITIATOR) {
-               if (attrs[NFC_ATTR_TARGET_INDEX] == NULL) {
+               if (!attrs[NFC_ATTR_TARGET_INDEX]) {
                        near_error("Missing target index");
                        return -ENODEV;
                };
@@ -586,7 +586,7 @@ static int nfc_netlink_event_dep_down(struct genlmsghdr *gnlh)
 
        nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                near_error("Missing device index");
                return -ENODEV;
        }
@@ -607,7 +607,7 @@ static int nfc_netlink_event_tm_activated(struct genlmsghdr *gnlh)
 
        nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                near_error("Missing device index");
                return -ENODEV;
        }
@@ -628,7 +628,7 @@ static int nfc_netlink_event_tm_deactivated(struct genlmsghdr *gnlh)
 
        nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                near_error("Missing device index");
                return -ENODEV;
        }
@@ -700,7 +700,7 @@ static gboolean __nfc_netlink_event(GIOChannel *channel,
                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, no_seq_check, NULL);
@@ -784,7 +784,7 @@ static int nl_get_multicast_id(struct nl_sock *sock, const char *family,
        DBG("");
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        ctrlid = genl_ctrl_resolve(sock, "nlctrl");
@@ -816,18 +816,18 @@ int __near_netlink_init(void)
        DBG("");
 
        nfc_state = g_try_malloc0(sizeof(struct nlnfc_state));
-       if (nfc_state == NULL)
+       if (!nfc_state)
                return -ENOMEM;
 
        nfc_state->cmd_sock = nl_socket_alloc();
-       if (nfc_state->cmd_sock == NULL) {
+       if (!nfc_state->cmd_sock) {
                near_error("Failed to allocate NFC command netlink socket");
                err = -ENOMEM;
                goto state_free;
        }
 
        nfc_state->event_sock = nl_socket_alloc();
-       if (nfc_state->event_sock == NULL) {
+       if (!nfc_state->event_sock) {
                near_error("Failed to allocate NFC event netlink socket");
                err = -ENOMEM;
                goto handle_cmd_destroy;
@@ -886,14 +886,14 @@ state_free:
 
 void __near_netlink_cleanup(void)
 {
-       if (netlink_channel != NULL) {
+       if (netlink_channel) {
                g_io_channel_shutdown(netlink_channel, TRUE, NULL);
                g_io_channel_unref(netlink_channel);
 
                netlink_channel = NULL;
        }
 
-       if (nfc_state == NULL)
+       if (!nfc_state)
                return;
 
        nl_socket_free(nfc_state->cmd_sock);
index fbfc34d..f48c97e 100644 (file)
@@ -53,7 +53,7 @@ static bool add_plugin(void *handle, struct near_plugin_desc *desc)
 {
        struct near_plugin *plugin;
 
-       if (desc->init == NULL)
+       if (!desc->init)
                return false;
 
        if (!g_str_equal(desc->version, NEAR_VERSION)) {
@@ -62,7 +62,7 @@ static bool add_plugin(void *handle, struct near_plugin_desc *desc)
        }
 
        plugin = g_try_new0(struct near_plugin, 1);
-       if (plugin == NULL)
+       if (!plugin)
                return false;
 
        plugin->handle = handle;
@@ -128,8 +128,8 @@ int __near_plugin_init(const char *pattern, const char *exclude)
        }
 
        dir = g_dir_open(PLUGINDIR, 0, NULL);
-       if (dir != NULL) {
-               while ((file = g_dir_read_name(dir)) != NULL) {
+       if (dir) {
+               while ((file = g_dir_read_name(dir))) {
                        void *handle;
                        struct near_plugin_desc *desc;
 
@@ -140,7 +140,7 @@ int __near_plugin_init(const char *pattern, const char *exclude)
                        filename = g_build_filename(PLUGINDIR, file, NULL);
 
                        handle = dlopen(filename, RTLD_NOW);
-                       if (handle == NULL) {
+                       if (!handle) {
                                near_error("Can't load %s: %s",
                                                        filename, dlerror());
                                g_free(filename);
@@ -150,7 +150,7 @@ int __near_plugin_init(const char *pattern, const char *exclude)
                        g_free(filename);
 
                        desc = dlsym(handle, "near_plugin_desc");
-                       if (desc == NULL) {
+                       if (!desc) {
                                near_error("Can't load symbol: %s",
                                                                dlerror());
                                dlclose(handle);
@@ -196,7 +196,7 @@ void __near_plugin_cleanup(void)
                if (plugin->active && plugin->desc->exit)
                        plugin->desc->exit();
 
-               if (plugin->handle != NULL)
+               if (plugin->handle)
                        dlclose(plugin->handle);
 
                g_free(plugin);
index 6a87383..ef13e7f 100644 (file)
@@ -120,7 +120,7 @@ void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
        GList *records;
        struct near_ndef_message *msg = NULL;
 
-       if (ndef == NULL)
+       if (!ndef)
                return;
 
        /*
@@ -134,7 +134,7 @@ void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
 
        /* Parse the incoming frame */
        records = near_ndef_parse_msg(ndef, nfc_data_length, &msg);
-       if (records == NULL)
+       if (!records)
                return;
 
        near_ndef_records_free(records);
@@ -203,7 +203,7 @@ static void free_snep_core_fragment(gpointer data)
 {
        struct snep_fragment *fragment = data;
 
-       if (fragment != NULL)
+       if (fragment)
                g_free(fragment->data);
 
        g_free(fragment);
@@ -216,7 +216,7 @@ static void free_snep_core_push_data(gpointer userdata, int status)
 
        DBG("");
 
-       if (userdata == NULL)
+       if (!userdata)
                return;
 
        data = (struct p2p_snep_put_req_data *) userdata;
@@ -240,7 +240,7 @@ static int snep_core_send_fragment(struct p2p_snep_put_req_data *req)
 
        DBG("");
 
-       if (req == NULL || req->fragments == NULL ||
+       if (!req || !req->fragments ||
                g_slist_length(req->fragments) == 0)
                return -EINVAL;
 
@@ -292,7 +292,7 @@ static int snep_core_push_response(struct p2p_snep_put_req_data *req)
                /* Get the incoming data */
                ndef_len = frame.length;
                ndef = g_try_malloc0(ndef_len);
-               if (ndef == NULL)
+               if (!ndef)
                        return -ENOMEM;
 
                bytes_recv = recv(req->fd, ndef, ndef_len, 0);
@@ -357,7 +357,7 @@ static int snep_core_push_prepare_fragments(struct p2p_snep_put_req_data *req,
        while (ndef->offset < ndef->length) {
 
                fragment = g_try_malloc0(sizeof(struct snep_fragment));
-               if (fragment == NULL)
+               if (!fragment)
                        return -ENOMEM;
 
                if (max_fragment_len <= (ndef->length - ndef->offset))
@@ -366,7 +366,7 @@ static int snep_core_push_prepare_fragments(struct p2p_snep_put_req_data *req,
                        fragment->len = ndef->length - ndef->offset;
 
                fragment->data = g_try_malloc0(fragment->len);
-               if (fragment->data == NULL) {
+               if (!fragment->data) {
                        g_free(fragment);
                        return -ENOMEM;
                }
@@ -394,7 +394,7 @@ static bool snep_core_process_request(int client_fd,
        switch (snep_data->request) {
        case NEAR_SNEP_REQ_PUT:
                DBG("NEAR_SNEP_REQ_PUT");
-               if (req_put != NULL)
+               if (req_put)
                        ret = (*req_put)(client_fd, snep_data);
                else {
                        near_snep_core_response_noinfo(client_fd,
@@ -409,7 +409,7 @@ static bool snep_core_process_request(int client_fd,
 
        case NEAR_SNEP_REQ_GET:
                DBG("NEAR_SNEP_REQ_GET");
-               if (req_get != NULL)
+               if (req_get)
                        ret =  (*req_get)(client_fd, snep_data);
                else {
                        near_snep_core_response_noinfo(client_fd,
@@ -418,7 +418,7 @@ static bool snep_core_process_request(int client_fd,
                }
 
                /* If there's some fragments, don't delete before the CONT */
-               if (snep_data->req == NULL) {
+               if (!snep_data->req) {
                        /* free and leave */
                        DBG("Clean Table");
                        g_hash_table_remove(snep_client_hash,
@@ -428,7 +428,7 @@ static bool snep_core_process_request(int client_fd,
 
        case NEAR_SNEP_REQ_REJECT:
                DBG("NEAR_SNEP_REQ_REJECT");
-               if (snep_data->req->fragments == NULL) {
+               if (!snep_data->req->fragments) {
                        near_error("error: NEAR_SNEP_REQ_REJECT but no fragment");
                        ret = false;
                }
@@ -451,13 +451,13 @@ static bool snep_core_process_request(int client_fd,
                 * remaining fragments...
                 */
 
-               if (snep_data->req == NULL) {
+               if (!snep_data->req) {
                        ret = true;
                        break;
                }
 
                DBG("NEAR_SNEP_REQ_CONTINUE");
-               if (snep_data->req->fragments == NULL) {
+               if (!snep_data->req->fragments) {
                        near_error("error: NEAR_SNEP_REQ_CONTINUE but no fragment");
                        ret = false;
                        goto leave_cont;
@@ -531,7 +531,7 @@ bool near_snep_core_read(int client_fd,
         * If snep data is already there, and there are more bytes to read
         * we just go ahead and read more fragments from the client.
         */
-       if (snep_data != NULL &&
+       if (snep_data &&
                        snep_data->nfc_data_length !=
                                        snep_data->nfc_data_current_length) {
                ret = snep_core_read_ndef(client_fd, snep_data);
@@ -573,21 +573,21 @@ bool near_snep_core_read(int client_fd,
         * we should just process a CONTINUE frame and send the fragments
         * back to the client. This will be done from snep_core_process_request().
         */
-       if (snep_data != NULL) {
+       if (snep_data) {
                snep_data->request = frame.request;
                goto process_request;
        }
 
        /* This is a new request from the client */
        snep_data = g_try_malloc0(sizeof(struct p2p_snep_data));
-       if (snep_data == NULL)
+       if (!snep_data)
                return false;
 
        /* the whole frame length */
        ndef_length = GINT_FROM_BE(frame.length);
 
        snep_data->nfc_data = g_try_malloc0(ndef_length + TLV_SIZE);
-       if (snep_data->nfc_data == NULL) {
+       if (!snep_data->nfc_data) {
                g_free(snep_data);
                return false;
        }
@@ -658,7 +658,7 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req,
 
        fragment = g_try_malloc0(sizeof(struct snep_fragment));
 
-       if (fragment == NULL) {
+       if (!fragment) {
                err = -ENOMEM;
                goto error;
        }
@@ -672,7 +672,7 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req,
        }
 
        fragment->data = g_try_malloc0(fragment->len);
-       if (fragment->data == NULL) {
+       if (!fragment->data) {
                g_free(fragment);
                err = ENOMEM;
                goto error;
@@ -716,7 +716,7 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req,
        return 0;
 
 error:
-       if (req != NULL)
+       if (req)
                free_snep_core_push_data(req, err);
 
        return err;
@@ -737,18 +737,18 @@ void near_snep_core_response_with_info(int client_fd, uint8_t response,
        /* get the snep data */
        snep_data = g_hash_table_lookup(snep_client_hash,
                                                GINT_TO_POINTER(client_fd));
-       if (snep_data == NULL) {
+       if (!snep_data) {
                DBG("snep_data not found");
                goto done;
        }
 
        /* Prepare the ndef struct */
        ndef = g_try_malloc0(sizeof(struct near_ndef_message));
-       if (ndef == NULL)
+       if (!ndef)
                goto done;
 
        ndef->data = g_try_malloc0(length);
-       if (ndef->data == NULL) {
+       if (!ndef->data) {
                g_free(ndef);
                ndef = NULL;
                goto done;
@@ -763,7 +763,7 @@ void near_snep_core_response_with_info(int client_fd, uint8_t response,
 
        /* Now prepare req struct */
        req = g_try_malloc0(sizeof(struct p2p_snep_put_req_data));
-       if (req == NULL)
+       if (!req)
                goto done;
 
        /* Prepare the callback */
@@ -779,14 +779,14 @@ void near_snep_core_response_with_info(int client_fd, uint8_t response,
 
 done:
        /* If no fragment, free mem */
-       if (req != NULL) {
+       if (req) {
                if (req->fragments == 0) {
                        g_free(req);
                        snep_data->req = NULL;
                }
        }
 
-       if (ndef != NULL)
+       if (ndef)
                g_free(ndef->data);
        g_free(ndef);
 }
@@ -804,7 +804,7 @@ int near_snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
        DBG("");
 
        req = g_try_malloc0(sizeof(struct p2p_snep_put_req_data));
-       if (req == NULL) {
+       if (!req) {
                err = -ENOMEM;
                goto error;
        }
@@ -845,7 +845,7 @@ void near_snep_core_close(int client_fd, int err)
 
        snep_data = g_hash_table_lookup(snep_client_hash,
                                        GINT_TO_POINTER(client_fd));
-       if (snep_data == NULL)
+       if (!snep_data)
                return;
 
        snep_data->cb(snep_data->adapter_idx, snep_data->target_idx, err);
index 65a3780..28518f2 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -88,7 +88,7 @@ struct near_tag *near_tag_get_tag(uint32_t adapter_idx, uint32_t target_idx)
 
        path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
                                        adapter_idx, target_idx);
-       if (path == NULL)
+       if (!path)
                return NULL;
 
        tag = g_hash_table_lookup(tag_hash, path);
@@ -110,7 +110,7 @@ static void append_records(DBusMessageIter *iter, void *user_data)
                char *path;
 
                path = __near_ndef_record_get_path(record);
-               if (path == NULL)
+               if (!path)
                        continue;
 
                dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
@@ -193,7 +193,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBG("conn %p", conn);
 
        reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
+       if (!reply)
                return NULL;
 
        dbus_message_iter_init_append(reply, &array);
@@ -201,12 +201,12 @@ static DBusMessage *get_properties(DBusConnection *conn,
        near_dbus_dict_open(&array, &dict);
 
        type = type_string(tag);
-       if (type != NULL)
+       if (type)
                near_dbus_dict_append_basic(&dict, "Type",
                                        DBUS_TYPE_STRING, &type);
 
        protocol = protocol_string(tag);
-       if (protocol != NULL)
+       if (protocol)
                near_dbus_dict_append_basic(&dict, "Protocol",
                                        DBUS_TYPE_STRING, &protocol);
 
@@ -236,7 +236,7 @@ static void tag_read_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
 
-       if (tag == NULL)
+       if (!tag)
                return;
 
        dbus_message_unref(tag->write_msg);
@@ -256,16 +256,16 @@ static void write_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
        DBG("Write status %d", status);
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                return;
 
        conn = near_dbus_get_connection();
-       if (conn == NULL)
+       if (!conn)
                goto out;
 
        if (status != 0) {
                reply = __near_error_failed(tag->write_msg, EINVAL);
-               if (reply != NULL)
+               if (reply)
                        g_dbus_send_message(conn, reply);
        } else {
                g_dbus_send_reply(conn, tag->write_msg, DBUS_TYPE_INVALID);
@@ -301,10 +301,10 @@ static void format_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
        DBG("format status %d", status);
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                return;
 
-       if (tag->write_msg == NULL)
+       if (!tag->write_msg)
                return;
 
        if (status == 0) {
@@ -341,7 +341,7 @@ static DBusMessage *write_ndef(DBusConnection *conn,
                return __near_error_in_progress(msg);
 
        ndef = __ndef_build_from_message(msg);
-       if (ndef == NULL)
+       if (!ndef)
                return __near_error_failed(msg, EINVAL);
 
        tag->write_msg = dbus_message_ref(msg);
@@ -357,14 +357,14 @@ static DBusMessage *write_ndef(DBusConnection *conn,
 
                ndef_with_header = g_try_malloc0(sizeof(
                                        struct near_ndef_message));
-               if (ndef_with_header == NULL)
+               if (!ndef_with_header)
                        goto fail;
 
                ndef_with_header->offset = 0;
                ndef_with_header->length = ndef->length + tlv_len_size;
                ndef_with_header->data =
                                g_try_malloc0(ndef->length + tlv_len_size);
-               if (ndef_with_header->data == NULL)
+               if (!ndef_with_header->data)
                        goto fail;
 
                ndef_with_header->data[0] = TLV_NDEF;
@@ -387,14 +387,14 @@ static DBusMessage *write_ndef(DBusConnection *conn,
        case NFC_PROTO_FELICA:
                ndef_with_header = g_try_malloc0(sizeof(
                                        struct near_ndef_message));
-               if (ndef_with_header == NULL)
+               if (!ndef_with_header)
                        goto fail;
 
                ndef_with_header->offset = 0;
                ndef_with_header->length = ndef->length;
                ndef_with_header->data = g_try_malloc0(
                                                ndef_with_header->length);
-               if (ndef_with_header->data == NULL)
+               if (!ndef_with_header->data)
                        goto fail;
 
                memcpy(ndef_with_header->data, ndef->data, ndef->length);
@@ -404,13 +404,13 @@ static DBusMessage *write_ndef(DBusConnection *conn,
        case NFC_PROTO_ISO14443:
                ndef_with_header = g_try_malloc0(sizeof(
                                        struct near_ndef_message));
-               if (ndef_with_header == NULL)
+               if (!ndef_with_header)
                        goto fail;
 
                ndef_with_header->offset = 0;
                ndef_with_header->length = ndef->length + 2;
                ndef_with_header->data = g_try_malloc0(ndef->length + 2);
-               if (ndef_with_header->data == NULL)
+               if (!ndef_with_header->data)
                        goto fail;
 
                ndef_with_header->data[0] = (uint8_t)(ndef->length >> 8);
@@ -475,7 +475,7 @@ void __near_tag_append_records(struct near_tag *tag, DBusMessageIter *iter)
                char *path;
 
                path = __near_ndef_record_get_path(record);
-               if (path == NULL)
+               if (!path)
                        continue;
 
                dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
@@ -590,7 +590,7 @@ static int tag_initialize(struct near_tag *tag,
 
        tag->path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
                                        adapter_idx, target_idx);
-       if (tag->path == NULL)
+       if (!tag->path)
                return -ENOMEM;
        tag->adapter_idx = adapter_idx;
        tag->target_idx = target_idx;
@@ -617,11 +617,11 @@ struct near_tag *__near_tag_add(uint32_t adapter_idx, uint32_t target_idx,
        char *path;
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag != NULL)
+       if (tag)
                return NULL;
 
        tag = g_try_malloc0(sizeof(struct near_tag));
-       if (tag == NULL)
+       if (!tag)
                return NULL;
 
        if (tag_initialize(tag, adapter_idx, target_idx,
@@ -633,7 +633,7 @@ struct near_tag *__near_tag_add(uint32_t adapter_idx, uint32_t target_idx,
        }
 
        path = g_strdup(tag->path);
-       if (path == NULL) {
+       if (!path) {
                g_free(tag);
                return NULL;
        }
@@ -656,7 +656,7 @@ void __near_tag_remove(struct near_tag *tag)
 
        DBG("path %s", tag->path);
 
-       if (g_hash_table_lookup(tag_hash, tag->path) == NULL)
+       if (!g_hash_table_lookup(tag_hash, tag->path))
                return;
 
        g_dbus_unregister_interface(connection, tag->path,
@@ -682,7 +682,7 @@ enum near_tag_sub_type near_tag_get_subtype(uint32_t adapter_idx,
        struct near_tag *tag;
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                return NEAR_TAG_NFC_SUBTYPE_UNKNOWN;
 
        return tag->sub_type;
@@ -695,11 +695,11 @@ uint8_t *near_tag_get_nfcid(uint32_t adapter_idx, uint32_t target_idx,
        uint8_t *nfcid;
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                goto fail;
 
        nfcid = g_try_malloc0(tag->nfcid_len);
-       if (nfcid == NULL)
+       if (!nfcid)
                goto fail;
 
        memcpy(nfcid, tag->nfcid, tag->nfcid_len);
@@ -720,7 +720,7 @@ int near_tag_set_nfcid(uint32_t adapter_idx, uint32_t target_idx,
        DBG("NFCID len %zd", nfcid_len);
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                return -ENODEV;
 
        if (tag->nfcid_len > 0)
@@ -741,15 +741,15 @@ int near_tag_add_data(uint32_t adapter_idx, uint32_t target_idx,
        struct near_tag *tag;
 
        tag = near_tag_get_tag(adapter_idx, target_idx);
-       if (tag == NULL)
+       if (!tag)
                return -ENODEV;
 
        tag->data_length = data_length;
        tag->data = g_try_malloc0(data_length);
-       if (tag->data == NULL)
+       if (!tag->data)
                return -ENOMEM;
 
-       if (data != NULL)
+       if (data)
                memcpy(tag->data, data, data_length);
 
        return 0;
@@ -771,7 +771,7 @@ int near_tag_add_records(struct near_tag *tag, GList *records,
                                        NFC_PATH, tag->adapter_idx,
                                        tag->target_idx, tag->n_records);
 
-               if (path == NULL)
+               if (!path)
                        continue;
 
                __near_ndef_record_register(record, path);
@@ -787,7 +787,7 @@ int near_tag_add_records(struct near_tag *tag, GList *records,
                                        DBUS_TYPE_OBJECT_PATH, append_records,
                                        tag);
 
-       if (cb != NULL)
+       if (cb)
                cb(tag->adapter_idx, tag->target_idx, status);
 
        g_list_free(records);
@@ -812,7 +812,7 @@ bool near_tag_get_blank(struct near_tag *tag)
 
 uint8_t *near_tag_get_data(struct near_tag *tag, size_t *data_length)
 {
-       if (data_length == NULL)
+       if (!data_length)
                return NULL;
 
        *data_length = tag->data_length;
@@ -837,7 +837,7 @@ uint32_t near_tag_get_target_idx(struct near_tag *tag)
 
 enum near_tag_memory_layout near_tag_get_memory_layout(struct near_tag *tag)
 {
-       if (tag == NULL)
+       if (!tag)
                return NEAR_TAG_MEMORY_UNKNOWN;
 
        return tag->layout;
@@ -846,7 +846,7 @@ enum near_tag_memory_layout near_tag_get_memory_layout(struct near_tag *tag)
 void near_tag_set_memory_layout(struct near_tag *tag,
                                        enum near_tag_memory_layout layout)
 {
-       if (tag == NULL)
+       if (!tag)
                return;
 
        tag->layout = layout;
@@ -854,7 +854,7 @@ void near_tag_set_memory_layout(struct near_tag *tag,
 
 void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size)
 {
-       if (tag == NULL)
+       if (!tag)
                return;
 
        tag->t4.max_ndef_size = size;
@@ -862,7 +862,7 @@ void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size)
 
 uint16_t near_tag_get_max_ndef_size(struct near_tag *tag)
 {
-       if (tag == NULL)
+       if (!tag)
                return 0;
 
        return tag->t4.max_ndef_size;
@@ -870,7 +870,7 @@ uint16_t near_tag_get_max_ndef_size(struct near_tag *tag)
 
 void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size)
 {
-       if (tag == NULL)
+       if (!tag)
                return;
 
        tag->t4.c_apdu_max_size = size;
@@ -878,7 +878,7 @@ void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size)
 
 uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag)
 {
-       if (tag == NULL)
+       if (!tag)
                return 0;
 
        return tag->t4.c_apdu_max_size;
@@ -886,7 +886,7 @@ uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag)
 
 void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len)
 {
-       if (tag == NULL || len > TYPE3_IDM_LEN)
+       if (!tag || len > TYPE3_IDM_LEN)
                return;
 
        memset(tag->t3.IDm, 0, TYPE3_IDM_LEN);
@@ -895,7 +895,7 @@ void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len)
 
 uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len)
 {
-       if (tag == NULL || len == NULL)
+       if (!tag || !len)
                return NULL;
 
        *len = TYPE3_IDM_LEN;
@@ -904,7 +904,7 @@ uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len)
 
 void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len)
 {
-       if (tag == NULL || len > TYPE3_ATTR_BLOCK_SIZE)
+       if (!tag || len > TYPE3_ATTR_BLOCK_SIZE)
                return;
 
        memset(tag->t3.attr, 0, TYPE3_ATTR_BLOCK_SIZE);
@@ -913,7 +913,7 @@ void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len)
 
 uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len)
 {
-       if (tag == NULL || len == NULL)
+       if (!tag || !len)
                return NULL;
 
        *len = TYPE3_ATTR_BLOCK_SIZE;
@@ -922,7 +922,7 @@ uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len)
 
 void near_tag_set_ic_type(struct near_tag *tag, uint8_t ic_type)
 {
-       if (tag == NULL)
+       if (!tag)
                return;
 
        tag->t3.ic_type = ic_type;
@@ -930,7 +930,7 @@ void near_tag_set_ic_type(struct near_tag *tag, uint8_t ic_type)
 
 uint8_t near_tag_get_ic_type(struct near_tag *tag)
 {
-       if (tag == NULL)
+       if (!tag)
                return 0;
 
        return tag->t3.ic_type;
@@ -948,7 +948,7 @@ int near_tag_driver_register(struct near_tag_driver *driver)
 {
        DBG("");
 
-       if (driver->read == NULL)
+       if (!driver->read)
                return -EINVAL;
 
        driver_list = g_slist_insert_sorted(driver_list, driver, cmp_prio);
@@ -1004,7 +1004,7 @@ int __near_tag_write(struct near_tag *tag,
                        __near_adapter_stop_check_presence(tag->adapter_idx,
                                                                tag->target_idx);
 
-                       if (tag->blank && driver->format != NULL) {
+                       if (tag->blank && driver->format) {
                                DBG("Blank tag detected, formatting");
                                err = driver->format(tag->adapter_idx,
                                                tag->target_idx, format_cb);
@@ -1018,7 +1018,7 @@ int __near_tag_write(struct near_tag *tag,
                }
        }
 
-       if (list == NULL)
+       if (!list)
                err = -EOPNOTSUPP;
 
        if (err < 0)
@@ -1040,7 +1040,7 @@ int __near_tag_check_presence(struct near_tag *tag, near_tag_io_cb cb)
                DBG("driver type 0x%x", driver->type);
 
                if (driver->type == tag->type) {
-                       if (driver->check_presence == NULL)
+                       if (!driver->check_presence)
                                continue;
 
                        return driver->check_presence(tag->adapter_idx, tag->target_idx, cb);