#ifndef __SUBCMD_UTIL_H #define __SUBCMD_UTIL_H #include #include #include #define NORETURN __attribute__((__noreturn__)) static inline void report(const char *prefix, const char *err, va_list params) { char msg[1024]; vsnprintf(msg, sizeof(msg), err, params); fprintf(stderr, " %s%s\n", prefix, msg); } static NORETURN inline void die(const char *err, ...) { va_list params; va_start(params, err); report(" Fatal: ", err, params); exit(128); va_end(params); } #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) #define alloc_nr(x) (((x)+16)*3/2) /* * Realloc the buffer pointed at by variable 'x' so that it can hold * at least 'nr' entries; the number of entries currently allocated * is 'alloc', using the standard growing factor alloc_nr() macro. * * DO NOT USE any expression with side-effect for 'x' or 'alloc'. */ #define ALLOC_GROW(x, nr, alloc) \ do { \ if ((nr) > alloc) { \ if (alloc_nr(alloc) < (nr)) \ alloc = (nr); \ else \ alloc = alloc_nr(alloc); \ x = xrealloc((x), alloc * sizeof(*(x))); \ } \ } while(0) static inline void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) die("Out of memory, realloc failed"); } return ret; } #define astrcatf(out, fmt, ...) \ ({ \ char *tmp = *(out); \ if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1) \ die("asprintf failed"); \ free(tmp); \ }) static inline void astrcat(char **out, const char *add) { char *tmp = *out; if (asprintf(out, "%s%s", tmp ?: "", add) == -1) die("asprintf failed"); free(tmp); } static inline int prefixcmp(const char *str, const char *prefix) { for (; ; str++, prefix++) if (!*prefix) return 0; else if (*str != *prefix) return (unsigned char)*prefix - (unsigned char)*str; } #endif /* __SUBCMD_UTIL_H */ ?id=a7de92dac9f0dbf01deb56fe1d661d7baac097e1'>diff
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2016-12-05 13:43:25 -0800
committerDan Williams <dan.j.williams@intel.com>2016-12-06 17:42:36 -0800
commita7de92dac9f0dbf01deb56fe1d661d7baac097e1 (patch)
treeb1cc2c95f2094ea4ab5b508d49fbbd65fabd5048 /include/crypto
parentd6eb270c57fef35798525004ddf2ac5dcdadd43b (diff)
tools/testing/nvdimm: unit test acpi_nfit_ctl()
A recent flurry of bug discoveries in the nfit driver's DSM marshalling routine has highlighted the fact that we do not have unit test coverage for this routine. Add a self-test of acpi_nfit_ctl() routine before probing the "nfit_test.0" device. This mocks stimulus to acpi_nfit_ctl() and if any of the tests fail "nfit_test.0" will be unavailable causing the rest of the tests to not run / fail. This unit test will also be a place to land reproductions of quirky BIOS behavior discovered in the field and ensure the kernel does not regress against implementations it has seen in practice. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'include/crypto')