Date: Sat, 22 Feb 2025 02:51:41 GMT From: Zhenlei Huang <zlei@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 43339e7fc8a0 - stable/14 - bnxt_en: Improve sysctl handler bnxt_dcb_list_app() Message-ID: <202502220251.51M2pfle069863@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=43339e7fc8a0b07a532015878c5e4f5f36ae8400 commit 43339e7fc8a0b07a532015878c5e4f5f36ae8400 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2025-02-14 10:38:30 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2025-02-22 02:50:55 +0000 bnxt_en: Improve sysctl handler bnxt_dcb_list_app() Prefer sbuf_new_for_sysctl() over error-prone manually managed buffer. No functional change intended. Reviewed by: markj Tested by: Daniel Porsch <daniel.porsch@loopia.se> MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D48496 (cherry picked from commit 91bae242bc54856c560557b5ba245df94d570e95) --- sys/dev/bnxt/bnxt_en/bnxt_sysctl.c | 44 +++++++++++++++----------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c b/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c index 671ceef570f4..5a2e3f656278 100644 --- a/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c +++ b/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c @@ -1872,7 +1872,7 @@ bnxt_pfc_get_string(struct bnxt_softc *softc, char *buf, struct bnxt_ieee_pfc *p buf += sprintf(buf, "none"); } -static char *bnxt_get_tlv_selector_str(uint8_t selector) +static const char *bnxt_get_tlv_selector_str(uint8_t selector) { switch (selector) { case BNXT_IEEE_8021QAZ_APP_SEL_ETHERTYPE: @@ -1887,24 +1887,23 @@ static char *bnxt_get_tlv_selector_str(uint8_t selector) } static void -bnxt_app_tlv_get_string(struct bnxt_softc *softc, char *buf, - struct bnxt_dcb_app *app, int num) +bnxt_app_tlv_get_string(struct sbuf *sb, struct bnxt_dcb_app *app, int num) { - uint32_t i; + int i; - if (!num) { - buf += sprintf(buf, " None"); + if (num == 0) { + sbuf_printf(sb, " None"); return; } - buf += sprintf(buf, "\n"); + sbuf_putc(sb, '\n'); for (i = 0; i < num; i++) { - buf += sprintf(buf, "\tAPP#%0d:\tpri: %d,\tSel: %d,\t%s: %d\n", - i, - app[i].priority, - app[i].selector, - bnxt_get_tlv_selector_str(app[i].selector), - app[i].protocol); + sbuf_printf(sb, "\tAPP#%0d:\tpri: %d,\tSel: %d,\t%s: %d\n", + i, + app[i].priority, + app[i].selector, + bnxt_get_tlv_selector_str(app[i].selector), + app[i].protocol); } } @@ -1937,25 +1936,16 @@ bnxt_ets_get_string(struct bnxt_softc *softc, char *buf) static int bnxt_dcb_list_app(SYSCTL_HANDLER_ARGS) { + struct sbuf sb; struct bnxt_dcb_app app[128] = {0}; struct bnxt_softc *softc = arg1; int rc, num_inputs = 0; - char *buf; - -#define BNXT_APP_TLV_STR_LEN 4096 - buf = malloc(BNXT_APP_TLV_STR_LEN, M_DEVBUF, M_NOWAIT | M_ZERO); - if (!buf) - return ENOMEM; + sbuf_new_for_sysctl(&sb, NULL, 128, req); bnxt_dcb_ieee_listapp(softc, app, nitems(app), &num_inputs); - bnxt_app_tlv_get_string(softc, buf, app, num_inputs); - - rc = sysctl_handle_string(oidp, buf, BNXT_APP_TLV_STR_LEN, req); - if (rc || req->newptr == NULL) - goto end; - -end: - free(buf, M_DEVBUF); + bnxt_app_tlv_get_string(&sb, app, num_inputs); + rc = sbuf_finish(&sb); + sbuf_delete(&sb); return rc; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502220251.51M2pfle069863>