summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2016-05-02 19:18:29 +0000
committerchristos <christos@NetBSD.org>2016-05-02 19:18:29 +0000
commitd591b4e8741370bd42e79d22ed4da3f966edb669 (patch)
tree569fca075f4a14393f3a043c914a43f8ba82b500 /sys/dev/ic
parent0da5af96a0e50d94b3caf3b0f7da1563aeb673af (diff)
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland fix sizes of strings passed to it
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/ahcisata_core.c15
-rw-r--r--sys/dev/ic/mpt_netbsd.c34
-rw-r--r--sys/dev/ic/mvsata.c14
-rw-r--r--sys/dev/ic/nvme.c58
-rw-r--r--sys/dev/ic/siisata.c15
5 files changed, 52 insertions, 84 deletions
diff --git a/sys/dev/ic/ahcisata_core.c b/sys/dev/ic/ahcisata_core.c
index 78eea5e1db1..96970d6f44b 100644
--- a/sys/dev/ic/ahcisata_core.c
+++ b/sys/dev/ic/ahcisata_core.c
@@ -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 @@ ahci_atapi_probe_device(struct atapibus_softc *sc, int target)
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 --git a/sys/dev/ic/mpt_netbsd.c b/sys/dev/ic/mpt_netbsd.c
index 7f7c13bc91e..2a15d0d9c6a 100644
--- a/sys/dev/ic/mpt_netbsd.c
+++ b/sys/dev/ic/mpt_netbsd.c
@@ -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 @@ mpt_bio_ioctl_vol(mpt_softc_t *mpt, struct bioc_vol *bv)
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 @@ mpt_bio_ioctl_disk_common(mpt_softc_t *mpt, struct bioc_disk *bd,
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 --git a/sys/dev/ic/mvsata.c b/sys/dev/ic/mvsata.c
index 32d5ad89deb..13d5d1c7417 100644
--- a/sys/dev/ic/mvsata.c
+++ b/sys/dev/ic/mvsata.c
@@ -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 @@ mvsata_atapi_probe_device(struct atapibus_softc *sc, int target)
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 --git a/sys/dev/ic/nvme.c b/sys/dev/ic/nvme.c
index e6fb3456053..3f8e0cb19ee 100644
--- a/sys/dev/ic/nvme.c
+++ b/sys/dev/ic/nvme.c
@@ -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_fill(struct nvme_queue *, struct nvme_ccb *,
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 @@ nvme_identify(struct nvme_softc *sc, u_int mps)
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 @@ nvme_dmamem_free(struct nvme_softc *sc, struct nvme_dmamem *ndm)
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 --git a/sys/dev/ic/siisata.c b/sys/dev/ic/siisata.c
index ea7150b1503..a90fa092b05 100644
--- a/sys/dev/ic/siisata.c
+++ b/sys/dev/ic/siisata.c
@@ -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 @@ siisata_atapi_probe_device(struct atapibus_softc *sc, int target)
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;