sound/core/memory.c
Source file repositories/reference/linux-study-clean/sound/core/memory.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/memory.c- Extension
.c- Size
- 3130 bytes
- Lines
- 127
- Domain
- Driver Families
- Bucket
- sound/core
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/io.hlinux/uaccess.hsound/core.hsound/pcm.h
Detected Declarations
function Copyrightfunction copy_to_iter_fromiofunction copy_from_user_toiofunction copy_from_iter_toioexport copy_to_user_fromioexport copy_to_iter_fromioexport copy_from_user_toioexport copy_from_iter_toio
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) by Jaroslav Kysela <perex@perex.cz>
*
* Misc memory accessors
*/
#include <linux/export.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <sound/core.h>
#include <sound/pcm.h>
/**
* copy_to_user_fromio - copy data from mmio-space to user-space
* @dst: the destination pointer on user-space
* @src: the source pointer on mmio
* @count: the data size to copy in bytes
*
* Copies the data from mmio-space to user-space.
*
* Return: Zero if successful, or non-zero on failure.
*/
int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
{
struct iov_iter iter;
if (import_ubuf(ITER_DEST, dst, count, &iter))
return -EFAULT;
if (copy_to_iter_fromio((const void __iomem *)src, count, &iter) != count)
return -EFAULT;
return 0;
}
EXPORT_SYMBOL(copy_to_user_fromio);
/**
* copy_to_iter_fromio - copy data from mmio-space to iov_iter
* @src: the source pointer on mmio
* @count: the data size to copy in bytes
* @dst: the destination iov_iter
*
* Copies the data from mmio-space to iov_iter.
*
* Return: number of bytes to be copied
*/
size_t copy_to_iter_fromio(const void __iomem *src, size_t count,
struct iov_iter *dst)
{
#if defined(__i386__) || defined(CONFIG_SPARC32)
return copy_to_iter((const void __force *)src, count, dst);
#else
char buf[256];
size_t res = 0;
while (count) {
size_t c = count;
if (c > sizeof(buf))
c = sizeof(buf);
memcpy_fromio(buf, (void __iomem *)src, c);
if (copy_to_iter(buf, c, dst) != c)
return res;
count -= c;
src += c;
res += c;
}
return res;
#endif
}
EXPORT_SYMBOL(copy_to_iter_fromio);
/**
* copy_from_user_toio - copy data from user-space to mmio-space
* @dst: the destination pointer on mmio-space
* @src: the source pointer on user-space
* @count: the data size to copy in bytes
*
* Copies the data from user-space to mmio-space.
*
* Return: Zero if successful, or non-zero on failure.
*/
int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
{
struct iov_iter iter;
if (import_ubuf(ITER_SOURCE, (void __user *)src, count, &iter))
return -EFAULT;
if (copy_from_iter_toio((void __iomem *)dst, count, &iter) != count)
return -EFAULT;
return 0;
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/io.h`, `linux/uaccess.h`, `sound/core.h`, `sound/pcm.h`.
- Detected declarations: `function Copyright`, `function copy_to_iter_fromio`, `function copy_from_user_toio`, `function copy_from_iter_toio`, `export copy_to_user_fromio`, `export copy_to_iter_fromio`, `export copy_from_user_toio`, `export copy_from_iter_toio`.
- Atlas domain: Driver Families / sound/core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.