mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
Use g_slice_spoiled() rather than g_std_spoiled().
Remember to free the buffer we got from g_read_data().
This commit is contained in:
parent
4f806d2428
commit
e65ab0f83f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=114508
@ -251,11 +251,9 @@ g_aes_orphan(struct g_consumer *cp)
|
||||
|
||||
gp = cp->geom;
|
||||
sc = gp->softc;
|
||||
gp->flags |= G_GEOM_WITHER;
|
||||
error = cp->provider->error;
|
||||
LIST_FOREACH(pp, &gp->provider, provider)
|
||||
g_orphan_provider(pp, error);
|
||||
g_wither_geom(gp, cp->provider->error);
|
||||
bzero(sc, sizeof(struct g_aes_softc)); /* destroy evidence */
|
||||
g_free(sc);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -323,9 +321,11 @@ g_aes_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
|
||||
strlen(aes_magic_test))) {
|
||||
sc->keying = KEY_TEST;
|
||||
} else {
|
||||
g_free(buf);
|
||||
g_free(sc);
|
||||
break;
|
||||
}
|
||||
g_free(buf);
|
||||
gp->softc = sc;
|
||||
gp->access = g_aes_access;
|
||||
sc->sectorsize = sectorsize;
|
||||
|
@ -246,12 +246,13 @@ g_apple_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
"%ss%d", gp->name, i + 1);
|
||||
g_topology_unlock();
|
||||
}
|
||||
g_free(buf);
|
||||
break;
|
||||
} while(0);
|
||||
g_topology_lock();
|
||||
g_access_rel(cp, -1, 0, 0);
|
||||
if (LIST_EMPTY(&gp->provider)) {
|
||||
g_std_spoiled(cp);
|
||||
g_slice_spoiled(cp);
|
||||
return (NULL);
|
||||
}
|
||||
return (gp);
|
||||
|
@ -509,11 +509,15 @@ static int
|
||||
g_ctl_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
u_long l1, l2;
|
||||
|
||||
switch(cmd) {
|
||||
case GEOM_CTL:
|
||||
DROP_GIANT();
|
||||
l1 = M_GEOM[0].ks_memuse;
|
||||
error = g_ctl_ioctl_ctl(dev, cmd, data, fflag, td);
|
||||
l2 = M_GEOM[0].ks_memuse;
|
||||
printf("%ld %ld -> %ld\n", l1, l2, l2 - l1);
|
||||
PICKUP_GIANT();
|
||||
break;
|
||||
default:
|
||||
|
@ -244,6 +244,7 @@ g_dev_close(dev_t dev, int flags, int fmt, struct thread *td)
|
||||
return (error);
|
||||
}
|
||||
|
||||
MALLOC_DEFINE(M_GEOMGIO, "GEOMGIO", "Geom data structures");
|
||||
/*
|
||||
* XXX: Until we have unmessed the ioctl situation, there is a race against
|
||||
* XXX: a concurrent orphanization. We cannot close it by holding topology
|
||||
@ -272,7 +273,6 @@ g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
||||
("Consumer with zero access count in g_dev_ioctl"));
|
||||
DROP_GIANT();
|
||||
|
||||
gio = NULL;
|
||||
i = IOCPARM_LEN(cmd);
|
||||
switch (cmd) {
|
||||
case DIOCGSECTORSIZE:
|
||||
@ -314,7 +314,7 @@ g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
||||
break;
|
||||
|
||||
default:
|
||||
gio = g_malloc(sizeof *gio, M_WAITOK | M_ZERO);
|
||||
gio = malloc(sizeof *gio, M_GEOMGIO, M_WAITOK | M_ZERO);
|
||||
gio->cmd = cmd;
|
||||
gio->data = data;
|
||||
gio->fflag = fflag;
|
||||
@ -354,7 +354,7 @@ g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
||||
error = ENOTTY;
|
||||
}
|
||||
if (gio != NULL)
|
||||
g_free(gio);
|
||||
free(gio, M_GEOMGIO);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,8 @@ g_gpt_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
|
||||
}
|
||||
}
|
||||
|
||||
MALLOC_DEFINE(M_GEOMGPT, "GEOMGPT", "Geom data structures");
|
||||
|
||||
static struct g_geom *
|
||||
g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
{
|
||||
@ -188,7 +190,10 @@ g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
ent = (void*)(buf + i * hdr->hdr_entsz);
|
||||
if (!memcmp(&ent->ent_type, &unused, sizeof(unused)))
|
||||
continue;
|
||||
gs->part[i] = g_malloc(hdr->hdr_entsz, M_WAITOK);
|
||||
/*
|
||||
* XXX: memory leak, this is never freed.
|
||||
*/
|
||||
gs->part[i] = malloc(hdr->hdr_entsz, M_GEOMGPT, M_WAITOK);
|
||||
if (gs->part[i] == NULL)
|
||||
break;
|
||||
bcopy(ent, gs->part[i], hdr->hdr_entsz);
|
||||
@ -214,7 +219,7 @@ g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
g_topology_lock();
|
||||
g_access_rel(cp, -1, 0, 0);
|
||||
if (LIST_EMPTY(&gp->provider)) {
|
||||
g_std_spoiled(cp);
|
||||
g_slice_spoiled(cp);
|
||||
return (NULL);
|
||||
}
|
||||
return (gp);
|
||||
|
@ -109,6 +109,8 @@ g_bioq_enqueue_tail(struct bio *bp, struct g_bioq *rq)
|
||||
g_bioq_unlock(rq);
|
||||
}
|
||||
|
||||
MALLOC_DEFINE(M_GEOMBIO, "GEOM bio", "Geom bio");
|
||||
|
||||
struct bio *
|
||||
g_new_bio(void)
|
||||
{
|
||||
@ -118,7 +120,7 @@ g_new_bio(void)
|
||||
bp = g_bioq_first(&g_bio_idle);
|
||||
g_bioq_unlock(&g_bio_idle);
|
||||
if (bp == NULL)
|
||||
bp = g_malloc(sizeof *bp, M_NOWAIT | M_ZERO);
|
||||
bp = malloc(sizeof *bp, M_GEOMBIO, M_NOWAIT | M_ZERO);
|
||||
/* g_trace(G_T_BIO, "g_new_bio() = %p", bp); */
|
||||
return (bp);
|
||||
}
|
||||
@ -127,9 +129,13 @@ void
|
||||
g_destroy_bio(struct bio *bp)
|
||||
{
|
||||
|
||||
#if 0
|
||||
/* g_trace(G_T_BIO, "g_destroy_bio(%p)", bp); */
|
||||
bzero(bp, sizeof *bp);
|
||||
g_bioq_enqueue_tail(bp, &g_bio_idle);
|
||||
#else
|
||||
free(bp, M_GEOMBIO);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct bio *
|
||||
|
@ -300,7 +300,7 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
g_topology_lock();
|
||||
g_access_rel(cp, -1, 0, 0);
|
||||
if (LIST_EMPTY(&gp->provider)) {
|
||||
g_std_spoiled(cp);
|
||||
g_slice_spoiled(cp);
|
||||
return (NULL);
|
||||
}
|
||||
return (gp);
|
||||
@ -398,8 +398,10 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
|
||||
buf = g_read_data(cp, off, sectorsize, &error);
|
||||
if (buf == NULL || error != 0)
|
||||
break;
|
||||
if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa)
|
||||
if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) {
|
||||
g_free(buf);
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NDOSPART; i++)
|
||||
dos_partition_dec(
|
||||
buf + DOSPARTOFF +
|
||||
@ -440,7 +442,7 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
|
||||
g_topology_lock();
|
||||
g_access_rel(cp, -1, 0, 0);
|
||||
if (LIST_EMPTY(&gp->provider)) {
|
||||
g_std_spoiled(cp);
|
||||
g_slice_spoiled(cp);
|
||||
return (NULL);
|
||||
}
|
||||
return (gp);
|
||||
|
@ -237,7 +237,9 @@ g_new_provider_event(void *arg, int flag)
|
||||
struct g_class *mp;
|
||||
struct g_provider *pp;
|
||||
struct g_consumer *cp;
|
||||
struct g_geom *gp;
|
||||
int i;
|
||||
u_long l1, l2;
|
||||
|
||||
g_topology_assert();
|
||||
if (flag == EV_CANCEL)
|
||||
@ -254,7 +256,12 @@ g_new_provider_event(void *arg, int flag)
|
||||
i = 0;
|
||||
if (!i)
|
||||
continue;
|
||||
mp->taste(mp, pp, 0);
|
||||
l1 = M_GEOM[0].ks_memuse;
|
||||
gp = mp->taste(mp, pp, 0);
|
||||
l2 = M_GEOM[0].ks_memuse;
|
||||
if (l1 != l2)
|
||||
printf("%s %p %lu %lu -> %lu\n",
|
||||
mp->name, gp, l1, l2, l2 - l1);
|
||||
g_topology_assert();
|
||||
}
|
||||
}
|
||||
@ -595,20 +602,10 @@ g_std_done(struct bio *bp)
|
||||
void
|
||||
g_std_spoiled(struct g_consumer *cp)
|
||||
{
|
||||
struct g_geom *gp;
|
||||
struct g_provider *pp;
|
||||
|
||||
g_trace(G_T_TOPOLOGY, "g_std_spoiled(%p)", cp);
|
||||
g_topology_assert();
|
||||
g_detach(cp);
|
||||
gp = cp->geom;
|
||||
LIST_FOREACH(pp, &gp->provider, provider)
|
||||
g_orphan_provider(pp, ENXIO);
|
||||
g_destroy_consumer(cp);
|
||||
if (LIST_EMPTY(&gp->provider) && LIST_EMPTY(&gp->consumer))
|
||||
g_destroy_geom(gp);
|
||||
else
|
||||
gp->flags |= G_GEOM_WITHER;
|
||||
g_wither_geom(cp->geom, ENXIO);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -89,8 +89,12 @@ g_vol_ffs_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
for (sb=0; (superblock = superblocks[sb]) != -1; sb++) {
|
||||
fs = (struct fs *) g_read_data(cp, superblock,
|
||||
SBLOCKSIZE, &error);
|
||||
if (fs == NULL || error != 0)
|
||||
if (fs == NULL)
|
||||
continue;
|
||||
if (error != 0) {
|
||||
g_free(fs);
|
||||
continue;
|
||||
}
|
||||
/* Check for magic and make sure things are the right size */
|
||||
if (fs->fs_magic == FS_UFS1_MAGIC) {
|
||||
if (fs->fs_old_size * fs->fs_fsize !=
|
||||
@ -128,7 +132,7 @@ g_vol_ffs_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
g_topology_lock();
|
||||
g_access_rel(cp, -1, 0, 0);
|
||||
if (LIST_EMPTY(&gp->provider)) {
|
||||
g_std_spoiled(cp);
|
||||
g_slice_spoiled(cp);
|
||||
return (NULL);
|
||||
}
|
||||
return (gp);
|
||||
|
Loading…
Reference in New Issue
Block a user