ia64/linux-2.6.18-xen.hg

annotate drivers/pci/reserve.c @ 895:20be7f6d414a

pci/guestdev, iomul: use strlcpy()

use strlcpy() to make them robust.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:45:49 2009 +0100 (2009-06-04)
parents c7c92f868aa1
children
rev   line source
keir@884 1 /*
keir@884 2 * This program is free software; you can redistribute it and/or modify
keir@884 3 * it under the terms of the GNU General Public License as published by
keir@884 4 * the Free Software Foundation; either version 2 of the License, or
keir@884 5 * (at your option) any later version.
keir@884 6 *
keir@884 7 * This program is distributed in the hope that it will be useful,
keir@884 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
keir@884 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
keir@884 10 * GNU General Public License for more details.
keir@884 11 *
keir@884 12 * You should have received a copy of the GNU General Public License
keir@884 13 * along with this program; if not, write to the Free Software
keir@884 14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
keir@884 15 *
keir@884 16 * Copyright (c) 2009 Isaku Yamahata
keir@884 17 * VA Linux Systems Japan K.K.
keir@884 18 *
keir@884 19 */
keir@884 20
keir@884 21 #include <linux/kernel.h>
keir@884 22 #include <linux/pci.h>
keir@884 23
keir@884 24 #include <asm/setup.h>
keir@884 25
keir@884 26 static char pci_reserve_param[COMMAND_LINE_SIZE];
keir@884 27
keir@884 28 /* pci_reserve= [PCI]
keir@884 29 * Format: [<sbdf>[+IO<size>][+MEM<size>]][,<sbdf>...]
keir@884 30 * Format of sbdf: [<segment>:]<bus>:<dev>.<func>
keir@884 31 */
keir@884 32 static int pci_reserve_parse_size(const char *str,
keir@884 33 unsigned long *io_size,
keir@884 34 unsigned long *mem_size)
keir@884 35 {
keir@884 36 if (sscanf(str, "io%lx", io_size) == 1 ||
keir@884 37 sscanf(str, "IO%lx", io_size) == 1)
keir@884 38 return 0;
keir@884 39
keir@884 40 if (sscanf(str, "mem%lx", mem_size) == 1 ||
keir@884 41 sscanf(str, "MEM%lx", mem_size) == 1)
keir@884 42 return 0;
keir@884 43
keir@884 44 return -EINVAL;
keir@884 45 }
keir@884 46
keir@884 47 static int pci_reserve_parse_one(const char *str,
keir@884 48 int *seg, int *bus, int *dev, int *func,
keir@884 49 unsigned long *io_size,
keir@884 50 unsigned long *mem_size)
keir@884 51 {
keir@884 52 char *p;
keir@884 53
keir@884 54 *io_size = 0;
keir@884 55 *mem_size = 0;
keir@884 56
keir@884 57 if (sscanf(str, "%x:%x:%x.%x", seg, bus, dev, func) != 4) {
keir@884 58 *seg = 0;
keir@884 59 if (sscanf(str, "%x:%x.%x", bus, dev, func) != 3) {
keir@884 60 return -EINVAL;
keir@884 61 }
keir@884 62 }
keir@884 63
keir@884 64 p = strchr(str, '+');
keir@884 65 if (p == NULL)
keir@884 66 return -EINVAL;
keir@884 67 p++;
keir@884 68 if (pci_reserve_parse_size(p, io_size, mem_size))
keir@884 69 return -EINVAL;
keir@884 70
keir@884 71 p = strchr(str, '+');
keir@884 72 if (p != NULL) {
keir@884 73 p++;
keir@884 74 pci_reserve_parse_size(p, io_size, mem_size);
keir@884 75 }
keir@884 76 return 0;
keir@884 77 }
keir@884 78
keir@884 79 static unsigned long pci_reserve_size(struct pci_bus *pbus, int flags)
keir@884 80 {
keir@884 81 char *sp;
keir@884 82 char *ep;
keir@884 83
keir@884 84 int seg;
keir@884 85 int bus;
keir@884 86 int dev;
keir@884 87 int func;
keir@884 88
keir@884 89 unsigned long io_size;
keir@884 90 unsigned long mem_size;
keir@884 91
keir@884 92 sp = pci_reserve_param;
keir@884 93
keir@884 94 do {
keir@884 95 ep = strchr(sp, ',');
keir@884 96 if (ep)
keir@884 97 *ep = '\0'; /* chomp */
keir@884 98
keir@884 99 if (pci_reserve_parse_one(sp, &seg, &bus, &dev, &func,
keir@884 100 &io_size, &mem_size) == 0) {
keir@884 101 if (pci_domain_nr(pbus) == seg &&
keir@884 102 pbus->number == bus &&
keir@884 103 PCI_SLOT(pbus->self->devfn) == dev &&
keir@884 104 PCI_FUNC(pbus->self->devfn) == func) {
keir@884 105 switch (flags) {
keir@884 106 case IORESOURCE_IO:
keir@884 107 return io_size;
keir@884 108 case IORESOURCE_MEM:
keir@884 109 return mem_size;
keir@884 110 default:
keir@884 111 break;
keir@884 112 }
keir@884 113 }
keir@884 114 }
keir@884 115
keir@884 116 if (ep) {
keir@884 117 *ep = ','; /* restore chomp'ed ',' for later */
keir@884 118 ep++;
keir@884 119 }
keir@884 120 sp = ep;
keir@884 121 } while (ep);
keir@884 122
keir@884 123 return 0;
keir@884 124 }
keir@884 125
keir@884 126 unsigned long pci_reserve_size_io(struct pci_bus *pbus)
keir@884 127 {
keir@884 128 return pci_reserve_size(pbus, IORESOURCE_IO);
keir@884 129 }
keir@884 130
keir@884 131 unsigned long pci_reserve_size_mem(struct pci_bus *pbus)
keir@884 132 {
keir@884 133 return pci_reserve_size(pbus, IORESOURCE_MEM);
keir@884 134 }
keir@884 135
keir@884 136 static int __init pci_reserve_setup(char *str)
keir@884 137 {
keir@895 138 if (strlen(str) >= sizeof(pci_reserve_param))
keir@884 139 return 0;
keir@895 140 strlcpy(pci_reserve_param, str, sizeof(pci_reserve_param));
keir@884 141 return 1;
keir@884 142 }
keir@884 143 __setup("pci_reserve=", pci_reserve_setup);