diff options
-rw-r--r-- | sys/scsi/scsi_base.c | 35 | ||||
-rw-r--r-- | sys/scsi/scsi_disk.h | 3 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 6 | ||||
-rw-r--r-- | sys/scsi/sd.c | 15 |
4 files changed, 34 insertions, 25 deletions
diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index 494a719ef82..40e2d14c855 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_base.c,v 1.253 2019/12/03 13:25:57 krw Exp $ */ +/* $OpenBSD: scsi_base.c,v 1.254 2019/12/03 15:58:28 krw Exp $ */ /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ /* @@ -1159,31 +1159,42 @@ scsi_mode_sense_big(struct scsi_link *link, int byte2, int pg_code, } void * -scsi_mode_sense_page(struct scsi_mode_header *hdr, int pg_length) +scsi_mode_sense_page(struct scsi_mode_header *hdr, int pg_code, int pg_length) { - int total_length, header_length; + u_int8_t *page; + int total_length, header_length; total_length = hdr->data_length + sizeof(hdr->data_length); header_length = sizeof(*hdr) + hdr->blk_desc_len; + page = (u_int8_t *)hdr + header_length; if ((total_length - header_length) < pg_length) - return (NULL); + return NULL; + + if ((*page & SMS_PAGE_CODE) != pg_code) + return NULL; - return ((u_char *)hdr + header_length); + return page; } void * -scsi_mode_sense_big_page(struct scsi_mode_header_big *hdr, int pg_length) +scsi_mode_sense_big_page(struct scsi_mode_header_big *hdr, int pg_code, + int pg_length) { - int total_length, header_length; + u_int8_t *page; + int total_length, header_length; total_length = _2btol(hdr->data_length) + sizeof(hdr->data_length); header_length = sizeof(*hdr) + _2btol(hdr->blk_desc_len); + page = (u_int8_t *)hdr + header_length; if ((total_length - header_length) < pg_length) - return (NULL); + return NULL; + + if ((*page & SMS_PAGE_CODE) != pg_code) + return NULL; - return ((u_char *)hdr + header_length); + return page; } void @@ -1258,7 +1269,8 @@ scsi_do_mode_sense(struct scsi_link *link, int pg_code, error = scsi_mode_sense(link, 0, pg_code, &buf->hdr, sizeof(*buf), flags, 20000); if (error == 0) { - *page_data = scsi_mode_sense_page(&buf->hdr, pg_length); + *page_data = scsi_mode_sense_page(&buf->hdr, pg_code, + pg_length); if (*page_data == NULL) { /* * XXX @@ -1292,7 +1304,8 @@ scsi_do_mode_sense(struct scsi_link *link, int pg_code, return (EIO); *big = 1; - *page_data = scsi_mode_sense_big_page(&buf->hdr_big, pg_length); + *page_data = scsi_mode_sense_big_page(&buf->hdr_big, pg_code, + pg_length); blk_desc: scsi_parse_blkdesc(link, buf, *big, density, block_count, block_size); diff --git a/sys/scsi/scsi_disk.h b/sys/scsi/scsi_disk.h index 0f56fdd62d8..0fdfec2c5d9 100644 --- a/sys/scsi/scsi_disk.h +++ b/sys/scsi/scsi_disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_disk.h,v 1.39 2019/11/25 17:02:57 krw Exp $ */ +/* $OpenBSD: scsi_disk.h,v 1.40 2019/12/03 15:58:28 krw Exp $ */ /* $NetBSD: scsi_disk.h,v 1.10 1996/07/05 16:19:05 christos Exp $ */ /* @@ -313,7 +313,6 @@ struct scsi_reassign_blocks_data { }; /* Only the lower 6 bits of the pg_code field are used for page #. */ -#define DISK_PGCODE(pg, n) ((pg) != NULL) && (((pg)->pg_code & 0x3f) == n) #define PAGE_DISK_FORMAT 3 #define PAGE_RIGID_GEOMETRY 4 #define PAGE_FLEX_GEOMETRY 5 diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 28ce42a3c04..c9c0596dab5 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.h,v 1.178 2019/11/28 17:26:00 krw Exp $ */ +/* $OpenBSD: scsiconf.h,v 1.179 2019/12/03 15:58:28 krw Exp $ */ /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ /* @@ -487,8 +487,8 @@ int scsi_mode_sense(struct scsi_link *, int, int, struct scsi_mode_header *, size_t, int, int); int scsi_mode_sense_big(struct scsi_link *, int, int, struct scsi_mode_header_big *, size_t, int, int); -void * scsi_mode_sense_page(struct scsi_mode_header *, int); -void * scsi_mode_sense_big_page(struct scsi_mode_header_big *, int); +void * scsi_mode_sense_page(struct scsi_mode_header *, int, int); +void * scsi_mode_sense_big_page(struct scsi_mode_header_big *, int, int); void scsi_parse_blkdesc(struct scsi_link *, union scsi_mode_sense_buf *, int, u_int32_t *, u_int64_t *, u_int32_t *); int scsi_do_mode_sense(struct scsi_link *, int, diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 5ee246449c1..c87c127d575 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.303 2019/11/29 15:17:28 krw Exp $ */ +/* $OpenBSD: sd.c,v 1.304 2019/12/03 15:58:28 krw Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -1061,13 +1061,10 @@ sd_ioctl_cache(struct sd_softc *sc, long cmd, struct dk_cache *dkc) rv = scsi_do_mode_sense(link, PAGE_CACHING_MODE, buf, (void **)&mode, NULL, NULL, NULL, sizeof(*mode) - 4, scsi_autoconf | SCSI_SILENT, &big); - if (rv != 0) - goto done; - - if (!DISK_PGCODE(mode, PAGE_CACHING_MODE)) { + if (rv == 0 && mode == NULL) rv = EIO; + if (rv != 0) goto done; - } wrcache = (ISSET(mode->flags, PG_CACHE_FL_WCE) ? 1 : 0); rdcache = (ISSET(mode->flags, PG_CACHE_FL_RCD) ? 0 : 1); @@ -1726,7 +1723,7 @@ sd_get_parms(struct sd_softc *sc, int flags) err = scsi_do_mode_sense(link, PAGE_REDUCED_GEOMETRY, buf, (void **)&reduced, NULL, NULL, &dp.secsize, sizeof(*reduced), flags | SCSI_SILENT, &big); - if (!err && DISK_PGCODE(reduced, PAGE_REDUCED_GEOMETRY)) { + if (err == 0 && reduced != NULL) { if (dp.disksize == 0) dp.disksize = _5btol(reduced->sectors); if (dp.secsize == 0) @@ -1749,7 +1746,7 @@ sd_get_parms(struct sd_softc *sc, int flags) PAGE_RIGID_GEOMETRY, buf, (void **)&rigid, NULL, NULL, &dp.secsize, sizeof(*rigid) - 4, flags | SCSI_SILENT, &big); - if (!err && DISK_PGCODE(rigid, PAGE_RIGID_GEOMETRY)) { + if (err == 0 && rigid != NULL) { dp.heads = rigid->nheads; dp.cyls = _3btol(rigid->ncyl); if (dp.heads * dp.cyls > 0) @@ -1761,7 +1758,7 @@ sd_get_parms(struct sd_softc *sc, int flags) PAGE_FLEX_GEOMETRY, buf, (void **)&flex, NULL, NULL, &dp.secsize, sizeof(*flex) - 4, flags | SCSI_SILENT, &big); - if (!err && DISK_PGCODE(flex, PAGE_FLEX_GEOMETRY)) { + if (err == 0 && flex != NULL) { dp.sectors = flex->ph_sec_tr; dp.heads = flex->nheads; dp.cyls = _2btol(flex->ncyl); |