Changes in 4.9.303 Makefile.extrawarn: Move -Wunaligned-access to W=1 net: usb: ax88179_178a: Fix out-of-bounds accesses in RX fixup serial: parisc: GSC: fix build when IOSAPIC is not set parisc: Fix data TLB miss in sba_unmap_sg parisc: Fix sglist access in ccio-dma.c btrfs: send: in case of IO error log it net: ieee802154: at86rf230: Stop leaking skb's selftests/zram: Skip max_comp_streams interface on newer kernel selftests/zram01.sh: Fix compression ratio calculation selftests/zram: Adapt the situation that /dev/zram0 is being used ax25: improve the incomplete fix to avoid UAF and NPD bugs vfs: make freeze_super abort when sync_filesystem returns error quota: make dquot_quota_sync return errors from ->sync_fs drm/radeon: Fix backlight control on iMac 12,1 xfrm: Don't accidentally set RTO_ONLINK in decode_session4() taskstats: Cleanup the use of task->exit_code vsock: correct removal of socket from the list vsock: remove vsock from connected table when connect is interrupted by a signal iwlwifi: pcie: fix locking when "HW not ready" drop_monitor: fix data-race in dropmon_net_event / trace_napi_poll_hit libsubcmd: Fix use-after-free for realloc(..., 0) ALSA: hda: Fix regression on forced probe mask option ALSA: hda: Fix missing codec probe on Shenker Dock 15 ASoC: ops: Fix stereo change notifications in snd_soc_put_volsw() ASoC: ops: Fix stereo change notifications in snd_soc_put_volsw_range() NFS: LOOKUP_DIRECTORY is also ok with symlinks EDAC: Fix calculation of returned address and next offset in edac_align_ptr() i2c: brcmstb: fix support for DSL and CM variants lib/iov_iter: initialize "flags" in new pipe_buffer KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW NFS: Do not report writeback errors in nfs_getattr() ata: libata-core: Disable TRIM on M88V29 tracing: Fix tp_printk option related with tp_printk_stop_on_boot net: usb: qmi_wwan: Add support for Dell DW5829e Linux 4.9.303 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I19131cbf223588e36e1bccd435f93eab152f4199
85 lines
1.8 KiB
C
85 lines
1.8 KiB
C
#ifndef __SUBCMD_UTIL_H
|
|
#define __SUBCMD_UTIL_H
|
|
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#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)
|
|
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 */
|