In fdioctl(), allocate fd_formb dynamically when needed, rather than on

the stack, and remove the no-longer-necessary PHOLD()/PRELE() calls
in fdformat().

(This eliminates 1/3 of the instances of PHOLD()/PRELE() in the kernel code.)

XXX We still have too many mostly-redundant floppy drivers.
This commit is contained in:
nathanw 2000-08-24 20:04:28 +00:00
parent c829aa7773
commit 5127aa189d
6 changed files with 154 additions and 120 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.32 2000/06/29 08:53:01 mrg Exp $ */
/* $NetBSD: fd.c,v 1.33 2000/08/24 20:04:29 nathanw Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -1397,7 +1397,7 @@ fdioctl(dev, cmd, addr, flag, p)
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
struct disklabel buffer;
int error;
unsigned int scratch;
@ -1519,29 +1519,37 @@ fdioctl(dev, cmd, addr, flag, p)
return EINVAL;
}
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if(fd_formb == 0)
return ENOMEM;
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
memset(il, 0, sizeof il);
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs)+1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs)+1])
j++;
il[(j%fd_formb.fd_formb_nsecs)+1] = i;
il[(j%fd_formb->fd_formb_nsecs)+1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
return fdformat(dev, &fd_formb, p);
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return error;
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
@ -1575,7 +1583,6 @@ fdformat(dev, finfo, p)
bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
if(bp == 0)
return ENOBUFS;
PHOLD(p);
memset((void *)bp, 0, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
@ -1615,7 +1622,6 @@ fdformat(dev, finfo, p)
if(bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return rv;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: hdfd.c,v 1.25 2000/06/29 08:28:25 mrg Exp $ */
/* $NetBSD: hdfd.c,v 1.26 2000/08/24 20:04:29 nathanw Exp $ */
/*-
* Copyright (c) 1996 Leo Weppelman
@ -1321,7 +1321,7 @@ fdioctl(dev, cmd, addr, flag, p)
int error;
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
unsigned int scratch;
int il[FD_MAX_NSEC + 1];
register int i, j;
@ -1450,27 +1450,37 @@ fdioctl(dev, cmd, addr, flag, p)
return EINVAL;
}
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if (fd_formb == 0)
return ENOMEM;
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
bzero(il,sizeof il);
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs)+1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs)+1])
j++;
il[(j%fd_formb.fd_formb_nsecs)+1] = i;
il[(j%fd_formb->fd_formb_nsecs)+1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return error;
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
return 0;
@ -1504,7 +1514,6 @@ fdformat(dev, finfo, p)
bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
if(bp == 0)
return ENOBUFS;
PHOLD(p);
bzero((void *)bp, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
@ -1544,7 +1553,6 @@ fdformat(dev, finfo, p)
if(bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return rv;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.84 2000/07/09 20:57:46 pk Exp $ */
/* $NetBSD: fd.c,v 1.85 2000/08/24 20:04:29 nathanw Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -1897,7 +1897,7 @@ fdioctl(dev, cmd, addr, flag, p)
struct fdc_softc *fdc;
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
int il[FD_MAX_NSEC + 1];
int unit;
int i, j;
@ -2046,30 +2046,37 @@ fdioctl(dev, cmd, addr, flag, p)
form_cmd->cylinder >= fd->sc_type->cylinders) {
return (EINVAL);
}
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if (fd_formb == 0)
return (ENOMEM);
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
bzero(il, sizeof il);
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs) + 1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs) + 1])
j++;
il[(j%fd_formb.fd_formb_nsecs) + 1] = i;
il[(j%fd_formb->fd_formb_nsecs) + 1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
return fdformat(dev, &fd_formb, p);
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return error;
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
@ -2129,8 +2136,7 @@ fdformat(dev, finfo, p)
if (bp == 0)
return (ENOBUFS);
PHOLD(p);
bzero((void *)bp, sizeof(struct buf));
memset((void *)bp, 0, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
bp->b_dev = dev;
@ -2191,7 +2197,6 @@ fdformat(dev, finfo, p)
if (bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return (rv);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.17 2000/06/04 19:15:04 cgd Exp $ */
/* $NetBSD: fd.c,v 1.18 2000/08/24 20:04:29 nathanw Exp $ */
/*-
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum.
@ -1532,7 +1532,7 @@ fdioctl(dev, cmd, addr, flag, p)
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
int il[FD_MAX_NSEC + 1];
int i, j;
int error;
@ -1673,30 +1673,37 @@ fdioctl(dev, cmd, addr, flag, p)
form_cmd->cylinder >= fd->sc_type->cylinders) {
return (EINVAL);
}
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if (fd_formb == 0)
return (ENOMEM);
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
bzero(il, sizeof il);
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs) + 1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs) + 1])
j++;
il[(j%fd_formb.fd_formb_nsecs) + 1] = i;
il[(j%fd_formb->fd_formb_nsecs) + 1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
return fdformat(dev, &fd_formb, p);
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return (error);
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
@ -1768,7 +1775,6 @@ fdformat(dev, finfo, p)
if (bp == 0)
return (ENOBUFS);
PHOLD(p);
bzero((void *)bp, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
@ -1810,7 +1816,6 @@ fdformat(dev, finfo, p)
if (bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return (rv);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.21 2000/06/29 07:18:58 mrg Exp $ */
/* $NetBSD: fd.c,v 1.22 2000/08/24 20:04:29 nathanw Exp $ */
/*-
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum.
@ -1568,7 +1568,7 @@ fdioctl(dev, cmd, addr, flag, p)
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
int il[FD_MAX_NSEC + 1];
int i, j;
int error;
@ -1710,29 +1710,36 @@ fdioctl(dev, cmd, addr, flag, p)
return (EINVAL);
}
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if (fd_formb == 0)
return (ENOMEM);
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
bzero(il, sizeof(il));
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs) + 1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs) + 1])
j++;
il[(j%fd_formb.fd_formb_nsecs) + 1] = i;
il[(j%fd_formb->fd_formb_nsecs) + 1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
return fdformat(dev, &fd_formb, p);
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return (error);
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
@ -1804,7 +1811,6 @@ fdformat(dev, finfo, p)
if (bp == 0)
return (ENOBUFS);
PHOLD(p);
bzero((void *)bp, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
@ -1846,7 +1852,6 @@ fdformat(dev, finfo, p)
if (bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return (rv);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.7 2000/07/06 02:02:48 thorpej Exp $ */
/* $NetBSD: fd.c,v 1.8 2000/08/24 20:04:28 nathanw Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -1270,7 +1270,7 @@ fdioctl(dev, cmd, addr, flag, p)
struct fd_softc *fd = device_lookup(&fd_cd, FDUNIT(dev));
struct fdformat_parms *form_parms;
struct fdformat_cmd *form_cmd;
struct ne7_fd_formb fd_formb;
struct ne7_fd_formb *fd_formb;
struct disklabel buffer;
int error;
unsigned int scratch;
@ -1392,29 +1392,36 @@ fdioctl(dev, cmd, addr, flag, p)
return EINVAL;
}
fd_formb.head = form_cmd->head;
fd_formb.cyl = form_cmd->cylinder;
fd_formb.transfer_rate = fd->sc_type->rate;
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_NOWAIT);
if (fd_formb == 0)
return ENOMEM;
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
fd_formb->fd_formb_secshift = fd->sc_type->secsize;
fd_formb->fd_formb_nsecs = fd->sc_type->sectrac;
fd_formb->fd_formb_gaplen = fd->sc_type->gap2;
fd_formb->fd_formb_fillbyte = fd->sc_type->fillbyte;
memset(il, 0, sizeof il);
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
while (il[(j%fd_formb.fd_formb_nsecs)+1])
for (j = 0, i = 1; i <= fd_formb->fd_formb_nsecs; i++) {
while (il[(j%fd_formb->fd_formb_nsecs)+1])
j++;
il[(j%fd_formb.fd_formb_nsecs)+1] = i;
il[(j%fd_formb->fd_formb_nsecs)+1] = i;
j += fd->sc_type->interleave;
}
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb.fd_formb_headno(i) = form_cmd->head;
fd_formb.fd_formb_secno(i) = il[i+1];
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
for (i = 0; i < fd_formb->fd_formb_nsecs; i++) {
fd_formb->fd_formb_cylno(i) = form_cmd->cylinder;
fd_formb->fd_formb_headno(i) = form_cmd->head;
fd_formb->fd_formb_secno(i) = il[i+1];
fd_formb->fd_formb_secsize(i) = fd->sc_type->secsize;
}
return fdformat(dev, &fd_formb, p);
error = fdformat(dev, fd_formb, p);
free(fd_formb, M_TEMP);
return error;
case FDIOCGETOPTS: /* get drive options */
*(int *)addr = fd->sc_opts;
@ -1448,7 +1455,6 @@ fdformat(dev, finfo, p)
bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
if(bp == 0)
return ENOBUFS;
PHOLD(p);
memset((void *)bp, 0, sizeof(struct buf));
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
@ -1488,7 +1494,6 @@ fdformat(dev, finfo, p)
if(bp->b_flags & B_ERROR) {
rv = bp->b_error;
}
PRELE(p);
free(bp, M_TEMP);
return rv;
}