Avoid unneeded malloc/memcpy/free if there is no metadata on disk.

Submitted by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after:	2 weeks
This commit is contained in:
Alexander Motin 2014-12-05 10:23:18 +00:00
parent 457b4b8836
commit 1e68fe9c33
2 changed files with 12 additions and 10 deletions

View File

@ -256,23 +256,24 @@ nvidia_meta_read(struct g_consumer *cp)
pp->name, error);
return (NULL);
}
meta = malloc(sizeof(*meta), M_MD_NVIDIA, M_WAITOK);
memcpy(meta, buf, min(sizeof(*meta), pp->sectorsize));
g_free(buf);
meta = (struct nvidia_raid_conf *)buf;
/* Check if this is an NVIDIA RAID struct */
if (strncmp(meta->nvidia_id, NVIDIA_MAGIC, strlen(NVIDIA_MAGIC))) {
G_RAID_DEBUG(1, "NVIDIA signature check failed on %s", pp->name);
free(meta, M_MD_NVIDIA);
g_free(buf);
return (NULL);
}
if (meta->config_size > 128 ||
meta->config_size < 30) {
G_RAID_DEBUG(1, "NVIDIA metadata size looks wrong: %d",
meta->config_size);
free(meta, M_MD_NVIDIA);
g_free(buf);
return (NULL);
}
meta = malloc(sizeof(*meta), M_MD_NVIDIA, M_WAITOK);
memcpy(meta, buf, min(sizeof(*meta), pp->sectorsize));
g_free(buf);
/* Check metadata checksum. */
for (checksum = 0, ptr = (uint32_t *)meta,

View File

@ -277,15 +277,13 @@ sii_meta_read(struct g_consumer *cp)
pp->name, error);
return (NULL);
}
meta = malloc(sizeof(*meta), M_MD_SII, M_WAITOK);
memcpy(meta, buf, min(sizeof(*meta), pp->sectorsize));
g_free(buf);
meta = (struct sii_raid_conf *)buf;
/* Check vendor ID. */
if (meta->vendor_id != 0x1095) {
G_RAID_DEBUG(1, "SiI vendor ID check failed on %s (0x%04x)",
pp->name, meta->vendor_id);
free(meta, M_MD_SII);
g_free(buf);
return (NULL);
}
@ -293,9 +291,12 @@ sii_meta_read(struct g_consumer *cp)
if (meta->version_major != 2) {
G_RAID_DEBUG(1, "SiI version check failed on %s (%d.%d)",
pp->name, meta->version_major, meta->version_minor);
free(meta, M_MD_SII);
g_free(buf);
return (NULL);
}
meta = malloc(sizeof(*meta), M_MD_SII, M_WAITOK);
memcpy(meta, buf, min(sizeof(*meta), pp->sectorsize));
g_free(buf);
/* Check metadata checksum. */
for (checksum = 0, ptr = (uint16_t *)meta, i = 0; i <= 159; i++)