summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2010-07-01 22:20:02 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2010-07-01 22:20:02 +0000
commitcbbdc7661d38f717fcfcc9ca94d1df18904d2e0f (patch)
tree7518fb3521626418bc998f4a4b1f0c5de3020df5 /sys
parent335ff690f2b69831b4ff2617a13abbf346174076 (diff)
Move rdcap/rdcap16 structs used to get info about disk size off of
stack and malloc/free them instead. First stirrings of the tide of de-stacking to come. Feedback, fixes and ok matthew@ & tedu@.
Diffstat (limited to 'sys')
-rw-r--r--sys/scsi/scsi_base.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c
index 3ddbb2b9dcf..9f72d67689c 100644
--- a/sys/scsi/scsi_base.c
+++ b/sys/scsi/scsi_base.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scsi_base.c,v 1.178 2010/07/01 05:11:18 krw Exp $ */
+/* $OpenBSD: scsi_base.c,v 1.179 2010/07/01 22:20:01 krw Exp $ */
/* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */
/*
@@ -41,6 +41,7 @@
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/uio.h>
+#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/proc.h>
@@ -625,10 +626,10 @@ scsi_xs_put(struct scsi_xfer *xs)
daddr64_t
scsi_size(struct scsi_link *sc_link, int flags, u_int32_t *blksize)
{
- struct scsi_read_cap_data_16 rdcap16;
struct scsi_read_capacity_16 rc16;
- struct scsi_read_cap_data rdcap;
struct scsi_read_capacity rc;
+ struct scsi_read_cap_data_16 *rdcap16 = NULL;
+ struct scsi_read_cap_data *rdcap = NULL;
daddr64_t max_addr;
int error;
@@ -646,18 +647,23 @@ scsi_size(struct scsi_link *sc_link, int flags, u_int32_t *blksize)
* If the command works, interpret the result as a 4 byte
* number of blocks
*/
+ rdcap = malloc(sizeof(*rdcap), M_TEMP, M_NOWAIT|M_ZERO);
+ if (rdcap == NULL)
+ return (0);
error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&rc, sizeof(rc),
- (u_char *)&rdcap, sizeof(rdcap), SCSI_RETRIES, 20000, NULL,
+ (u_char *)rdcap, sizeof(*rdcap), SCSI_RETRIES, 20000, NULL,
flags | SCSI_DATA_IN);
if (error) {
SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY error (%#x)\n",
error));
+ free(rdcap, M_TEMP);
return (0);
}
- max_addr = _4btol(rdcap.addr);
+ max_addr = _4btol(rdcap->addr);
if (blksize != NULL)
- *blksize = _4btol(rdcap.length);
+ *blksize = _4btol(rdcap->length);
+ free(rdcap, M_TEMP);
if (max_addr != 0xffffffff)
return (max_addr + 1);
@@ -669,20 +675,25 @@ scsi_size(struct scsi_link *sc_link, int flags, u_int32_t *blksize)
bzero(&rdcap16, sizeof(rdcap16));
rc16.opcode = READ_CAPACITY_16;
rc16.byte2 = SRC16_SERVICE_ACTION;
- _lto4b(sizeof(rdcap16), rc16.length);
+ _lto4b(sizeof(*rdcap16), rc16.length);
+ rdcap16 = malloc(sizeof(*rdcap16), M_TEMP, M_NOWAIT|M_ZERO);
+ if (rdcap16 == NULL)
+ return (0);
error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&rc16,
- sizeof(rc16), (u_char *)&rdcap16, sizeof(rdcap16), SCSI_RETRIES,
+ sizeof(rc16), (u_char *)rdcap16, sizeof(*rdcap16), SCSI_RETRIES,
20000, NULL, flags | SCSI_DATA_IN);
if (error) {
SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY 16 error (%#x)\n",
error));
+ free(rdcap16, M_TEMP);
return (0);
}
- max_addr = _8btol(rdcap16.addr);
+ max_addr = _8btol(rdcap16->addr);
if (blksize != NULL)
- *blksize = _4btol(rdcap16.length);
+ *blksize = _4btol(rdcap16->length);
+ free(rdcap16, M_TEMP);
return (max_addr + 1);
}