/* * Simple pointer stack * * (c) 2010 Arnaldo Carvalho de Melo */ #include "util.h" #include "pstack.h" #include "debug.h" #include #include struct pstack { unsigned short top; unsigned short max_nr_entries; void *entries[0]; }; struct pstack *pstack__new(unsigned short max_nr_entries) { struct pstack *pstack = zalloc((sizeof(*pstack) + max_nr_entries * sizeof(void *))); if (pstack != NULL) pstack->max_nr_entries = max_nr_entries; return pstack; } void pstack__delete(struct pstack *pstack) { free(pstack); } bool pstack__empty(const struct pstack *pstack) { return pstack->top == 0; } void pstack__remove(struct pstack *pstack, void *key) { unsigned short i = pstack->top, last_index = pstack->top - 1; while (i-- != 0) { if (pstack->entries[i] == key) { if (i < last_index) memmove(pstack->entries + i, pstack->entries + i + 1, (last_index - i) * sizeof(void *)); --pstack->top; return; } } pr_err("%s: %p not on the pstack!\n", __func__, key); } void pstack__push(struct pstack *pstack, void *key) { if (pstack->top == pstack->max_nr_entries) { pr_err("%s: top=%d, overflow!\n", __func__, pstack->top); return; } pstack->entries[pstack->top++] = key; } void *pstack__pop(struct pstack *pstack) { void *ret; if (pstack->top == 0) { pr_err("%s: underflow!\n", __func__); return NULL; } ret = pstack->entries[--pstack->top]; pstack->entries[pstack->top] = NULL; return ret; } void *pstack__peek(struct pstack *pstack) { if (pstack->top == 0) return NULL; return pstack->entries[pstack->top - 1]; } /refs/?h=nds-private-remove&id=970d14e3989160ee9e97c7d75ecbc893fd29dab9'>refslogtreecommitdiff
diff options
context:
space:
mode:
authorBhumika Goyal <bhumirks@gmail.com>2017-01-25 00:54:07 +0530
committerDan Williams <dan.j.williams@intel.com>2017-01-31 18:16:30 -0800
commit970d14e3989160ee9e97c7d75ecbc893fd29dab9 (patch)
tree4a731cac4efedb17f86a912ec56c151d26792abe /include/pcmcia
parent7a308bb3016f57e5be11a677d15b821536419d36 (diff)
nvdimm: constify device_type structures
Declare device_type structure as const as it is only stored in the type field of a device structure. This field is of type const, so add const to declaration of device_type structure. File size before: text data bss dec hex filename 19278 3199 16 22493 57dd nvdimm/namespace_devs.o File size after: text data bss dec hex filename 19929 3160 16 23105 5a41 nvdimm/namespace_devs.o Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'include/pcmcia')