tools: Do not compare expression against NULL
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 14 Aug 2013 07:27:58 +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
)

tools/nfctool/adapter.c
tools/nfctool/llcp-decode.c
tools/nfctool/main.c
tools/nfctool/ndef-decode.c
tools/nfctool/netlink.c
tools/nfctool/snep-decode.c
tools/nfctool/sniffer.c
tools/snep-send.c

index 870bfb2..288e0b4 100644 (file)
@@ -82,7 +82,7 @@ void adapter_print_info(struct nfc_adapter *adapter)
 {
        gchar *rf_mode_str;
 
-       if (adapter == NULL)
+       if (!adapter)
                return;
 
        printf("nfc%d:\n", adapter->idx);
index 8afa067..8704873 100644 (file)
@@ -197,7 +197,7 @@ static void llcp_check_cc(struct sniffer_packet *packet)
        /* Do we have a CONNECT pending for this SAP ?*/
        sn = g_hash_table_lookup(connection_hash,
                                        GINT_TO_POINTER(dsap));
-       if (sn == NULL)
+       if (!sn)
                return;
 
        if (strcmp(sn, "urn:nfc:sn:handover") == 0)
@@ -517,7 +517,7 @@ int llcp_print_pdu(guint8 *data, guint32 data_len, struct timeval *timestamp)
        gchar *direction_color;
        int err;
 
-       if (timestamp == NULL)
+       if (!timestamp)
                return -EINVAL;
 
        if (!timerisset(&start_timestamp))
index c6a05af..8527dd7 100644 (file)
@@ -67,7 +67,7 @@ static int nfctool_start_poll(void)
 
        adapter = adapter_get(opts.adapter_idx);
 
-       if (adapter == NULL) {
+       if (!adapter) {
                print_error("Invalid adapter index: %d", opts.adapter_idx);
 
                return -ENODEV;
@@ -231,7 +231,7 @@ static int nfctool_targets_found(guint32 adapter_idx)
 
        adapter = adapter_get(adapter_idx);
 
-       if (adapter == NULL)
+       if (!adapter)
                return -ENODEV;
 
        err = nl_get_targets(adapter);
@@ -287,7 +287,7 @@ static void nfctool_print_and_remove_snl(struct nfc_snl *sdres,
                elem = g_slist_find_custom(opts.snl_list, sdres->uri,
                                           (GCompareFunc)g_strcmp0);
 
-               if (elem != NULL) {
+               if (elem) {
                        g_free(elem->data);
                        opts.snl_list = g_slist_delete_link(opts.snl_list,
                                                            elem);
@@ -306,7 +306,7 @@ static int nfctool_snl_cb(guint8 cmd, guint32 idx, gpointer data)
 
        printf("\n");
 
-       if (opts.snl_list == NULL) {
+       if (!opts.snl_list) {
                opts.snl = false;
                nfctool_quit(false);
        }
@@ -380,7 +380,7 @@ static bool opt_parse_poll_arg(const gchar *option_name, const gchar *value,
 
        opts.poll_mode = POLLING_MODE_INITIATOR;
 
-       if (value != NULL) {
+       if (value) {
                if (*value == 't' || *value == 'T')
                        opts.poll_mode = POLLING_MODE_TARGET;
                else if (*value == 'b' || *value == 'B')
@@ -402,10 +402,10 @@ static bool opt_parse_set_param_arg(const gchar *option_name,
        params = g_strsplit(value, ",", -1);
 
        i = 0;
-       while (params[i] != NULL) {
+       while (params[i]) {
                keyval = g_strsplit(params[i], "=", 2);
 
-               if (keyval[0] == NULL || keyval[1] == NULL) {
+               if (!keyval[0] || !keyval[1]) {
                        result = false;
                        goto exit;
                }
@@ -472,7 +472,7 @@ static bool opt_parse_show_timestamp_arg(const gchar *option_name,
                                             const gchar *value,
                                             gpointer data, GError **error)
 {
-       if (value != NULL && (*value == 'a' || *value == 'A'))
+       if (value && (*value == 'a' || *value == 'A'))
                opts.show_timestamp = SNIFFER_SHOW_TIMESTAMP_ABS;
        else
                opts.show_timestamp = SNIFFER_SHOW_TIMESTAMP_DELTA;
@@ -556,7 +556,7 @@ static int nfctool_options_parse(int argc, char **argv)
                goto done;
        }
 
-       if (opts.device_name != NULL) {
+       if (opts.device_name) {
                if (strncmp("nfc", opts.device_name, 3) != 0) {
                        print_error("Invalid device name: %s",
                                                        opts.device_name);
@@ -622,10 +622,10 @@ static void nfctool_main_loop_start(void)
 
 static void nfctool_options_cleanup(void)
 {
-       if (opts.device_name != NULL)
+       if (opts.device_name)
                g_free(opts.device_name);
 
-       if (opts.pcap_filename != NULL)
+       if (opts.pcap_filename)
                g_free(opts.pcap_filename);
 
        g_slist_free_full(opts.snl_list, g_free);
@@ -633,7 +633,7 @@ static void nfctool_options_cleanup(void)
 
 static void nfctool_main_loop_clean(void)
 {
-       if (main_loop != NULL)
+       if (main_loop)
                g_main_loop_unref(main_loop);
 }
 
index e4146e7..953a622 100644 (file)
@@ -117,7 +117,7 @@ static void ndef_print_bt_oob(guint8 *oob_data, guint32 oob_length)
                case EIR_NAME_SHORT:
                case EIR_NAME_COMPLETE:
                        local_name = g_try_malloc0(eir_length);
-                       if (local_name == NULL)
+                       if (!local_name)
                                break;
 
                        g_snprintf(local_name, eir_length,
@@ -176,7 +176,7 @@ static void ndef_print_wsc_oob(guint8 *oob_data, guint32 oob_length)
 
                case DE_SSID:
                        ssid = g_try_malloc0(de_length + 1);
-                       if (ssid == NULL)
+                       if (!ssid)
                                break;
 
                        g_snprintf(ssid, de_length + 1,
@@ -188,7 +188,7 @@ static void ndef_print_wsc_oob(guint8 *oob_data, guint32 oob_length)
 
                case DE_NETWORK_KEY:
                        passphrase = g_try_malloc0(de_length + 1);
-                       if (passphrase == NULL)
+                       if (!passphrase)
                                break;
 
                        g_snprintf(passphrase, de_length + 1,
@@ -326,7 +326,7 @@ int ndef_print_records(guint8 *data, guint32 data_len)
                        switch (tnf) {
                        case RECORD_TNF_MIME:
                                mime_string = g_try_malloc(type_len + 1);
-                               if (mime_string != NULL) {
+                               if (mime_string) {
                                        g_snprintf(mime_string,
                                                type_len + 1, "%s", type);
 
@@ -351,7 +351,7 @@ int ndef_print_records(guint8 *data, guint32 data_len)
                }
 
                if (payload) {
-                       if (mime_string != NULL) {
+                       if (mime_string) {
                                if (strcmp(mime_string,
                                "application/vnd.bluetooth.ep.oob") == 0)
                                        ndef_print_bt_oob(payload, payload_len);
index 7c2560f..3d248a5 100644 (file)
@@ -123,7 +123,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);
@@ -140,7 +140,7 @@ static int nl_send_msg(struct nl_sock *sock, struct nl_msg *msg,
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, nl_finish_handler, &done);
        nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, nl_ack_handler, &done);
 
-       if (rx_handler != NULL)
+       if (rx_handler)
                nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, rx_handler, data);
 
        while (err == 0 && done == 0)
@@ -200,7 +200,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");
@@ -242,7 +242,7 @@ static int nl_get_params_handler(struct nl_msg *n, void *arg)
 
        genlmsg_parse(nlh, 0, attrs, NFC_ATTR_MAX, NULL);
 
-       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_PARAMS");
                return NL_STOP;
        }
@@ -268,16 +268,16 @@ int nl_get_params(struct nfc_adapter *adapter)
 
        DBG("");
 
-       if (nfc_state == NULL || nfc_state->nfc_id < 0)
+       if (!nfc_state || nfc_state->nfc_id < 0)
                return -ENODEV;
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
                          0, NFC_CMD_LLC_GET_PARAMS, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -307,16 +307,16 @@ int nl_set_params(struct nfc_adapter *adapter, gint32 lto, gint32 rw,
        if (lto < 0 && rw < 0 && miux < 0)
                return -EINVAL;
 
-       if (nfc_state == NULL || nfc_state->nfc_id < 0)
+       if (!nfc_state || nfc_state->nfc_id < 0)
                return -ENODEV;
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
                          0, NFC_CMD_LLC_SET_PARAMS, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -373,16 +373,16 @@ int nl_get_targets(struct nfc_adapter *adapter)
 
        DBG("");
 
-       if (nfc_state == NULL || nfc_state->nfc_id < 0)
+       if (!nfc_state || nfc_state->nfc_id < 0)
                return -ENODEV;
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
                          NLM_F_DUMP, NFC_CMD_GET_TARGET, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -420,20 +420,20 @@ static int nl_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) {
+       if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
                nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_DEVICE");
                return NL_STOP;
        }
 
        idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
 
-       if (attrs[NFC_ATTR_PROTOCOLS] != NULL)
+       if (attrs[NFC_ATTR_PROTOCOLS])
                protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
 
-       if (attrs[NFC_ATTR_RF_MODE] != NULL)
+       if (attrs[NFC_ATTR_RF_MODE])
                rf_mode = nla_get_u8(attrs[NFC_ATTR_RF_MODE]);
 
-       if (attrs[NFC_ATTR_DEVICE_POWERED] != NULL)
+       if (attrs[NFC_ATTR_DEVICE_POWERED])
                powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
 
        adapter_add(idx, protocols, powered, rf_mode);
@@ -449,16 +449,16 @@ int nl_get_devices(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;
        }
@@ -483,12 +483,12 @@ int nl_send_dep_link_up(guint32 idx, guint32 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;
        }
@@ -525,12 +525,12 @@ int nl_start_poll(struct nfc_adapter *adapter, guint8 mode)
        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;
        }
@@ -566,7 +566,7 @@ int nl_set_powered(struct nfc_adapter *adapter, bool powered)
        DBG("");
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        if (powered)
@@ -576,7 +576,7 @@ int nl_set_powered(struct nfc_adapter *adapter, bool powered)
 
        hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
                        NLM_F_REQUEST, cmd, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -603,16 +603,16 @@ int nl_send_sdreq(struct nfc_adapter *adapter, GSList *uris)
 
        DBG("");
 
-       if (nfc_state == NULL || nfc_state->nfc_id < 0)
+       if (!nfc_state || nfc_state->nfc_id < 0)
                return -ENODEV;
 
        msg = nlmsg_alloc();
-       if (msg == NULL)
+       if (!msg)
                return -ENOMEM;
 
        hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
                          NLM_F_REQUEST, NFC_CMD_LLC_SDREQ, NFC_GENL_VERSION);
-       if (hdr == NULL) {
+       if (!hdr) {
                err = -EINVAL;
                goto nla_put_failure;
        }
@@ -620,17 +620,17 @@ int nl_send_sdreq(struct nfc_adapter *adapter, GSList *uris)
        NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, adapter->idx);
 
        sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP);
-       if (sdp_attr == NULL) {
+       if (!sdp_attr) {
                err = -ENOMEM;
                goto nla_put_failure;
        }
 
        i = 1;
        uri = uris;
-       while (uri != NULL) {
+       while (uri) {
                uri_attr = nla_nest_start(msg, i);
 
-               if (uri_attr == NULL) {
+               if (!uri_attr) {
                        err = -ENOMEM;
                        goto nla_put_failure;
                }
@@ -675,8 +675,8 @@ static int nl_nfc_send_sdres_event(guint32 idx, struct nlattr *sdres_attr,
                        continue;
                }
 
-               if (sdp_attrs[NFC_SDP_ATTR_URI] == NULL ||
-                   sdp_attrs[NFC_SDP_ATTR_SAP] == NULL) {
+               if (!sdp_attrs[NFC_SDP_ATTR_URI] ||
+                   !sdp_attrs[NFC_SDP_ATTR_SAP]) {
                        print_error("Missing attribute in reply");
                        continue;
                }
@@ -716,13 +716,13 @@ static int nl_nfc_event_cb(struct nl_msg *n, void *arg)
        nla_parse(attr, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                genlmsg_attrlen(gnlh, 0), NULL);
 
-       if (attr[NFC_ATTR_DEVICE_INDEX] != NULL)
+       if (attr[NFC_ATTR_DEVICE_INDEX])
                idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
 
-       if (handlers != NULL)
+       if (handlers)
                cb = g_hash_table_lookup(handlers, GINT_TO_POINTER(cmd));
 
-       if (cb == NULL)
+       if (!cb)
                return NL_SKIP;
 
        switch (cmd) {
@@ -749,7 +749,7 @@ static gboolean nl_gio_handler(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, nl_no_seq_check_cb, NULL);
@@ -766,7 +766,7 @@ void nl_add_event_handler(guint8 cmd, nfc_event_cb_t cb)
 {
        guint32 c = cmd;
 
-       if (handlers != NULL)
+       if (handlers)
                g_hash_table_replace(handlers, GINT_TO_POINTER(c), cb);
 }
 
@@ -789,7 +789,7 @@ void nl_cleanup(void)
                nfc_state = NULL;
        }
 
-       if (handlers != NULL)
+       if (handlers)
                g_hash_table_destroy(handlers);
 }
 
@@ -803,14 +803,14 @@ int nl_init(void)
        nfc_state = g_malloc0(sizeof(struct nlnfc_state));
 
        nfc_state->cmd_sock = nl_socket_alloc();
-       if (nfc_state->cmd_sock == NULL) {
+       if (!nfc_state->cmd_sock) {
                print_error("Failed to allocate NFC netlink socket");
                err = -ENOMEM;
                goto exit_err;
        }
 
        nfc_state->event_sock = nl_socket_alloc();
-       if (nfc_state->event_sock == NULL) {
+       if (!nfc_state->event_sock) {
                print_error("Failed to allocate NFC netlink socket");
                err = -ENOMEM;
                goto exit_err;
index 0578a7f..27d3c1e 100644 (file)
@@ -261,7 +261,7 @@ int snep_print_pdu(struct sniffer_packet *packet)
 
        frag = g_hash_table_lookup(snep_frag_hash, GINT_TO_POINTER(frag_index));
 
-       if (frag != NULL) {
+       if (frag) {
                /* Incoming or outgoing fragmented message */
                err = snep_frag_append(frag, packet);
 
@@ -362,7 +362,7 @@ exit:
 
 void snep_decode_cleanup(void)
 {
-       if (snep_frag_hash != NULL)
+       if (snep_frag_hash)
                g_hash_table_destroy(snep_frag_hash);
 }
 
index aba06ec..71ac612 100644 (file)
@@ -61,7 +61,7 @@ static int pcap_file_write_packet(guint8 *data, guint32 len,
        guint32 val32;
        guint32 incl_len;
 
-       if (pcap_file == NULL || data == NULL || len == 0)
+       if (!pcap_file || !data || len == 0)
                return -EINVAL;
 
        val32 = timestamp->tv_sec;
@@ -141,7 +141,7 @@ exit_err:
 
 static void pcap_file_cleanup(void)
 {
-       if (pcap_file != NULL) {
+       if (pcap_file) {
                fclose(pcap_file);
                pcap_file = NULL;
        }
@@ -359,7 +359,7 @@ int sniffer_init(void)
 
        g_io_channel_unref(gio_channel);
 
-       if (opts.pcap_filename != NULL) {
+       if (opts.pcap_filename) {
                err = pcap_file_init(opts.pcap_filename);
                if (err)
                        goto exit;
index 8d9aa64..5bb1532 100644 (file)
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
        }
        
        ndef = near_ndef_prepare_text_record("UTF-8", "en", "Hello world");
-       if (ndef == NULL) {
+       if (!ndef) {
                close(fd);
                near_error("Could not build NDEF");
                return -1;
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
 
        frame_length = sizeof(struct p2p_snep_req_frame) + ndef->length;
        frame = g_try_malloc0(frame_length);
-       if (frame == NULL) {
+       if (!frame) {
                close(fd);
                near_error("Could not allocate SNEP frame");
                return -1;