drivers/staging/greybus/log.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/log.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/log.c- Extension
.c- Size
- 3163 bytes
- Lines
- 134
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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.
- 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/slab.hlinux/sizes.hlinux/uaccess.hlinux/greybus.h
Detected Declarations
struct gb_logfunction gb_log_request_handlerfunction gb_log_probefunction gb_log_disconnect
Annotated Snippet
struct gb_log {
struct gb_connection *connection;
};
static int gb_log_request_handler(struct gb_operation *op)
{
struct gb_connection *connection = op->connection;
struct device *dev = &connection->bundle->dev;
struct gb_log_send_log_request *receive;
u16 len;
if (op->type != GB_LOG_TYPE_SEND_LOG) {
dev_err(dev, "unknown request type 0x%02x\n", op->type);
return -EINVAL;
}
/* Verify size of payload */
if (op->request->payload_size < sizeof(*receive)) {
dev_err(dev, "log request too small (%zu < %zu)\n",
op->request->payload_size, sizeof(*receive));
return -EINVAL;
}
receive = op->request->payload;
len = le16_to_cpu(receive->len);
if (len != (op->request->payload_size - sizeof(*receive))) {
dev_err(dev, "log request wrong size %d vs %zu\n", len,
(op->request->payload_size - sizeof(*receive)));
return -EINVAL;
}
if (len == 0) {
dev_err(dev, "log request of 0 bytes?\n");
return -EINVAL;
}
if (len > GB_LOG_MAX_LEN) {
dev_err(dev, "log request too big: %d\n", len);
return -EINVAL;
}
/* Ensure the buffer is 0 terminated */
receive->msg[len - 1] = '\0';
/*
* Print with dev_dbg() so that it can be easily turned off using
* dynamic debugging (and prevent any DoS)
*/
dev_dbg(dev, "%s", receive->msg);
return 0;
}
static int gb_log_probe(struct gb_bundle *bundle,
const struct greybus_bundle_id *id)
{
struct greybus_descriptor_cport *cport_desc;
struct gb_connection *connection;
struct gb_log *log;
int retval;
if (bundle->num_cports != 1)
return -ENODEV;
cport_desc = &bundle->cport_desc[0];
if (cport_desc->protocol_id != GREYBUS_PROTOCOL_LOG)
return -ENODEV;
log = kzalloc_obj(*log);
if (!log)
return -ENOMEM;
connection = gb_connection_create(bundle, le16_to_cpu(cport_desc->id),
gb_log_request_handler);
if (IS_ERR(connection)) {
retval = PTR_ERR(connection);
goto error_free;
}
log->connection = connection;
greybus_set_drvdata(bundle, log);
retval = gb_connection_enable(connection);
if (retval)
goto error_connection_destroy;
return 0;
error_connection_destroy:
gb_connection_destroy(connection);
error_free:
kfree(log);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/sizes.h`, `linux/uaccess.h`, `linux/greybus.h`.
- Detected declarations: `struct gb_log`, `function gb_log_request_handler`, `function gb_log_probe`, `function gb_log_disconnect`.
- Atlas domain: Driver Families / drivers/staging.
- 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.