drivers/usb/gadget/legacy/printer.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/legacy/printer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/legacy/printer.c- Extension
.c- Size
- 5902 bytes
- Lines
- 227
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hasm/byteorder.hlinux/usb/ch9.hlinux/usb/composite.hlinux/usb/gadget.hlinux/usb/g_printer.hu_printer.h
Detected Declarations
function printer_do_configfunction printer_bindfunction printer_unbind
Annotated Snippet
if (!opts->pnp_string) {
ret = -ENOMEM;
goto fail_put_func_inst;
}
opts->pnp_string_allocated = true;
/*
* we don't free this memory in case of error
* as printer cleanup func will do this for us
*/
} else {
opts->pnp_string = pnp_string;
}
ret = usb_string_ids_tab(cdev, strings);
if (ret < 0)
goto fail_put_func_inst;
device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id;
device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id;
if (gadget_is_otg(cdev->gadget) && !otg_desc[0]) {
struct usb_descriptor_header *usb_desc;
usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
if (!usb_desc) {
ret = -ENOMEM;
goto fail_put_func_inst;
}
usb_otg_descriptor_init(cdev->gadget, usb_desc);
otg_desc[0] = usb_desc;
otg_desc[1] = NULL;
}
ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config);
if (ret)
goto fail_free_otg_desc;
usb_composite_overwrite_options(cdev, &coverwrite);
return ret;
fail_free_otg_desc:
kfree(otg_desc[0]);
otg_desc[0] = NULL;
fail_put_func_inst:
usb_put_function_instance(fi_printer);
return ret;
}
static int printer_unbind(struct usb_composite_dev *cdev)
{
usb_put_function(f_printer);
usb_put_function_instance(fi_printer);
kfree(otg_desc[0]);
otg_desc[0] = NULL;
return 0;
}
static struct usb_composite_driver printer_driver = {
.name = shortname,
.dev = &device_desc,
.strings = dev_strings,
.max_speed = USB_SPEED_SUPER,
.bind = printer_bind,
.unbind = printer_unbind,
};
module_usb_composite_driver(printer_driver);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_AUTHOR("Craig Nadler");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `asm/byteorder.h`, `linux/usb/ch9.h`, `linux/usb/composite.h`, `linux/usb/gadget.h`, `linux/usb/g_printer.h`, `u_printer.h`.
- Detected declarations: `function printer_do_config`, `function printer_bind`, `function printer_unbind`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
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.