flash/nor/at91samd: Use 32-bit register writes for ST-Link compat
[fw/openocd] / src / jtag / drivers / cmsis_dap_usb_bulk.c
index c42bab28f5301559e193cdf0d86a273f87fbac10..a738200ea57d878bd35f5ef25c6e873edc24ef19 100644 (file)
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2018 by MickaĆ«l Thomas                                  *
  *   mickael9@gmail.com                                                    *
  *                                                                         *
  *   Copyright (C) 2013 by Spencer Oliver                                  *
  *   spen@spen-soft.co.uk                                                  *
- *                                                                         *
- *   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
@@ -55,7 +44,7 @@ static int cmsis_dap_usb_interface = -1;
 static void cmsis_dap_usb_close(struct cmsis_dap *dap);
 static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz);
 
-static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], char *serial)
+static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial)
 {
        int err;
        struct libusb_context *ctx;
@@ -353,7 +342,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
                                LOG_WARNING("could not claim interface: %s", libusb_strerror(err));
 
                        dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
-                       if (dap->bdata == NULL) {
+                       if (!dap->bdata) {
                                LOG_ERROR("unable to allocate memory");
                                libusb_release_interface(dev_handle, interface_num);
                                libusb_close(dev_handle);
@@ -370,7 +359,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
                        dap->bdata->interface = interface_num;
 
                        dap->packet_buffer = malloc(dap->packet_buffer_size);
-                       if (dap->packet_buffer == NULL) {
+                       if (!dap->packet_buffer) {
                                LOG_ERROR("unable to allocate memory");
                                cmsis_dap_usb_close(dap);
                                return ERROR_FAIL;
@@ -446,7 +435,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
 static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
 {
        uint8_t *buf = malloc(pkt_sz);
-       if (buf == NULL) {
+       if (!buf) {
                LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
                return ERROR_FAIL;
        }
@@ -464,7 +453,7 @@ static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
 COMMAND_HANDLER(cmsis_dap_handle_usb_interface_command)
 {
        if (CMD_ARGC == 1)
-               cmsis_dap_usb_interface = strtoul(CMD_ARGV[0], NULL, 10);
+               COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], cmsis_dap_usb_interface);
        else
                LOG_ERROR("expected exactly one argument to cmsis_dap_usb_interface <interface_number>");