drivers/watchdog/riowd.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/riowd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/riowd.c- Extension
.c- Size
- 5723 bytes
- Lines
- 245
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/types.hlinux/fs.hlinux/errno.hlinux/miscdevice.hlinux/watchdog.hlinux/of.hlinux/platform_device.hlinux/io.hlinux/uaccess.hlinux/slab.h
Detected Declarations
struct riowdfunction riowd_writeregfunction riowd_openfunction riowd_releasefunction riowd_ioctlfunction riowd_writefunction riowd_probefunction riowd_remove
Annotated Snippet
static const struct file_operations riowd_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = riowd_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = riowd_open,
.write = riowd_write,
.release = riowd_release,
};
static struct miscdevice riowd_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &riowd_fops
};
static int riowd_probe(struct platform_device *op)
{
struct riowd *p;
int err = -EINVAL;
if (riowd_device)
goto out;
err = -ENOMEM;
p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL);
if (!p)
goto out;
spin_lock_init(&p->lock);
p->regs = of_ioremap(&op->resource[0], 0, 2, DRIVER_NAME);
if (!p->regs) {
pr_err("Cannot map registers\n");
goto out;
}
/* Make miscdev useable right away */
riowd_device = p;
err = misc_register(&riowd_miscdev);
if (err) {
pr_err("Cannot register watchdog misc device\n");
goto out_iounmap;
}
pr_info("Hardware watchdog [%i minutes], regs at %p\n",
riowd_timeout, p->regs);
platform_set_drvdata(op, p);
return 0;
out_iounmap:
riowd_device = NULL;
of_iounmap(&op->resource[0], p->regs, 2);
out:
return err;
}
static void riowd_remove(struct platform_device *op)
{
struct riowd *p = platform_get_drvdata(op);
misc_deregister(&riowd_miscdev);
of_iounmap(&op->resource[0], p->regs, 2);
}
static const struct of_device_id riowd_match[] = {
{
.name = "pmc",
},
{},
};
MODULE_DEVICE_TABLE(of, riowd_match);
static struct platform_driver riowd_driver = {
.driver = {
.name = DRIVER_NAME,
.of_match_table = riowd_match,
},
.probe = riowd_probe,
.remove = riowd_remove,
};
module_platform_driver(riowd_driver);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `linux/fs.h`, `linux/errno.h`, `linux/miscdevice.h`, `linux/watchdog.h`, `linux/of.h`.
- Detected declarations: `struct riowd`, `function riowd_writereg`, `function riowd_open`, `function riowd_release`, `function riowd_ioctl`, `function riowd_write`, `function riowd_probe`, `function riowd_remove`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.