Skip to content

Commit 05440df

Browse files
David BrownellLinus Torvalds
authored andcommitted
rtc-cmos probe() cleanup
Some cleanups for the rtc-cmos probe logic: - Claim i/o ports with request_region() not request_resource(), for better coexistence betwen platform and pnp bus glues. - Claim those ports earlier, to help work around procfs bugs (it allows duplicate names, like /proc/driver/rtc). - Fix some glitches in cleanup code, notably a cut'n'paste-o where the i/o port region might not get released during cleanup after a probe fault. And some comment clarifications, including noting that this code must work with PNPBIOS not just PNPACPI.. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0e36a9a commit 05440df

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

‎drivers/rtc/rtc-cmos.c‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
433433
if (!ports)
434434
return -ENODEV;
435435

436+
/* Claim I/O ports ASAP, minimizing conflict with legacy driver.
437+
*
438+
* REVISIT non-x86 systems may instead use memory space resources
439+
* (needing ioremap etc), not i/o space resources like this ...
440+
*/
441+
ports = request_region(ports->start,
442+
ports->end + 1 - ports->start,
443+
driver_name);
444+
if (!ports) {
445+
dev_dbg(dev, "i/o registers already in use\n");
446+
return -EBUSY;
447+
}
448+
436449
cmos_rtc.irq = rtc_irq;
437450
cmos_rtc.iomem = ports;
438451

@@ -454,24 +467,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
454467

455468
cmos_rtc.rtc = rtc_device_register(driver_name, dev,
456469
&cmos_rtc_ops, THIS_MODULE);
457-
if (IS_ERR(cmos_rtc.rtc))
458-
return PTR_ERR(cmos_rtc.rtc);
470+
if (IS_ERR(cmos_rtc.rtc)) {
471+
retval = PTR_ERR(cmos_rtc.rtc);
472+
goto cleanup0;
473+
}
459474

460475
cmos_rtc.dev = dev;
461476
dev_set_drvdata(dev, &cmos_rtc);
462-
463-
/* platform and pnp busses handle resources incompatibly.
464-
*
465-
* REVISIT for non-x86 systems we may need to handle io memory
466-
* resources: ioremap them, and request_mem_region().
467-
*/
468-
if (is_pnp()) {
469-
retval = request_resource(&ioport_resource, ports);
470-
if (retval < 0) {
471-
dev_dbg(dev, "i/o registers already in use\n");
472-
goto cleanup0;
473-
}
474-
}
475477
rename_region(ports, cmos_rtc.rtc->dev.bus_id);
476478

477479
spin_lock_irq(&rtc_lock);
@@ -534,9 +536,10 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
534536
return 0;
535537

536538
cleanup1:
537-
rename_region(ports, NULL);
538-
cleanup0:
539+
cmos_rtc.dev = NULL;
539540
rtc_device_unregister(cmos_rtc.rtc);
541+
cleanup0:
542+
release_region(ports->start, ports->end + 1 - ports->start);
540543
return retval;
541544
}
542545

@@ -555,19 +558,21 @@ static void cmos_do_shutdown(void)
555558
static void __exit cmos_do_remove(struct device *dev)
556559
{
557560
struct cmos_rtc *cmos = dev_get_drvdata(dev);
561+
struct resource *ports;
558562

559563
cmos_do_shutdown();
560564

561-
if (is_pnp())
562-
release_resource(cmos->iomem);
563-
rename_region(cmos->iomem, NULL);
564-
565565
if (is_valid_irq(cmos->irq))
566-
free_irq(cmos->irq, cmos_rtc.rtc);
566+
free_irq(cmos->irq, cmos->rtc);
567567

568-
rtc_device_unregister(cmos_rtc.rtc);
568+
rtc_device_unregister(cmos->rtc);
569+
cmos->rtc = NULL;
569570

570-
cmos_rtc.dev = NULL;
571+
ports = cmos->iomem;
572+
release_region(ports->start, ports->end + 1 - ports->start);
573+
cmos->iomem = NULL;
574+
575+
cmos->dev = NULL;
571576
dev_set_drvdata(dev, NULL);
572577
}
573578

@@ -654,7 +659,8 @@ static int cmos_resume(struct device *dev)
654659
/*----------------------------------------------------------------*/
655660

656661
/* The "CMOS" RTC normally lives on the platform_bus. On ACPI systems,
657-
* the device node will always be created as a PNPACPI device.
662+
* the device node will always be created as a PNPACPI device. Plus
663+
* pre-ACPI PCs probably list it in the PNPBIOS tables.
658664
*/
659665

660666
#ifdef CONFIG_PNP

0 commit comments

Comments
 (0)