/* * This ensures private data behaves like if it were kmalloced * separately. Also ensures the minimum alignment for safe DMA * operations (which may or may not mean cache alignment).
*/ unsignedlong privdata[] __aligned(ARCH_DMA_MINALIGN);
};
/** * counter_alloc - allocate a counter_device * @sizeof_priv: size of the driver private data * * This is part one of counter registration. The structure is allocated * dynamically to ensure the right lifetime for the embedded struct device. * * If this succeeds, call counter_put() to get rid of the counter_device again.
*/ struct counter_device *counter_alloc(size_t sizeof_priv)
{ struct counter_device_allochelper *ch; struct counter_device *counter; struct device *dev; int err;
ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL); if (!ch) return NULL;
counter = &ch->counter;
dev = &counter->dev;
/* Acquire unique ID */
err = ida_alloc(&counter_ida, GFP_KERNEL); if (err < 0) goto err_ida_alloc;
dev->id = err;
/** * counter_add - complete registration of a counter * @counter: the counter to add * * This is part two of counter registration. * * If this succeeds, call counter_unregister() to get rid of the counter_device again.
*/ int counter_add(struct counter_device *counter)
{ int err; struct device *dev = &counter->dev;
if (counter->parent) {
dev->parent = counter->parent;
dev->of_node = counter->parent->of_node;
}
err = counter_sysfs_add(counter); if (err < 0) return err;
/** * counter_unregister - unregister Counter from the system * @counter: pointer to Counter to unregister * * The Counter is unregistered from the system.
*/ void counter_unregister(struct counter_device *const counter)
{ if (!counter) return;
/** * devm_counter_alloc - allocate a counter_device * @dev: the device to register the release callback for * @sizeof_priv: size of the driver private data * * This is the device managed version of counter_add(). It registers a cleanup * callback to care for calling counter_put().
*/ struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv)
{ struct counter_device *counter; int err;
counter = counter_alloc(sizeof_priv); if (!counter) return NULL;
/** * devm_counter_add - complete registration of a counter * @dev: the device to register the release callback for * @counter: the counter to add * * This is the device managed version of counter_add(). It registers a cleanup * callback to care for calling counter_unregister().
*/ int devm_counter_add(struct device *dev, struct counter_device *const counter)
{ int err;
err = counter_add(counter); if (err < 0) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.