git: f035d56e711d - stable/14 - CAM: Use sbuf_new_for_sysctl() in more places
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 06 Dec 2023 15:36:39 UTC
The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=f035d56e711d1de9e4cfd924e9a8db42e842a53b commit f035d56e711d1de9e4cfd924e9a8db42e842a53b Author: Alexander Motin <mav@FreeBSD.org> AuthorDate: 2023-11-22 20:32:16 +0000 Commit: Alexander Motin <mav@FreeBSD.org> CommitDate: 2023-12-06 15:35:02 +0000 CAM: Use sbuf_new_for_sysctl() in more places There is no need to allocate buffer, worry about overflows, etc. MFC after: 2 weeks (cherry picked from commit 1b44079584dc317230cf810c0fe0a8c401a5c791) --- sys/cam/ata/ata_da.c | 12 ++++-------- sys/cam/scsi/scsi_da.c | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index d1ef28300666..e9a1c175f333 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -1426,7 +1426,6 @@ adazonemodesysctl(SYSCTL_HANDLER_ARGS) static int adazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct ada_softc *softc; struct sbuf sb; int error, first; @@ -1434,15 +1433,14 @@ adazonesupsysctl(SYSCTL_HANDLER_ARGS) softc = (struct ada_softc *)arg1; - error = 0; first = 1; - sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + sbuf_new_for_sysctl(&sb, NULL, 0, req); for (i = 0; i < sizeof(ada_zone_desc_table) / sizeof(ada_zone_desc_table[0]); i++) { if (softc->zone_flags & ada_zone_desc_table[i].value) { if (first == 0) - sbuf_printf(&sb, ", "); + sbuf_cat(&sb, ", "); else first = 0; sbuf_cat(&sb, ada_zone_desc_table[i].desc); @@ -1452,10 +1450,8 @@ adazonesupsysctl(SYSCTL_HANDLER_ARGS) if (first == 1) sbuf_printf(&sb, "None"); - sbuf_finish(&sb); - - error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); - + error = sbuf_finish(&sb); + sbuf_delete(&sb); return (error); } diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 7a063fce128b..df44d2279fbe 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -2735,7 +2735,6 @@ dazonemodesysctl(SYSCTL_HANDLER_ARGS) static int dazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct da_softc *softc; struct sbuf sb; int error, first; @@ -2743,15 +2742,14 @@ dazonesupsysctl(SYSCTL_HANDLER_ARGS) softc = (struct da_softc *)arg1; - error = 0; first = 1; - sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + sbuf_new_for_sysctl(&sb, NULL, 0, req); for (i = 0; i < sizeof(da_zone_desc_table) / sizeof(da_zone_desc_table[0]); i++) { if (softc->zone_flags & da_zone_desc_table[i].value) { if (first == 0) - sbuf_printf(&sb, ", "); + sbuf_cat(&sb, ", "); else first = 0; sbuf_cat(&sb, da_zone_desc_table[i].desc); @@ -2761,10 +2759,8 @@ dazonesupsysctl(SYSCTL_HANDLER_ARGS) if (first == 1) sbuf_printf(&sb, "None"); - sbuf_finish(&sb); - - error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); - + error = sbuf_finish(&sb); + sbuf_delete(&sb); return (error); }