On Fri, May 28, 2021 at 5:25 PM Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx> wrote: > > Add small API covering lists of register dumps. Currently this is a part > of MSM DRM driver, but is extracted as it might be usefull to other > drivers too. > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx> > --- > include/linux/dump_state.h | 78 ++++++++++++++++++++++++++++++++++++++ > lib/Kconfig | 3 ++ > lib/Makefile | 1 + > lib/dump_state.c | 51 +++++++++++++++++++++++++ > 4 files changed, 133 insertions(+) > create mode 100644 include/linux/dump_state.h > create mode 100644 lib/dump_state.c > [snip] > diff --git a/lib/dump_state.c b/lib/dump_state.c > new file mode 100644 > index 000000000000..58d88be65c0a > --- /dev/null > +++ b/lib/dump_state.c > @@ -0,0 +1,51 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. > + * Copyright (c) 2021, Linaro Ltd > + */ > + > +#include <linux/dump_state.h> > +#include <linux/slab.h> > + > +void dump_state_free_blocks(struct dump_state *state) > +{ > + struct dump_state_block *block, *tmp; > + > + list_for_each_entry_safe(block, tmp, &state->blocks, node) { > + list_del(&block->node); > + kfree(block); > + } > +} > +EXPORT_SYMBOL(dump_state_free_blocks); nit, perhaps EXPORT_SYMBOL_GPL()? BR, -R > + > +struct dump_state_block *dump_state_allocate_block_va(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, va_list args) > +{ > + struct dump_state_block *block = kzalloc(sizeof(*block) + len, gfp); > + > + if (!block) > + return ERR_PTR(-ENOMEM); > + > + vsnprintf(block->name, sizeof(block->name), fmt, args); > + > + INIT_LIST_HEAD(&block->node); > + block->size = len; > + block->base_addr = base_addr; > + > + return block; > +} > +EXPORT_SYMBOL(dump_state_allocate_block); > + > +struct dump_state_block *dump_state_allocate_block(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, ...) > +{ > + struct dump_state_block *block; > + va_list va; > + > + va_start(va, fmt); > + > + block = dump_state_allocate_block_va(base_addr, len, gfp, fmt, va); > + > + va_end(va); > + > + return block; > +} > +EXPORT_SYMBOL(dump_state_allocate_block_va); > -- > 2.30.2 >