+// SPDX-License-Identifier: GPL-2.0-or-later
+
/***************************************************************************
* Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
.ep_out = VERSALOON_OUTP,
.ep_in = VERSALOON_INP,
.interface = VERSALOON_IFACE,
- .serialstring = NULL,
.buf_size = 256,
}
};
struct versaloon_want_pos_t *tmp, *free_tmp;
tmp = versaloon_want_pos;
- while (tmp != NULL) {
+ while (tmp) {
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) {
tmp = versaloon_pending[i].pos;
- while (tmp != NULL) {
+ while (tmp) {
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
struct versaloon_want_pos_t *new_pos = NULL;
new_pos = malloc(sizeof(*new_pos));
- if (NULL == new_pos) {
+ if (!new_pos) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
new_pos->buff = buff;
new_pos->next = NULL;
- if (NULL == versaloon_want_pos)
+ if (!versaloon_want_pos)
versaloon_want_pos = new_pos;
else {
struct versaloon_want_pos_t *tmp = versaloon_want_pos;
- while (tmp->next != NULL)
+ while (tmp->next)
tmp = tmp->next;
tmp->next = new_pos;
}
int transferred;
#if PARAM_CHECK
- if (NULL == versaloon_buf) {
+ if (!versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
- if ((0 == out_len) || (out_len > versaloon_interface.usb_setting.buf_size)) {
+ if ((out_len == 0) || (out_len > versaloon_interface.usb_setting.buf_size)) {
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
return ERRCODE_INVALID_PARAMETER;
}
ret = libusb_bulk_transfer(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_out,
versaloon_buf, out_len, &transferred, versaloon_usb_to);
- if (0 != ret || transferred != out_len) {
+ if (ret != 0 || transferred != out_len) {
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "send usb data");
return ERRCODE_FAILURE_OPERATION;
}
- if (inlen != NULL) {
+ if (inlen) {
ret = libusb_bulk_transfer(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_in,
versaloon_buf, versaloon_interface.usb_setting.buf_size,
&transferred, versaloon_usb_to);
- if (0 == ret) {
+ if (ret == 0) {
*inlen = (uint16_t)transferred;
return ERROR_OK;
} else {
/* malloc temporary buffer */
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
- if (NULL == versaloon_buf) {
+ if (!versaloon_buf) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
versaloon_usb_to = 100;
for (retry = 0; retry < VERSALOON_RETRY_CNT; retry++) {
versaloon_buf[0] = VERSALOON_GET_INFO;
- if ((ERROR_OK == versaloon_send_command(1, &ret)) && (ret >= 3))
+ if ((versaloon_send_command(1, &ret) == ERROR_OK) && (ret >= 3))
break;
}
versaloon_usb_to = timeout_tmp;
versaloon_buf = NULL;
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
- if (NULL == versaloon_buf) {
+ if (!versaloon_buf) {
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
- if (NULL == versaloon_cmd_buf) {
+ if (!versaloon_cmd_buf) {
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
- if (ERROR_OK != usbtoxxx_init()) {
+ if (usbtoxxx_init() != ERROR_OK) {
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "initialize usbtoxxx");
return ERROR_FAIL;
}
static RESULT versaloon_fini(void)
{
- if (versaloon_usb_device_handle != NULL) {
+ if (versaloon_usb_device_handle) {
usbtoxxx_fini();
versaloon_free_want_pos();
uint16_t inlen;
#if PARAM_CHECK
- if (NULL == versaloon_buf) {
+ if (!versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
- if (NULL == voltage) {
+ if (!voltage) {
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
return ERRCODE_INVALID_PARAMETER;
}
versaloon_buf[0] = VERSALOON_GET_TVCC;
- if ((ERROR_OK != versaloon_send_command(1, &inlen)) || (inlen != 2)) {
+ if ((versaloon_send_command(1, &inlen) != ERROR_OK) || (inlen != 2)) {
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon");
return ERRCODE_FAILURE_OPERATION;
} else {