From 4352b8aee98005853aa63f57d6377282de17a33f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 23 Aug 2026 13:28:57 -0700 Subject: Merge tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux Pull I3C updates from Alexandre Belloni: "A new driver this cycle, for the AMD AXI I3C controller. There are also new features such as IBI wakeup support, SETAASA device discovery and ACPI support for the the DAA methods, meaning we can now communicate with the SPD devices on DDR5 modules. New driver: - AMD AXI I3C master controller Subsystem: - I3C Common Command Code (CCC) handling improvements, especially around GET CCCs - SETAASA device discovery support - ACPI support for all existing DAA methods like SETDASA, SETNEWDA as well as I2C devices on I3C bus - IBI-based wakeup support Drivers: - dw: SETAASA support - mipi-i3c-hci: advertise IBI wakeup capability, AMD_PT I3C controller support, PIO queue management support for HCI v1.2 - renesas: improve suspend to RAM support, add runtime PM support" * tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux: (70 commits) i3c: dw: reduce do_daa time if there's no client i3c: mipi-i3c-hci: Add support for AMD_PT I3C controller i3c: mipi-i3c-hci: Add PIO queue management support for HCI v1.2 i3c: mipi-i3c-hci: Fix missing STAT_IBI_STATUS_THLD in PIO mode i3c: dw: rename "pclk" to "apb" to match dt-binding i3c: dw: make struct dw_i3c_cmd smaller i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding i3c: renesas: Don't register devices when ENTDAA times out i3c: master: dw-i3c-master: fix OD timing for first broadcast i3c: mipi-i3c-hci: Advertise IBI wakeup capability i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev() i3c: mipi-i3c-hci-pci: Propagate I3C wakeup requirements to PCI i3c: master: Reject IBI requests from non-IBI-capable devices i3c: master: Add helper to query bus wakeup requirements i3c: master: Report wakeup events for IBIs i3c: master: Support IBI-based wakeup capability i3c: master: Fix potential UAF in i3c_device_match() i3c: master: Fix potential UAF in i3c_device_uevent() i3c: Make dev->desc locking assumptions explicit i3c: master: Fix use-after-free of master->this ... --- tools/perf/util/strbuf.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 tools/perf/util/strbuf.c (limited to 'tools/perf/util/strbuf.c') diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c new file mode 100644 index 000000000..a64a37628 --- /dev/null +++ b/tools/perf/util/strbuf.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "cache.h" +#include "debug.h" +#include "strbuf.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Used as the default ->buf value, so that people can always assume + * buf is non NULL and ->buf is NUL terminated even for a freshly + * initialized strbuf. + */ +char strbuf_slopbuf[1]; + +int strbuf_init(struct strbuf *sb, ssize_t hint) +{ + sb->alloc = sb->len = 0; + sb->buf = strbuf_slopbuf; + if (hint) + return strbuf_grow(sb, hint); + return 0; +} + +void strbuf_release(struct strbuf *sb) +{ + if (sb->alloc) { + zfree(&sb->buf); + strbuf_init(sb, 0); + } +} + +char *strbuf_detach(struct strbuf *sb, size_t *sz) +{ + char *res = sb->alloc ? sb->buf : NULL; + if (sz) + *sz = sb->len; + strbuf_init(sb, 0); + return res; +} + +int strbuf_grow(struct strbuf *sb, size_t extra) +{ + char *buf; + size_t nr = sb->len + extra + 1; + + if (nr < sb->alloc) + return 0; + + if (nr <= sb->len) + return -E2BIG; + + if (alloc_nr(sb->alloc) > nr) + nr = alloc_nr(sb->alloc); + + /* + * Note that sb->buf == strbuf_slopbuf if sb->alloc == 0, and it is + * a static variable. Thus we have to avoid passing it to realloc. + */ + buf = realloc(sb->alloc ? sb->buf : NULL, nr * sizeof(*buf)); + if (!buf) + return -ENOMEM; + + sb->buf = buf; + sb->alloc = nr; + return 0; +} + +int strbuf_addch(struct strbuf *sb, int c) +{ + int ret = strbuf_grow(sb, 1); + if (ret) + return ret; + + sb->buf[sb->len++] = c; + sb->buf[sb->len] = '\0'; + return 0; +} + +int strbuf_add(struct strbuf *sb, const void *data, size_t len) +{ + int ret = strbuf_grow(sb, len); + if (ret) + return ret; + + memcpy(sb->buf + sb->len, data, len); + return strbuf_setlen(sb, sb->len + len); +} + +static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap) +{ + int len, ret; + va_list ap_saved; + + if (!strbuf_avail(sb)) { + ret = strbuf_grow(sb, 64); + if (ret) + return ret; + } + + va_copy(ap_saved, ap); + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); + if (len < 0) { + va_end(ap_saved); + return len; + } + if (len > strbuf_avail(sb)) { + ret = strbuf_grow(sb, len); + if (ret) { + va_end(ap_saved); + return ret; + } + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); + if (len > strbuf_avail(sb)) { + pr_debug("this should not happen, your vsnprintf is broken"); + va_end(ap_saved); + return -EINVAL; + } + } + va_end(ap_saved); + return strbuf_setlen(sb, sb->len + len); +} + +int strbuf_addf(struct strbuf *sb, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = strbuf_addv(sb, fmt, ap); + va_end(ap); + return ret; +} + +ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) +{ + size_t oldlen = sb->len; + size_t oldalloc = sb->alloc; + int ret; + + ret = strbuf_grow(sb, hint ? hint : 8192); + if (ret) + return ret; + + for (;;) { + ssize_t cnt; + + cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); + if (cnt < 0) { + if (oldalloc == 0) + strbuf_release(sb); + else + strbuf_setlen(sb, oldlen); + return cnt; + } + if (!cnt) + break; + sb->len += cnt; + ret = strbuf_grow(sb, 8192); + if (ret) + return ret; + } + + sb->buf[sb->len] = '\0'; + return sb->len - oldlen; +} -- cgit v1.3.1