diff options
author | Guenter Roeck <linux@roeck-us.net> | 2017-12-24 16:04:10 -0500 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2018-01-21 06:56:35 -0500 |
commit | e189410cbef1374ec29d42b72df0d58d5c7e193c (patch) | |
tree | 22b1781ed0a8edc5643ff14ba486b22c5e7b2c11 | |
parent | 23dfe140057baa165daebadf8f4600e3603e0954 (diff) |
watchdog: sp5100_tco: Clean up sp5100_tco_setupdevice
There are too many unnecessary goto statements in sp5100_tco_setupdevice().
Rearrange the code and limit goto statements to error handling.
Cc: Zoltán Böszörményi <zboszor@pr.hu>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
-rw-r--r-- | drivers/watchdog/sp5100_tco.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index 0e816f2cdb07..5a13ab483c50 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c | |||
@@ -396,48 +396,44 @@ static int sp5100_tco_setupdevice(void) | |||
396 | pr_debug("Got 0x%04x from indirect I/O\n", val); | 396 | pr_debug("Got 0x%04x from indirect I/O\n", val); |
397 | 397 | ||
398 | /* Check MMIO address conflict */ | 398 | /* Check MMIO address conflict */ |
399 | if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE, | 399 | if (!request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE, |
400 | dev_name)) | 400 | dev_name)) { |
401 | goto setup_wdt; | ||
402 | else | ||
403 | pr_debug("MMIO address 0x%04x already in use\n", val); | 401 | pr_debug("MMIO address 0x%04x already in use\n", val); |
402 | /* | ||
403 | * Secondly, Find the watchdog timer MMIO address | ||
404 | * from SBResource_MMIO register. | ||
405 | */ | ||
406 | if (tco_has_sp5100_reg_layout(sp5100_tco_pci)) { | ||
407 | /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */ | ||
408 | pci_read_config_dword(sp5100_tco_pci, | ||
409 | SP5100_SB_RESOURCE_MMIO_BASE, | ||
410 | &val); | ||
411 | } else { | ||
412 | /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ | ||
413 | val = sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN); | ||
414 | } | ||
404 | 415 | ||
405 | /* | 416 | /* The SBResource_MMIO is enabled and mapped memory space? */ |
406 | * Secondly, Find the watchdog timer MMIO address | 417 | if ((val & (SB800_ACPI_MMIO_DECODE_EN | SB800_ACPI_MMIO_SEL)) != |
407 | * from SBResource_MMIO register. | ||
408 | */ | ||
409 | if (tco_has_sp5100_reg_layout(sp5100_tco_pci)) { | ||
410 | /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */ | ||
411 | pci_read_config_dword(sp5100_tco_pci, | ||
412 | SP5100_SB_RESOURCE_MMIO_BASE, &val); | ||
413 | } else { | ||
414 | /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ | ||
415 | val = sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN); | ||
416 | } | ||
417 | |||
418 | /* The SBResource_MMIO is enabled and mapped memory space? */ | ||
419 | if ((val & (SB800_ACPI_MMIO_DECODE_EN | SB800_ACPI_MMIO_SEL)) == | ||
420 | SB800_ACPI_MMIO_DECODE_EN) { | 418 | SB800_ACPI_MMIO_DECODE_EN) { |
419 | pr_notice("failed to find MMIO address, giving up.\n"); | ||
420 | ret = -ENODEV; | ||
421 | goto unreg_region; | ||
422 | } | ||
421 | /* Clear unnecessary the low twelve bits */ | 423 | /* Clear unnecessary the low twelve bits */ |
422 | val &= ~0xFFF; | 424 | val &= ~0xFFF; |
423 | /* Add the Watchdog Timer offset to base address. */ | 425 | /* Add the Watchdog Timer offset to base address. */ |
424 | val += SB800_PM_WDT_MMIO_OFFSET; | 426 | val += SB800_PM_WDT_MMIO_OFFSET; |
425 | /* Check MMIO address conflict */ | 427 | /* Check MMIO address conflict */ |
426 | if (request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE, | 428 | if (!request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE, |
427 | dev_name)) { | 429 | dev_name)) { |
428 | pr_debug("Got 0x%04x from SBResource_MMIO register\n", | ||
429 | val); | ||
430 | goto setup_wdt; | ||
431 | } else | ||
432 | pr_debug("MMIO address 0x%04x already in use\n", val); | 430 | pr_debug("MMIO address 0x%04x already in use\n", val); |
433 | } else | 431 | ret = -EBUSY; |
434 | pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val); | 432 | goto unreg_region; |
435 | 433 | } | |
436 | pr_notice("failed to find MMIO address, giving up.\n"); | 434 | pr_debug("Got 0x%04x from SBResource_MMIO register\n", val); |
437 | ret = -ENODEV; | 435 | } |
438 | goto unreg_region; | ||
439 | 436 | ||
440 | setup_wdt: | ||
441 | tcobase_phys = val; | 437 | tcobase_phys = val; |
442 | 438 | ||
443 | tcobase = ioremap(val, SP5100_WDT_MEM_MAP_SIZE); | 439 | tcobase = ioremap(val, SP5100_WDT_MEM_MAP_SIZE); |
@@ -472,7 +468,7 @@ setup_wdt: | |||
472 | tco_timer_stop(); | 468 | tco_timer_stop(); |
473 | 469 | ||
474 | release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); | 470 | release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); |
475 | /* Done */ | 471 | |
476 | return 0; | 472 | return 0; |
477 | 473 | ||
478 | unreg_mem_region: | 474 | unreg_mem_region: |