git: 1b44079584dc - main - CAM: Use sbuf_new_for_sysctl() in more places
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 22 Nov 2023 20:33:55 UTC
The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=1b44079584dc317230cf810c0fe0a8c401a5c791 commit 1b44079584dc317230cf810c0fe0a8c401a5c791 Author: Alexander Motin <mav@FreeBSD.org> AuthorDate: 2023-11-22 20:32:16 +0000 Commit: Alexander Motin <mav@FreeBSD.org> CommitDate: 2023-11-22 20:33:48 +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 --- 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 db2dc3a23b34..caaded5be7ba 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -1425,7 +1425,6 @@ adazonemodesysctl(SYSCTL_HANDLER_ARGS) static int adazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct ada_softc *softc; struct sbuf sb; int error, first; @@ -1433,15 +1432,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); @@ -1451,10 +1449,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 e795cecb5d11..175774d83015 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -2734,7 +2734,6 @@ dazonemodesysctl(SYSCTL_HANDLER_ARGS) static int dazonesupsysctl(SYSCTL_HANDLER_ARGS) { - char tmpbuf[180]; struct da_softc *softc; struct sbuf sb; int error, first; @@ -2742,15 +2741,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); @@ -2760,10 +2758,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); }