From: Uwe Hermann Date: Mon, 23 Mar 2015 19:09:08 +0000 (+0100) Subject: Various NULL-check consistency fixes. X-Git-Tag: libsigrok-0.4.0~563 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=98fec29ecbb5093856b69311be8e937c162edded;p=libsigrok.git Various NULL-check consistency fixes. --- diff --git a/src/ezusb.c b/src/ezusb.c index 034c6c9e..9f40d3b7 100644 --- a/src/ezusb.c +++ b/src/ezusb.c @@ -57,7 +57,7 @@ SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl, unsigned char buf[4096]; sr_info("Uploading firmware at %s", filename); - if ((fw = g_fopen(filename, "rb")) == NULL) { + if (!(fw = g_fopen(filename, "rb"))) { sr_err("Unable to open firmware file %s for reading: %s", filename, strerror(errno)); return SR_ERR; diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index 4bcf772d..def373d1 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -115,7 +115,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) * Let's assume there's no ACME device present if no probe * has been registered. */ - if (sdi->channel_groups == NULL) + if (!sdi->channel_groups) goto err_out; devices = g_slist_append(devices, sdi); diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 4fae9b80..5f1d35fc 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -365,7 +365,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index baa1476d..04284e50 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -426,7 +426,7 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; - if (usb->devhdl == NULL) + if (!usb->devhdl) return SR_ERR; sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.", @@ -629,7 +629,7 @@ static int start_transfers(const struct sr_dev_inst *sdi) if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else diff --git a/src/hardware/fx2lafw/dslogic.c b/src/hardware/fx2lafw/dslogic.c index f0b49c34..715ca8a5 100644 --- a/src/hardware/fx2lafw/dslogic.c +++ b/src/hardware/fx2lafw/dslogic.c @@ -57,7 +57,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, } buf = g_malloc(FW_BUFSIZE); - if ((fw = g_fopen(filename, "rb")) == NULL) { + if (!(fw = g_fopen(filename, "rb"))) { sr_err("Unable to open %s for reading: %s.", filename, strerror(errno)); return SR_ERR; } diff --git a/src/hardware/hantek-dso/dso.c b/src/hardware/hantek-dso/dso.c index 814db598..76615748 100644 --- a/src/hardware/hantek-dso/dso.c +++ b/src/hardware/hantek-dso/dso.c @@ -185,7 +185,7 @@ SR_PRIV void dso_close(struct sr_dev_inst *sdi) usb = sdi->conn; - if (usb->devhdl == NULL) + if (!usb->devhdl) return; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 31e1fb1f..a18557cf 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -77,7 +77,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, USB_VID_PID); - if (usb_devices == NULL) + if (!usb_devices) return NULL; for (l = usb_devices; l; l = l->next) { diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 89718894..dbc66fdd 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -116,7 +116,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } if (!conn) conn = SERIALCONN; - if (serialcomm == NULL) + if (!serialcomm) serialcomm = SERIALCOMM; udev = udev_new(); diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 11fa8a61..148f0ba1 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -336,7 +336,7 @@ SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info) sr_dbg("Requesting trigger state."); ret = mso_send_control_message(serial, ARRAY_AND_SIZE(ops)); - if (info == NULL || ret != SR_OK) + if (!info || ret != SR_OK) return ret; uint8_t buf = 0; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index c8ddc4be..14437839 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -123,7 +123,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (!conn) return NULL; - if (serialcomm == NULL) + if (!serialcomm) serialcomm = SERIALCOMM; serial = sr_serial_dev_inst_new(conn, serialcomm); diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index c82bac80..55e3d752 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -398,7 +398,7 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; - if (usb->devhdl == NULL) + if (!usb->devhdl) return SR_ERR; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", @@ -738,7 +738,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else diff --git a/src/hardware/saleae-logic16/protocol.c b/src/hardware/saleae-logic16/protocol.c index 9e5806e0..3bc7c756 100644 --- a/src/hardware/saleae-logic16/protocol.c +++ b/src/hardware/saleae-logic16/protocol.c @@ -107,7 +107,7 @@ static int do_ep1_command(const struct sr_dev_inst *sdi, usb = sdi->conn; if (cmd_len < 1 || cmd_len > 64 || reply_len > 64 || - command == NULL || (reply_len > 0 && reply == NULL)) + !command || (reply_len > 0 && !reply)) return SR_ERR_ARG; encrypt(buf, command, cmd_len); @@ -165,7 +165,7 @@ static int upload_led_table(const struct sr_dev_inst *sdi, uint8_t chunk, command[64]; int ret; - if (cnt < 1 || cnt + offset > 64 || table == NULL) + if (cnt < 1 || cnt + offset > 64 || !table) return SR_ERR_ARG; while (cnt > 0) { @@ -351,7 +351,7 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi, } sr_info("Uploading FPGA bitstream at %s.", filename); - if ((fw = g_fopen(filename, "rb")) == NULL) { + if (!(fw = g_fopen(filename, "rb"))) { sr_err("Unable to open bitstream file %s for reading: %s.", filename, strerror(errno)); return SR_ERR; diff --git a/src/scpi/scpi_serial.c b/src/scpi/scpi_serial.c index 7f039bf0..de307989 100644 --- a/src/scpi/scpi_serial.c +++ b/src/scpi/scpi_serial.c @@ -54,8 +54,8 @@ static GSList *scpi_serial_scan(struct drv_context *drvc) (void)drvc; for (i = 0; i < ARRAY_SIZE(scpi_serial_usb_ids); i++) { - if ((l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id, - scpi_serial_usb_ids[i].product_id)) == NULL) + if (!(l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id, + scpi_serial_usb_ids[i].product_id))) continue; for (r = l; r; r = r->next) { if (scpi_serial_usb_ids[i].serialcomm) diff --git a/src/scpi/scpi_vxi.c b/src/scpi/scpi_vxi.c index e4efbf1d..e7a4b2b5 100644 --- a/src/scpi/scpi_vxi.c +++ b/src/scpi/scpi_vxi.c @@ -66,7 +66,7 @@ static int scpi_vxi_open(void *priv) Create_LinkResp *link_resp; vxi->client = clnt_create(vxi->address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp"); - if (vxi->client == NULL) { + if (!vxi->client) { sr_err("Client creation failed for %s", vxi->address); return SR_ERR; } diff --git a/src/soft-trigger.c b/src/soft-trigger.c index 27c71b61..9c3963d3 100644 --- a/src/soft-trigger.c +++ b/src/soft-trigger.c @@ -40,7 +40,7 @@ SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new( stl->pre_trigger_buffer = g_malloc(stl->pre_trigger_size); stl->pre_trigger_head = stl->pre_trigger_buffer; - if (stl->pre_trigger_size > 0 && stl->pre_trigger_buffer == NULL) { + if (stl->pre_trigger_size > 0 && !stl->pre_trigger_buffer) { soft_trigger_logic_free(stl); return NULL; } diff --git a/src/strutil.c b/src/strutil.c index 050f37bf..131126b0 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -246,7 +246,7 @@ SR_API char *sr_si_string_u64(uint64_t x, const char *unit) const char *p, prefix[] = "\0kMGTPE"; char fmt[16], fract[20] = "", *f; - if (unit == NULL) + if (!unit) unit = ""; for (i = 0; (quot = x / divisor[i]) >= 1000; i++);