aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/support.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-07-31 03:07:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-08-01 15:46:41 -0400
commitea44c1d60df3640bd956a67c392865c44fe9bc45 (patch)
treea419febccc84cf70c36704f1a444c2c34bda05d7 /drivers/pnp/support.c
parent61a2d07d3fb1ac34d142b9b62d4cd60a0f8c229e (diff)
PNP: fix formatting of dbg_pnp_show_resources() output
Each resource should be printed on its own line, so start snprintf'ing at the beginning of the buffer every time through the loop. Also, use scnprintf() rather than snprintf() when building up the buffer to print. scnprintf() returns the number of characters actually written into the buffer (not including the trailing NULL). snprintf() returns the number of characters that *would be* written, assuming everything would fit in the buffer. That's nice if we want to resize the buffer to make sure everything fits, but in this case, I just want to keep from overflowing the buffer, and it's OK if the output is truncated. Using snprintf() meant that my "len" could grow to be more than the the buffer size, which makes "sizeof(buf) - len" negative, which causes this alarming WARN_ON: http://marc.info/?l=linux-kernel&m=121736480005656&w=2 More useful snprintf/scnprintf discussion: http://lwn.net/Articles/69419/ Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Reported-by: Pete Clements <clem@clem.clem-digital.net> Cc: Rene Herman <rene.herman@keyaccess.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/pnp/support.c')
-rw-r--r--drivers/pnp/support.c96
1 files changed, 49 insertions, 47 deletions
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c
index bbf78ef4ba02..b42df1620718 100644
--- a/drivers/pnp/support.c
+++ b/drivers/pnp/support.c
@@ -77,7 +77,7 @@ void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
77{ 77{
78#ifdef DEBUG 78#ifdef DEBUG
79 char buf[128]; 79 char buf[128];
80 int len = 0; 80 int len;
81 struct pnp_resource *pnp_res; 81 struct pnp_resource *pnp_res;
82 struct resource *res; 82 struct resource *res;
83 83
@@ -89,9 +89,10 @@ void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
89 dev_dbg(&dev->dev, "%s: current resources:\n", desc); 89 dev_dbg(&dev->dev, "%s: current resources:\n", desc);
90 list_for_each_entry(pnp_res, &dev->resources, list) { 90 list_for_each_entry(pnp_res, &dev->resources, list) {
91 res = &pnp_res->res; 91 res = &pnp_res->res;
92 len = 0;
92 93
93 len += snprintf(buf + len, sizeof(buf) - len, " %-3s ", 94 len += scnprintf(buf + len, sizeof(buf) - len, " %-3s ",
94 pnp_resource_type_name(res)); 95 pnp_resource_type_name(res));
95 96
96 if (res->flags & IORESOURCE_DISABLED) { 97 if (res->flags & IORESOURCE_DISABLED) {
97 dev_dbg(&dev->dev, "%sdisabled\n", buf); 98 dev_dbg(&dev->dev, "%sdisabled\n", buf);
@@ -101,18 +102,18 @@ void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
101 switch (pnp_resource_type(res)) { 102 switch (pnp_resource_type(res)) {
102 case IORESOURCE_IO: 103 case IORESOURCE_IO:
103 case IORESOURCE_MEM: 104 case IORESOURCE_MEM:
104 len += snprintf(buf + len, sizeof(buf) - len, 105 len += scnprintf(buf + len, sizeof(buf) - len,
105 "%#llx-%#llx flags %#lx", 106 "%#llx-%#llx flags %#lx",
106 (unsigned long long) res->start, 107 (unsigned long long) res->start,
107 (unsigned long long) res->end, 108 (unsigned long long) res->end,
108 res->flags); 109 res->flags);
109 break; 110 break;
110 case IORESOURCE_IRQ: 111 case IORESOURCE_IRQ:
111 case IORESOURCE_DMA: 112 case IORESOURCE_DMA:
112 len += snprintf(buf + len, sizeof(buf) - len, 113 len += scnprintf(buf + len, sizeof(buf) - len,
113 "%lld flags %#lx", 114 "%lld flags %#lx",
114 (unsigned long long) res->start, 115 (unsigned long long) res->start,
115 res->flags); 116 res->flags);
116 break; 117 break;
117 } 118 }
118 dev_dbg(&dev->dev, "%s\n", buf); 119 dev_dbg(&dev->dev, "%s\n", buf);
@@ -144,66 +145,67 @@ void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option)
144 struct pnp_dma *dma; 145 struct pnp_dma *dma;
145 146
146 if (pnp_option_is_dependent(option)) 147 if (pnp_option_is_dependent(option))
147 len += snprintf(buf + len, sizeof(buf) - len, 148 len += scnprintf(buf + len, sizeof(buf) - len,
148 " dependent set %d (%s) ", 149 " dependent set %d (%s) ",
149 pnp_option_set(option), 150 pnp_option_set(option),
150 pnp_option_priority_name(option)); 151 pnp_option_priority_name(option));
151 else 152 else
152 len += snprintf(buf + len, sizeof(buf) - len, " independent "); 153 len += scnprintf(buf + len, sizeof(buf) - len,
154 " independent ");
153 155
154 switch (option->type) { 156 switch (option->type) {
155 case IORESOURCE_IO: 157 case IORESOURCE_IO:
156 port = &option->u.port; 158 port = &option->u.port;
157 len += snprintf(buf + len, sizeof(buf) - len, "io min %#llx " 159 len += scnprintf(buf + len, sizeof(buf) - len, "io min %#llx "
158 "max %#llx align %lld size %lld flags %#x", 160 "max %#llx align %lld size %lld flags %#x",
159 (unsigned long long) port->min, 161 (unsigned long long) port->min,
160 (unsigned long long) port->max, 162 (unsigned long long) port->max,
161 (unsigned long long) port->align, 163 (unsigned long long) port->align,
162 (unsigned long long) port->size, port->flags); 164 (unsigned long long) port->size, port->flags);
163 break; 165 break;
164 case IORESOURCE_MEM: 166 case IORESOURCE_MEM:
165 mem = &option->u.mem; 167 mem = &option->u.mem;
166 len += snprintf(buf + len, sizeof(buf) - len, "mem min %#llx " 168 len += scnprintf(buf + len, sizeof(buf) - len, "mem min %#llx "
167 "max %#llx align %lld size %lld flags %#x", 169 "max %#llx align %lld size %lld flags %#x",
168 (unsigned long long) mem->min, 170 (unsigned long long) mem->min,
169 (unsigned long long) mem->max, 171 (unsigned long long) mem->max,
170 (unsigned long long) mem->align, 172 (unsigned long long) mem->align,
171 (unsigned long long) mem->size, mem->flags); 173 (unsigned long long) mem->size, mem->flags);
172 break; 174 break;
173 case IORESOURCE_IRQ: 175 case IORESOURCE_IRQ:
174 irq = &option->u.irq; 176 irq = &option->u.irq;
175 len += snprintf(buf + len, sizeof(buf) - len, "irq"); 177 len += scnprintf(buf + len, sizeof(buf) - len, "irq");
176 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR)) 178 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
177 len += snprintf(buf + len, sizeof(buf) - len, 179 len += scnprintf(buf + len, sizeof(buf) - len,
178 " <none>"); 180 " <none>");
179 else { 181 else {
180 for (i = 0; i < PNP_IRQ_NR; i++) 182 for (i = 0; i < PNP_IRQ_NR; i++)
181 if (test_bit(i, irq->map.bits)) 183 if (test_bit(i, irq->map.bits))
182 len += snprintf(buf + len, 184 len += scnprintf(buf + len,
183 sizeof(buf) - len, 185 sizeof(buf) - len,
184 " %d", i); 186 " %d", i);
185 } 187 }
186 len += snprintf(buf + len, sizeof(buf) - len, " flags %#x", 188 len += scnprintf(buf + len, sizeof(buf) - len, " flags %#x",
187 irq->flags); 189 irq->flags);
188 if (irq->flags & IORESOURCE_IRQ_OPTIONAL) 190 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
189 len += snprintf(buf + len, sizeof(buf) - len, 191 len += scnprintf(buf + len, sizeof(buf) - len,
190 " (optional)"); 192 " (optional)");
191 break; 193 break;
192 case IORESOURCE_DMA: 194 case IORESOURCE_DMA:
193 dma = &option->u.dma; 195 dma = &option->u.dma;
194 len += snprintf(buf + len, sizeof(buf) - len, "dma"); 196 len += scnprintf(buf + len, sizeof(buf) - len, "dma");
195 if (!dma->map) 197 if (!dma->map)
196 len += snprintf(buf + len, sizeof(buf) - len, 198 len += scnprintf(buf + len, sizeof(buf) - len,
197 " <none>"); 199 " <none>");
198 else { 200 else {
199 for (i = 0; i < 8; i++) 201 for (i = 0; i < 8; i++)
200 if (dma->map & (1 << i)) 202 if (dma->map & (1 << i))
201 len += snprintf(buf + len, 203 len += scnprintf(buf + len,
202 sizeof(buf) - len, 204 sizeof(buf) - len,
203 " %d", i); 205 " %d", i);
204 } 206 }
205 len += snprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) " 207 len += scnprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) "
206 "flags %#x", dma->map, dma->flags); 208 "flags %#x", dma->map, dma->flags);
207 break; 209 break;
208 } 210 }
209 dev_dbg(&dev->dev, "%s\n", buf); 211 dev_dbg(&dev->dev, "%s\n", buf);