aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/resource.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-04-28 18:34:19 -0400
committerLen Brown <len.brown@intel.com>2008-04-29 03:22:25 -0400
commit30c016a0c8d2aae10be6a87bb98f0e85db8b09d5 (patch)
tree3c76ff434ac96ca0a3948b335b740d8992651b68 /drivers/pnp/resource.c
parent28ccffcf028777e830cbdc30bc54ba8a37e2fc23 (diff)
PNP: reduce redundancy in pnp_check_port() and others
Use a temporary "res" pointer to replace repeated lookups in the pnp resource tables. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Acked-By: Rene Herman <rene.herman@gmail.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp/resource.c')
-rw-r--r--drivers/pnp/resource.c92
1 files changed, 54 insertions, 38 deletions
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 15995f9f8b7c..f89945ebd8b6 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -243,13 +243,15 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
243{ 243{
244 int i; 244 int i;
245 struct pnp_dev *tdev; 245 struct pnp_dev *tdev;
246 struct resource *res, *tres;
246 resource_size_t *port, *end, *tport, *tend; 247 resource_size_t *port, *end, *tport, *tend;
247 248
248 port = &dev->res.port_resource[idx].start; 249 res = &dev->res.port_resource[idx];
249 end = &dev->res.port_resource[idx].end; 250 port = &res->start;
251 end = &res->end;
250 252
251 /* if the resource doesn't exist, don't complain about it */ 253 /* if the resource doesn't exist, don't complain about it */
252 if (cannot_compare(dev->res.port_resource[idx].flags)) 254 if (cannot_compare(res->flags))
253 return 1; 255 return 1;
254 256
255 /* check if the resource is already in use, skip if the 257 /* check if the resource is already in use, skip if the
@@ -269,9 +271,10 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
269 271
270 /* check for internal conflicts */ 272 /* check for internal conflicts */
271 for (i = 0; i < PNP_MAX_PORT && i != idx; i++) { 273 for (i = 0; i < PNP_MAX_PORT && i != idx; i++) {
272 if (dev->res.port_resource[i].flags & IORESOURCE_IO) { 274 tres = &dev->res.port_resource[i];
273 tport = &dev->res.port_resource[i].start; 275 if (tres->flags & IORESOURCE_IO) {
274 tend = &dev->res.port_resource[i].end; 276 tport = &tres->start;
277 tend = &tres->end;
275 if (ranged_conflict(port, end, tport, tend)) 278 if (ranged_conflict(port, end, tport, tend))
276 return 0; 279 return 0;
277 } 280 }
@@ -282,12 +285,12 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
282 if (tdev == dev) 285 if (tdev == dev)
283 continue; 286 continue;
284 for (i = 0; i < PNP_MAX_PORT; i++) { 287 for (i = 0; i < PNP_MAX_PORT; i++) {
285 if (tdev->res.port_resource[i].flags & IORESOURCE_IO) { 288 tres = &tdev->res.port_resource[i];
286 if (cannot_compare 289 if (tres->flags & IORESOURCE_IO) {
287 (tdev->res.port_resource[i].flags)) 290 if (cannot_compare(tres->flags))
288 continue; 291 continue;
289 tport = &tdev->res.port_resource[i].start; 292 tport = &tres->start;
290 tend = &tdev->res.port_resource[i].end; 293 tend = &tres->end;
291 if (ranged_conflict(port, end, tport, tend)) 294 if (ranged_conflict(port, end, tport, tend))
292 return 0; 295 return 0;
293 } 296 }
@@ -301,13 +304,15 @@ int pnp_check_mem(struct pnp_dev *dev, int idx)
301{ 304{
302 int i; 305 int i;
303 struct pnp_dev *tdev; 306 struct pnp_dev *tdev;
307 struct resource *res, *tres;
304 resource_size_t *addr, *end, *taddr, *tend; 308 resource_size_t *addr, *end, *taddr, *tend;
305 309
306 addr = &dev->res.mem_resource[idx].start; 310 res = &dev->res.mem_resource[idx];
307 end = &dev->res.mem_resource[idx].end; 311 addr = &res->start;
312 end = &res->end;
308 313
309 /* if the resource doesn't exist, don't complain about it */ 314 /* if the resource doesn't exist, don't complain about it */
310 if (cannot_compare(dev->res.mem_resource[idx].flags)) 315 if (cannot_compare(res->flags))
311 return 1; 316 return 1;
312 317
313 /* check if the resource is already in use, skip if the 318 /* check if the resource is already in use, skip if the
@@ -327,9 +332,10 @@ int pnp_check_mem(struct pnp_dev *dev, int idx)
327 332
328 /* check for internal conflicts */ 333 /* check for internal conflicts */
329 for (i = 0; i < PNP_MAX_MEM && i != idx; i++) { 334 for (i = 0; i < PNP_MAX_MEM && i != idx; i++) {
330 if (dev->res.mem_resource[i].flags & IORESOURCE_MEM) { 335 tres = &dev->res.mem_resource[i];
331 taddr = &dev->res.mem_resource[i].start; 336 if (tres->flags & IORESOURCE_MEM) {
332 tend = &dev->res.mem_resource[i].end; 337 taddr = &tres->start;
338 tend = &tres->end;
333 if (ranged_conflict(addr, end, taddr, tend)) 339 if (ranged_conflict(addr, end, taddr, tend))
334 return 0; 340 return 0;
335 } 341 }
@@ -340,12 +346,12 @@ int pnp_check_mem(struct pnp_dev *dev, int idx)
340 if (tdev == dev) 346 if (tdev == dev)
341 continue; 347 continue;
342 for (i = 0; i < PNP_MAX_MEM; i++) { 348 for (i = 0; i < PNP_MAX_MEM; i++) {
343 if (tdev->res.mem_resource[i].flags & IORESOURCE_MEM) { 349 tres = &tdev->res.mem_resource[i];
344 if (cannot_compare 350 if (tres->flags & IORESOURCE_MEM) {
345 (tdev->res.mem_resource[i].flags)) 351 if (cannot_compare(tres->flags))
346 continue; 352 continue;
347 taddr = &tdev->res.mem_resource[i].start; 353 taddr = &tres->start;
348 tend = &tdev->res.mem_resource[i].end; 354 tend = &tres->end;
349 if (ranged_conflict(addr, end, taddr, tend)) 355 if (ranged_conflict(addr, end, taddr, tend))
350 return 0; 356 return 0;
351 } 357 }
@@ -364,10 +370,14 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
364{ 370{
365 int i; 371 int i;
366 struct pnp_dev *tdev; 372 struct pnp_dev *tdev;
367 resource_size_t *irq = &dev->res.irq_resource[idx].start; 373 struct resource *res, *tres;
374 resource_size_t *irq;
375
376 res = &dev->res.irq_resource[idx];
377 irq = &res->start;
368 378
369 /* if the resource doesn't exist, don't complain about it */ 379 /* if the resource doesn't exist, don't complain about it */
370 if (cannot_compare(dev->res.irq_resource[idx].flags)) 380 if (cannot_compare(res->flags))
371 return 1; 381 return 1;
372 382
373 /* check if the resource is valid */ 383 /* check if the resource is valid */
@@ -382,8 +392,9 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
382 392
383 /* check for internal conflicts */ 393 /* check for internal conflicts */
384 for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) { 394 for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) {
385 if (dev->res.irq_resource[i].flags & IORESOURCE_IRQ) { 395 tres = &dev->res.irq_resource[i];
386 if (dev->res.irq_resource[i].start == *irq) 396 if (tres->flags & IORESOURCE_IRQ) {
397 if (tres->start == *irq)
387 return 0; 398 return 0;
388 } 399 }
389 } 400 }
@@ -415,11 +426,11 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
415 if (tdev == dev) 426 if (tdev == dev)
416 continue; 427 continue;
417 for (i = 0; i < PNP_MAX_IRQ; i++) { 428 for (i = 0; i < PNP_MAX_IRQ; i++) {
418 if (tdev->res.irq_resource[i].flags & IORESOURCE_IRQ) { 429 tres = &tdev->res.irq_resource[i];
419 if (cannot_compare 430 if (tres->flags & IORESOURCE_IRQ) {
420 (tdev->res.irq_resource[i].flags)) 431 if (cannot_compare(tres->flags))
421 continue; 432 continue;
422 if ((tdev->res.irq_resource[i].start == *irq)) 433 if (tres->start == *irq)
423 return 0; 434 return 0;
424 } 435 }
425 } 436 }
@@ -433,10 +444,14 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
433#ifndef CONFIG_IA64 444#ifndef CONFIG_IA64
434 int i; 445 int i;
435 struct pnp_dev *tdev; 446 struct pnp_dev *tdev;
436 resource_size_t *dma = &dev->res.dma_resource[idx].start; 447 struct resource *res, *tres;
448 resource_size_t *dma;
449
450 res = &dev->res.dma_resource[idx];
451 dma = &res->start;
437 452
438 /* if the resource doesn't exist, don't complain about it */ 453 /* if the resource doesn't exist, don't complain about it */
439 if (cannot_compare(dev->res.dma_resource[idx].flags)) 454 if (cannot_compare(res->flags))
440 return 1; 455 return 1;
441 456
442 /* check if the resource is valid */ 457 /* check if the resource is valid */
@@ -451,8 +466,9 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
451 466
452 /* check for internal conflicts */ 467 /* check for internal conflicts */
453 for (i = 0; i < PNP_MAX_DMA && i != idx; i++) { 468 for (i = 0; i < PNP_MAX_DMA && i != idx; i++) {
454 if (dev->res.dma_resource[i].flags & IORESOURCE_DMA) { 469 tres = &dev->res.dma_resource[i];
455 if (dev->res.dma_resource[i].start == *dma) 470 if (tres->flags & IORESOURCE_DMA) {
471 if (tres->start == *dma)
456 return 0; 472 return 0;
457 } 473 }
458 } 474 }
@@ -470,11 +486,11 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
470 if (tdev == dev) 486 if (tdev == dev)
471 continue; 487 continue;
472 for (i = 0; i < PNP_MAX_DMA; i++) { 488 for (i = 0; i < PNP_MAX_DMA; i++) {
473 if (tdev->res.dma_resource[i].flags & IORESOURCE_DMA) { 489 tres = &tdev->res.dma_resource[i];
474 if (cannot_compare 490 if (tres->flags & IORESOURCE_DMA) {
475 (tdev->res.dma_resource[i].flags)) 491 if (cannot_compare(tres->flags))
476 continue; 492 continue;
477 if ((tdev->res.dma_resource[i].start == *dma)) 493 if (tres->start == *dma)
478 return 0; 494 return 0;
479 } 495 }
480 } 496 }