/* * gpio-event-mon - monitor GPIO line events from userspace * * Copyright (C) 2016 Linus Walleij * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. * * Usage: * gpio-event-mon -n -o */ #include #include #include #include #include #include #include #include #include #include #include #include #include int monitor_device(const char *device_name, unsigned int line, u_int32_t handleflags, u_int32_t eventflags, unsigned int loops) { struct gpioevent_request req; struct gpiohandle_data data; char *chrdev_name; int fd; int ret; int i = 0; ret = asprintf(&chrdev_name, "/dev/%s", device_name); if (ret < 0) return -ENOMEM; fd = open(chrdev_name, 0); if (fd == -1) { ret = -errno; fprintf(stderr, "Failed to open %s\n", chrdev_name); goto exit_close_error; } req.lineoffset = line; req.handleflags = handleflags; req.eventflags = eventflags; strcpy(req.consumer_label, "gpio-event-mon"); ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &req); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET EVENT " "IOCTL (%d)\n", ret); goto exit_close_error; } /* Read initial states */ ret = ioctl(req.fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE " "VALUES IOCTL (%d)\n", ret); goto exit_close_error; } fprintf(stdout, "Monitoring line %d on %s\n", line, device_name); fprintf(stdout, "Initial line value: %d\n", data.values[0]); while (1) { struct gpioevent_data event; ret = read(req.fd, &event, sizeof(event)); if (ret == -1) { if (errno == -EAGAIN) { fprintf(stderr, "nothing available\n"); continue; } else { ret = -errno; fprintf(stderr, "Failed to read event (%d)\n", ret); break; } } if (ret != sizeof(event)) { fprintf(stderr, "Reading event failed\n"); ret = -EIO; break; } fprintf(stdout, "GPIO EVENT %" PRIu64 ": ", event.timestamp); switch (event.id) { case GPIOEVENT_EVENT_RISING_EDGE: fprintf(stdout, "rising edge"); break; case GPIOEVENT_EVENT_FALLING_EDGE: fprintf(stdout, "falling edge"); break; default: fprintf(stdout, "unknown event"); } fprintf(stdout, "\n"); i++; if (i == loops) break; } exit_close_error: if (close(fd) == -1) perror("Failed to close GPIO character device file"); free(chrdev_name); return ret; } void print_usage(void) { fprintf(stderr, "Usage: gpio-event-mon [options]...\n" "Listen to events on GPIO lines, 0->1 1->0\n" " -n Listen on GPIOs on a named device (must be stated)\n" " -o Offset to monitor\n" " -d Set line as open drain\n" " -s Set line as open source\n" " -r Listen for rising edges\n" " -f Listen for falling edges\n" " [-c ] Do loops (optional, infinite loop if not stated)\n" " -? This helptext\n" "\n" "Example:\n" "gpio-event-mon -n gpiochip0 -o 4 -r -f\n" ); } int main(int argc, char **argv) { const char *device_name = NULL; unsigned int line = -1; unsigned int loops = 0; u_int32_t handleflags = GPIOHANDLE_REQUEST_INPUT; u_int32_t eventflags = 0; int c; while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) { switch (c) { case 'c': loops = strtoul(optarg, NULL, 10); break; case 'n': device_name = optarg; break; case 'o': line = strtoul(optarg, NULL, 10); break; case 'd': handleflags |= GPIOHANDLE_REQUEST_OPEN_DRAIN; break; case 's': handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; break; case 'r': eventflags |= GPIOEVENT_REQUEST_RISING_EDGE; break; case 'f': eventflags |= GPIOEVENT_REQUEST_FALLING_EDGE; break; case '?': print_usage(); return -1; } } if (!device_name || line == -1) { print_usage(); return -1; } if (!eventflags) { printf("No flags specified, listening on both rising and " "falling edges\n"); eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; } return monitor_device(device_name, line, handleflags, eventflags, loops); } ct>mode:
authorBjorn Helgaas <bhelgaas@google.com>2017-01-27 15:00:45 -0600
committerBjorn Helgaas <bhelgaas@google.com>2017-01-27 15:00:45 -0600
commit030305d69fc6963c16003f50d7e8d74b02d0a143 (patch)
tree363a4e34d199178769b7e7eeb26ea2620a55847b /include/uapi/scsi/fc/fc_ns.h
parent4d191b1b63c209e37bf27938ef365244d3c41084 (diff)
PCI/ASPM: Handle PCI-to-PCIe bridges as roots of PCIe hierarchies
In a struct pcie_link_state, link->root points to the pcie_link_state of the root of the PCIe hierarchy. For the topmost link, this points to itself (link->root = link). For others, we copy the pointer from the parent (link->root = link->parent->root). Previously we recognized that Root Ports originated PCIe hierarchies, but we treated PCI/PCI-X to PCIe Bridges as being in the middle of the hierarchy, and when we tried to copy the pointer from link->parent->root, there was no parent, and we dereferenced a NULL pointer: BUG: unable to handle kernel NULL pointer dereference at 0000000000000090 IP: [<ffffffff9e424350>] pcie_aspm_init_link_state+0x170/0x820 Recognize that PCI/PCI-X to PCIe Bridges originate PCIe hierarchies just like Root Ports do, so link->root for these devices should also point to itself. Fixes: 51ebfc92b72b ("PCI: Enumerate switches below PCI-to-PCIe bridges") Link: https://bugzilla.kernel.org/show_bug.cgi?id=193411 Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1022181 Tested-by: lists@ssl-mail.com Tested-by: Jayachandran C. <jnair@caviumnetworks.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> CC: stable@vger.kernel.org # v4.2+
Diffstat (limited to 'include/uapi/scsi/fc/fc_ns.h')