2 * SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2018 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
6 #include <helper/log.h>
8 #include "jtag_usb_common.h"
10 static char *jtag_usb_location;
13 * 2 * 7 chars: max 7 ports
14 * 1 char: test for overflow
18 #define JTAG_USB_MAX_LOCATION_LENGHT 16
20 void jtag_usb_set_location(const char *location)
22 if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGHT) ==
23 JTAG_USB_MAX_LOCATION_LENGHT)
24 LOG_WARNING("usb location string is too long!!\n");
26 if (jtag_usb_location)
27 free(jtag_usb_location);
29 jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGHT);
32 const char *jtag_usb_get_location(void)
34 return jtag_usb_location;
37 bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path,
40 size_t path_step, string_lengh;
44 /* strtok need non const char */
45 loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGHT);
46 string_lengh = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT);
48 ptr = strtok(loc, "-");
50 LOG_WARNING("no '-' in usb path\n");
55 /* check bus mismatch */
56 if (atoi(ptr) != dev_bus)
60 while (path_step < path_len) {
61 ptr = strtok(NULL, ".");
63 /* no more tokens in path */
67 /* path mismatch at some step */
68 if (path_step < path_len && atoi(ptr) != port_path[path_step])
75 /* walked the full path, all elements match */
76 if (path_step == path_len && !string_lengh)
79 LOG_WARNING("excluded by device path option: %s\n",
80 jtag_usb_get_location());