drivers/media/usb/pvrusb2/pvrusb2-ioread.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/pvrusb2/pvrusb2-ioread.c- Extension
.c- Size
- 11552 bytes
- Lines
- 486
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
pvrusb2-ioread.hpvrusb2-debug.hlinux/errno.hlinux/string.hlinux/mm.hlinux/slab.hlinux/mutex.hlinux/uaccess.h
Detected Declarations
struct pvr2_ioreadfunction pvr2_ioread_initfunction pvr2_ioread_donefunction pvr2_ioread_destroyfunction pvr2_ioread_set_sync_keyfunction pvr2_ioread_stopfunction pvr2_ioread_startfunction pvr2_ioread_setupfunction pvr2_ioread_set_enabledfunction pvr2_ioread_get_bufferfunction pvr2_ioread_filterfunction pvr2_ioread_availfunction pvr2_ioread_read
Annotated Snippet
struct pvr2_ioread {
struct pvr2_stream *stream;
char *buffer_storage[BUFFER_COUNT];
char *sync_key_ptr;
unsigned int sync_key_len;
unsigned int sync_buf_offs;
unsigned int sync_state;
unsigned int sync_trashed_count;
int enabled; // Streaming is on
int spigot_open; // OK to pass data to client
int stream_running; // Passing data to client now
/* State relevant to current buffer being read */
struct pvr2_buffer *c_buf;
char *c_data_ptr;
unsigned int c_data_len;
unsigned int c_data_offs;
struct mutex mutex;
};
static int pvr2_ioread_init(struct pvr2_ioread *cp)
{
unsigned int idx;
cp->stream = NULL;
mutex_init(&cp->mutex);
for (idx = 0; idx < BUFFER_COUNT; idx++) {
cp->buffer_storage[idx] = kmalloc(BUFFER_SIZE,GFP_KERNEL);
if (!(cp->buffer_storage[idx])) break;
}
if (idx < BUFFER_COUNT) {
// An allocation appears to have failed
for (idx = 0; idx < BUFFER_COUNT; idx++) {
if (!(cp->buffer_storage[idx])) continue;
kfree(cp->buffer_storage[idx]);
}
return -ENOMEM;
}
return 0;
}
static void pvr2_ioread_done(struct pvr2_ioread *cp)
{
unsigned int idx;
pvr2_ioread_setup(cp,NULL);
for (idx = 0; idx < BUFFER_COUNT; idx++) {
if (!(cp->buffer_storage[idx])) continue;
kfree(cp->buffer_storage[idx]);
}
}
struct pvr2_ioread *pvr2_ioread_create(void)
{
struct pvr2_ioread *cp;
cp = kzalloc_obj(*cp);
if (!cp) return NULL;
pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_create id=%p",cp);
if (pvr2_ioread_init(cp) < 0) {
kfree(cp);
return NULL;
}
return cp;
}
void pvr2_ioread_destroy(struct pvr2_ioread *cp)
{
if (!cp) return;
pvr2_ioread_done(cp);
pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_destroy id=%p",cp);
if (cp->sync_key_ptr) {
kfree(cp->sync_key_ptr);
cp->sync_key_ptr = NULL;
}
kfree(cp);
}
void pvr2_ioread_set_sync_key(struct pvr2_ioread *cp,
const char *sync_key_ptr,
unsigned int sync_key_len)
{
if (!cp) return;
if (!sync_key_ptr) sync_key_len = 0;
if ((sync_key_len == cp->sync_key_len) &&
((!sync_key_len) ||
(!memcmp(sync_key_ptr,cp->sync_key_ptr,sync_key_len)))) return;
Annotation
- Immediate include surface: `pvrusb2-ioread.h`, `pvrusb2-debug.h`, `linux/errno.h`, `linux/string.h`, `linux/mm.h`, `linux/slab.h`, `linux/mutex.h`, `linux/uaccess.h`.
- Detected declarations: `struct pvr2_ioread`, `function pvr2_ioread_init`, `function pvr2_ioread_done`, `function pvr2_ioread_destroy`, `function pvr2_ioread_set_sync_key`, `function pvr2_ioread_stop`, `function pvr2_ioread_start`, `function pvr2_ioread_setup`, `function pvr2_ioread_set_enabled`, `function pvr2_ioread_get_buffer`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source 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.