drivers/video/fbdev/core/fbcmap.c
Source file repositories/reference/linux-study-clean/drivers/video/fbdev/core/fbcmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/fbdev/core/fbcmap.c- Extension
.c- Size
- 8637 bytes
- Lines
- 364
- Domain
- Driver Families
- Bucket
- drivers/video
- 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.
- 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/export.hlinux/string.hlinux/module.hlinux/fb.hlinux/slab.hlinux/uaccess.h
Detected Declarations
function fb_alloc_cmap_gfpfunction fb_alloc_cmapfunction fb_alloc_cmapfunction fb_copy_cmapfunction fb_cmap_to_userfunction fb_set_cmapfunction fb_set_user_cmapfunction copy_from_userfunction fb_invert_cmapsexport fb_alloc_cmapexport fb_dealloc_cmapexport fb_copy_cmapexport fb_set_cmapexport fb_default_cmapexport fb_invert_cmaps
Annotated Snippet
if (transp) {
cmap->transp = kzalloc(size, flags);
if (!cmap->transp)
goto fail;
} else {
cmap->transp = NULL;
}
}
cmap->start = 0;
cmap->len = len;
ret = fb_copy_cmap(fb_default_cmap(len), cmap);
if (ret)
goto fail;
return 0;
fail:
fb_dealloc_cmap(cmap);
return ret;
}
int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
{
return fb_alloc_cmap_gfp(cmap, len, transp, GFP_ATOMIC);
}
/**
* fb_dealloc_cmap - deallocate a colormap
* @cmap: frame buffer colormap structure
*
* Deallocates a colormap that was previously allocated with
* fb_alloc_cmap().
*
*/
void fb_dealloc_cmap(struct fb_cmap *cmap)
{
kfree(cmap->red);
kfree(cmap->green);
kfree(cmap->blue);
kfree(cmap->transp);
cmap->red = cmap->green = cmap->blue = cmap->transp = NULL;
cmap->len = 0;
}
/**
* fb_copy_cmap - copy a colormap
* @from: frame buffer colormap structure
* @to: frame buffer colormap structure
*
* Copy contents of colormap from @from to @to.
*/
int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)
{
unsigned int tooff = 0, fromoff = 0;
size_t size;
if (to->start > from->start)
fromoff = to->start - from->start;
else
tooff = from->start - to->start;
if (fromoff >= from->len || tooff >= to->len)
return -EINVAL;
size = min_t(size_t, to->len - tooff, from->len - fromoff);
if (size == 0)
return -EINVAL;
size *= sizeof(u16);
memcpy(to->red+tooff, from->red+fromoff, size);
memcpy(to->green+tooff, from->green+fromoff, size);
memcpy(to->blue+tooff, from->blue+fromoff, size);
if (from->transp && to->transp)
memcpy(to->transp+tooff, from->transp+fromoff, size);
return 0;
}
int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to)
{
unsigned int tooff = 0, fromoff = 0;
size_t size;
if (to->start > from->start)
fromoff = to->start - from->start;
else
tooff = from->start - to->start;
if (fromoff >= from->len || tooff >= to->len)
return -EINVAL;
Annotation
- Immediate include surface: `linux/export.h`, `linux/string.h`, `linux/module.h`, `linux/fb.h`, `linux/slab.h`, `linux/uaccess.h`.
- Detected declarations: `function fb_alloc_cmap_gfp`, `function fb_alloc_cmap`, `function fb_alloc_cmap`, `function fb_copy_cmap`, `function fb_cmap_to_user`, `function fb_set_cmap`, `function fb_set_user_cmap`, `function copy_from_user`, `function fb_invert_cmaps`, `export fb_alloc_cmap`.
- Atlas domain: Driver Families / drivers/video.
- 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.