Date: Fri, 19 Dec 2014 01:14:42 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r275927 - stable/9/sys/geom/raid Message-ID: <201412190114.sBJ1Eg8T004721@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Fri Dec 19 01:14:41 2014 New Revision: 275927 URL: https://svnweb.freebsd.org/changeset/base/275927 Log: MFC r275503: Avoid unneeded malloc/memcpy/free if there is no metadata on disk. Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com> Modified: stable/9/sys/geom/raid/md_nvidia.c stable/9/sys/geom/raid/md_sii.c Directory Properties: stable/9/ (props changed) stable/9/sys/ (props changed) Modified: stable/9/sys/geom/raid/md_nvidia.c ============================================================================== --- stable/9/sys/geom/raid/md_nvidia.c Fri Dec 19 01:13:41 2014 (r275926) +++ stable/9/sys/geom/raid/md_nvidia.c Fri Dec 19 01:14:41 2014 (r275927) @@ -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, Modified: stable/9/sys/geom/raid/md_sii.c ============================================================================== --- stable/9/sys/geom/raid/md_sii.c Fri Dec 19 01:13:41 2014 (r275926) +++ stable/9/sys/geom/raid/md_sii.c Fri Dec 19 01:14:41 2014 (r275927) @@ -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++)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412190114.sBJ1Eg8T004721>