Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys move scsipi_strvis -> libkern:strnvisx()
details: https://anonhg.NetBSD.org/src/rev/47c92c639247
branches: trunk
changeset: 345018:47c92c639247
user: christos <christos%NetBSD.org@localhost>
date: Mon May 02 19:18:29 2016 +0000
description:
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
diffstat:
sys/dev/ata/ld_ataraid.c | 16 +++---
sys/dev/ic/ahcisata_core.c | 15 +++---
sys/dev/ic/mpt_netbsd.c | 34 +++++++++------
sys/dev/ic/mvsata.c | 14 +++--
sys/dev/ic/nvme.c | 58 +++----------------------
sys/dev/ic/siisata.c | 15 +++---
sys/dev/pci/arcmsr.c | 27 +++++++-----
sys/dev/pci/mpii.c | 18 ++++---
sys/dev/scsipi/atapi_wdc.c | 17 ++++---
sys/dev/scsipi/scsiconf.c | 13 +++--
sys/dev/scsipi/scsipiconf.c | 44 +-------------------
sys/dev/scsipi/scsipiconf.h | 3 +-
sys/dev/usb/umass_scsipi.c | 13 +++--
sys/lib/libkern/Makefile.libkern | 3 +-
sys/lib/libkern/libkern.h | 6 ++-
sys/lib/libkern/strnvisx.c | 87 ++++++++++++++++++++++++++++++++++++++++
16 files changed, 209 insertions(+), 174 deletions(-)
diffs (truncated from 726 to 300 lines):
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ata/ld_ataraid.c
--- a/sys/dev/ata/ld_ataraid.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ata/ld_ataraid.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_ataraid.c,v 1.40 2015/04/13 16:33:24 riastradh Exp $ */
+/* $NetBSD: ld_ataraid.c,v 1.41 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.40 2015/04/13 16:33:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.41 2016/05/02 19:18:29 christos Exp $");
#include "bio.h"
@@ -698,12 +698,12 @@
strlcpy(bd->bd_procdev, device_xname(adi->adi_dev),
sizeof(bd->bd_procdev));
- scsipi_strvis(serial, sizeof(serial), wd->sc_params.atap_serial,
- sizeof(wd->sc_params.atap_serial));
- scsipi_strvis(model, sizeof(model), wd->sc_params.atap_model,
- sizeof(wd->sc_params.atap_model));
- scsipi_strvis(rev, sizeof(rev), wd->sc_params.atap_revision,
- sizeof(wd->sc_params.atap_revision));
+ strnvisx(serial, sizeof(serial), wd->sc_params.atap_serial,
+ sizeof(wd->sc_params.atap_serial), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(model, sizeof(model), wd->sc_params.atap_model,
+ sizeof(wd->sc_params.atap_model), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(rev, sizeof(rev), wd->sc_params.atap_revision,
+ sizeof(wd->sc_params.atap_revision), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ic/ahcisata_core.c
--- a/sys/dev/ic/ahcisata_core.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ic/ahcisata_core.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_core.c,v 1.55 2015/11/11 02:43:09 jakllsch Exp $ */
+/* $NetBSD: ahcisata_core.c,v 1.56 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.55 2015/11/11 02:43:09 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.56 2016/05/02 19:18:29 christos Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -1846,11 +1846,12 @@
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20, id->atap_serial,
- 20);
- scsipi_strvis((u_char *)firmware_revision, 8,
- id->atap_revision, 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number), id->atap_serial,
+ 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ic/mpt_netbsd.c
--- a/sys/dev/ic/mpt_netbsd.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ic/mpt_netbsd.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpt_netbsd.c,v 1.32 2015/07/22 08:33:51 hannken Exp $ */
+/* $NetBSD: mpt_netbsd.c,v 1.33 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.32 2015/07/22 08:33:51 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.33 2016/05/02 19:18:29 christos Exp $");
#include "bio.h"
@@ -1857,12 +1857,15 @@
memset(&inqbuf, 0, sizeof(inqbuf));
if (scsipi_inquire(periph, &inqbuf,
XS_CTL_DISCOVERY | XS_CTL_SILENT) == 0) {
- scsipi_strvis(vendor, sizeof(vendor),
- inqbuf.vendor, sizeof(inqbuf.vendor));
- scsipi_strvis(product, sizeof(product),
- inqbuf.product, sizeof(inqbuf.product));
- scsipi_strvis(revision, sizeof(revision),
- inqbuf.revision, sizeof(inqbuf.revision));
+ strnvisx(vendor, sizeof(vendor),
+ inqbuf.vendor, sizeof(inqbuf.vendor),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product, sizeof(product),
+ inqbuf.product, sizeof(inqbuf.product),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(revision, sizeof(revision),
+ inqbuf.revision, sizeof(inqbuf.revision),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bv->bv_vendor, sizeof(bv->bv_vendor),
"%s %s %s", vendor, product, revision);
@@ -1927,13 +1930,16 @@
if (phys == NULL)
return;
- scsipi_strvis(vendor_id, sizeof(vendor_id),
- phys->InquiryData.VendorID, sizeof(phys->InquiryData.VendorID));
- scsipi_strvis(product_id, sizeof(product_id),
- phys->InquiryData.ProductID, sizeof(phys->InquiryData.ProductID));
- scsipi_strvis(product_rev_level, sizeof(product_rev_level),
+ strnvisx(vendor_id, sizeof(vendor_id),
+ phys->InquiryData.VendorID, sizeof(phys->InquiryData.VendorID),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product_id, sizeof(product_id),
+ phys->InquiryData.ProductID, sizeof(phys->InquiryData.ProductID),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product_rev_level, sizeof(product_rev_level),
phys->InquiryData.ProductRevLevel,
- sizeof(phys->InquiryData.ProductRevLevel));
+ sizeof(phys->InquiryData.ProductRevLevel),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s %s",
vendor_id, product_id, product_rev_level);
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ic/mvsata.c
--- a/sys/dev/ic/mvsata.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ic/mvsata.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mvsata.c,v 1.34 2015/01/02 19:42:07 christos Exp $ */
+/* $NetBSD: mvsata.c,v 1.35 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2008 KIYOHARA Takashi
* All rights reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.34 2015/01/02 19:42:07 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35 2016/05/02 19:18:29 christos Exp $");
#include "opt_mvsata.h"
@@ -888,10 +888,12 @@
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20, id->atap_serial, 20);
- scsipi_strvis((u_char *)firmware_revision, 8, id->atap_revision,
- 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number), id->atap_serial,
+ 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ic/nvme.c
--- a/sys/dev/ic/nvme.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ic/nvme.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme.c,v 1.1 2016/05/01 10:21:02 nonaka Exp $ */
+/* $NetBSD: nvme.c,v 1.2 2016/05/02 19:18:29 christos Exp $ */
/* $OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
/*
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.1 2016/05/01 10:21:02 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.2 2016/05/02 19:18:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -95,8 +95,6 @@
static void nvme_ns_sync_done(struct nvme_queue *, struct nvme_ccb *,
struct nvme_cqe *);
-static void nvme_strvis(u_char *, int, const u_char *, int);
-
#define nvme_read4(_s, _r) \
bus_space_read_4((_s)->sc_iot, (_s)->sc_ioh, (_r))
#define nvme_write4(_s, _r, _v) \
@@ -900,9 +898,12 @@
identify = NVME_DMA_KVA(mem);
- nvme_strvis(sn, sizeof(sn), identify->sn, sizeof(identify->sn));
- nvme_strvis(mn, sizeof(mn), identify->mn, sizeof(identify->mn));
- nvme_strvis(fr, sizeof(fr), identify->fr, sizeof(identify->fr));
+ strnvisx(sn, sizeof(sn), (const char *)identify->sn,
+ sizeof(identify->sn), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(mn, sizeof(mn), (const char *)identify->mn,
+ sizeof(identify->mn), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(fr, sizeof(fr), (const char *)identify->fr,
+ sizeof(identify->fr), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
aprint_normal_dev(sc->sc_dev, "%s, firmware %s, serial %s\n", mn, fr,
sn);
@@ -1288,46 +1289,3 @@
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
kmem_free(ndm, sizeof(*ndm));
}
-
-/*
- * Copy of sys/dev/scsipi/scsipiconf.c:scsipi_strvis()
- */
-static void
-nvme_strvis(u_char *dst, int dlen, const u_char *src, int slen)
-{
-
-#define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377')
- /* Trim leading and trailing blanks and NULs. */
- while (slen > 0 && STRVIS_ISWHITE(src[0]))
- ++src, --slen;
- while (slen > 0 && STRVIS_ISWHITE(src[slen - 1]))
- --slen;
-
- while (slen > 0) {
- if (*src < 0x20 || *src >= 0x80) {
- /* non-printable characters */
- dlen -= 4;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = ((*src & 0300) >> 6) + '0';
- *dst++ = ((*src & 0070) >> 3) + '0';
- *dst++ = ((*src & 0007) >> 0) + '0';
- } else if (*src == '\\') {
- /* quote characters */
- dlen -= 2;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = '\\';
- } else {
- /* normal characters */
- if (--dlen < 1)
- break;
- *dst++ = *src;
- }
- ++src, --slen;
- }
-
- *dst++ = 0;
-}
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/ic/siisata.c
--- a/sys/dev/ic/siisata.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/ic/siisata.c Mon May 02 19:18:29 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.27 2013/08/08 17:38:56 bouyer Exp $ */
+/* $NetBSD: siisata.c,v 1.28 2016/05/02 19:18:29 christos Exp $ */
/* from ahcisata_core.c */
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.27 2013/08/08 17:38:56 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.28 2016/05/02 19:18:29 christos Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -1459,11 +1459,12 @@
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20,
- id->atap_serial, 20);
- scsipi_strvis((u_char *)firmware_revision, 8,
- id->atap_revision, 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number),
+ id->atap_serial, 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
diff -r acf8e72afd32 -r 47c92c639247 sys/dev/pci/arcmsr.c
--- a/sys/dev/pci/arcmsr.c Mon May 02 17:37:23 2016 +0000
+++ b/sys/dev/pci/arcmsr.c Mon May 02 19:18:29 2016 +0000
Home |
Main Index |
Thread Index |
Old Index