summaryrefslogtreecommitdiffstats
path: root/super-ddf.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2008-09-28 12:12:07 -0700
committerDan Williams <dan.j.williams@intel.com>2008-10-15 14:15:52 -0700
commit3d2c4fc7b6bed924f8d5d1eae9a164b191e1b6da (patch)
treed8ade835972ae3cc8f1103dfcd036fefa91bd971 /super-ddf.c
parent3f6efecc4ccc4b5e50ade7368cf825c372cda0cf (diff)
downloadmdadm-3d2c4fc7b6bed924f8d5d1eae9a164b191e1b6da.tar.gz
mdadm-3d2c4fc7b6bed924f8d5d1eae9a164b191e1b6da.tar.xz
mdadm-3d2c4fc7b6bed924f8d5d1eae9a164b191e1b6da.zip
trivial warn_unused_result squashing
Made the mistake of recompiling the F9 mdadm rpm which has a patch to remove -Werror and add "-Wp,-D_FORTIFY_SOURCE -O2" which turns on lots of errors: config.c:568: warning: ignoring return value of asprintf Assemble.c:411: warning: ignoring return value of asprintf Assemble.c:413: warning: ignoring return value of asprintf super0.c:549: warning: ignoring return value of posix_memalign super0.c:742: warning: ignoring return value of posix_memalign super0.c:812: warning: ignoring return value of posix_memalign super1.c:692: warning: ignoring return value of posix_memalign super1.c:1039: warning: ignoring return value of posix_memalign super1.c:1155: warning: ignoring return value of posix_memalign super-ddf.c:508: warning: ignoring return value of posix_memalign super-ddf.c:645: warning: ignoring return value of posix_memalign super-ddf.c:696: warning: ignoring return value of posix_memalign super-ddf.c:715: warning: ignoring return value of posix_memalign super-ddf.c:1476: warning: ignoring return value of posix_memalign super-ddf.c:1603: warning: ignoring return value of posix_memalign super-ddf.c:1614: warning: ignoring return value of posix_memalign super-ddf.c:1842: warning: ignoring return value of posix_memalign super-ddf.c:2013: warning: ignoring return value of posix_memalign super-ddf.c:2140: warning: ignoring return value of write super-ddf.c:2143: warning: ignoring return value of write super-ddf.c:2147: warning: ignoring return value of write super-ddf.c:2150: warning: ignoring return value of write super-ddf.c:2162: warning: ignoring return value of write super-ddf.c:2169: warning: ignoring return value of write super-ddf.c:2172: warning: ignoring return value of write super-ddf.c:2176: warning: ignoring return value of write super-ddf.c:2181: warning: ignoring return value of write super-ddf.c:2686: warning: ignoring return value of posix_memalign super-ddf.c:2690: warning: ignoring return value of write super-ddf.c:3070: warning: ignoring return value of posix_memalign super-ddf.c:3254: warning: ignoring return value of posix_memalign bitmap.c:128: warning: ignoring return value of posix_memalign mdmon.c:94: warning: ignoring return value of write mdmon.c:221: warning: ignoring return value of pipe mdmon.c:327: warning: ignoring return value of write mdmon.c:330: warning: ignoring return value of chdir mdmon.c:335: warning: ignoring return value of dup monitor.c:415: warning: rv may be used uninitialized in this function ...some of these like the write() ones are not so trivial so save those fixes for the next patch. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'super-ddf.c')
-rw-r--r--super-ddf.c91
1 files changed, 70 insertions, 21 deletions
diff --git a/super-ddf.c b/super-ddf.c
index e8f8005..eb9ccbb 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -504,9 +504,8 @@ static void *load_section(int fd, struct ddf_super *super, void *buf,
/* All pre-allocated sections are a single block */
if (len != 1)
return NULL;
- } else {
- posix_memalign(&buf, 512, len<<9);
- }
+ } else if (posix_memalign(&buf, 512, len<<9) != 0)
+ buf = NULL;
if (!buf)
return NULL;
@@ -642,9 +641,13 @@ static int load_ddf_local(int fd, struct ddf_super *super,
unsigned long long dsize;
/* First the local disk info */
- posix_memalign((void**)&dl, 512,
+ if (posix_memalign((void**)&dl, 512,
sizeof(*dl) +
- (super->max_part) * sizeof(dl->vlist[0]));
+ (super->max_part) * sizeof(dl->vlist[0])) != 0) {
+ fprintf(stderr, Name ": %s could not allocate disk info buffer\n",
+ __func__);
+ return 1;
+ }
load_section(fd, super, &dl->disk,
super->active->data_section_offset,
@@ -693,8 +696,14 @@ static int load_ddf_local(int fd, struct ddf_super *super,
if (vd->magic == DDF_SPARE_ASSIGN_MAGIC) {
if (dl->spare)
continue;
- posix_memalign((void**)&dl->spare, 512,
- super->conf_rec_len*512);
+ if (posix_memalign((void**)&dl->spare, 512,
+ super->conf_rec_len*512) != 0) {
+ fprintf(stderr, Name
+ ": %s could not allocate spare info buf\n",
+ __func__);
+ return 1;
+ }
+
memcpy(dl->spare, vd, super->conf_rec_len*512);
continue;
}
@@ -712,9 +721,14 @@ static int load_ddf_local(int fd, struct ddf_super *super,
__be32_to_cpu(vcl->conf.seqnum))
continue;
} else {
- posix_memalign((void**)&vcl, 512,
+ if (posix_memalign((void**)&vcl, 512,
(super->conf_rec_len*512 +
- offsetof(struct vcl, conf)));
+ offsetof(struct vcl, conf))) != 0) {
+ fprintf(stderr, Name
+ ": %s could not allocate vcl buf\n",
+ __func__);
+ return 1;
+ }
vcl->next = super->conflist;
vcl->block_sizes = NULL; /* FIXME not for CONCAT */
super->conflist = vcl;
@@ -804,7 +818,16 @@ static int load_super_ddf(struct supertype *st, int fd,
return rv;
}
- load_ddf_local(fd, super, devname, 0);
+ rv = load_ddf_local(fd, super, devname, 0);
+
+ if (rv) {
+ if (devname)
+ fprintf(stderr,
+ Name ": Failed to load all information "
+ "sections on %s\n", devname);
+ free(super);
+ return rv;
+ }
/* Should possibly check the sections .... */
@@ -1473,7 +1496,10 @@ static int init_super_ddf(struct supertype *st,
return init_super_ddf_bvd(st, info, size, name, homehost,
uuid);
- posix_memalign((void**)&ddf, 512, sizeof(*ddf));
+ if (posix_memalign((void**)&ddf, 512, sizeof(*ddf)) != 0) {
+ fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
+ return 0;
+ }
memset(ddf, 0, sizeof(*ddf));
ddf->dlist = NULL; /* no physical disks yet */
ddf->conflist = NULL; /* No virtual disks yet */
@@ -1600,7 +1626,10 @@ static int init_super_ddf(struct supertype *st,
memset(ddf->controller.pad, 0xff, 8);
memset(ddf->controller.vendor_data, 0xff, 448);
- posix_memalign((void**)&pd, 512, pdsize);
+ if (posix_memalign((void**)&pd, 512, pdsize) != 0) {
+ fprintf(stderr, Name ": %s could not allocate pd\n", __func__);
+ return 0;
+ }
ddf->phys = pd;
ddf->pdsize = pdsize;
@@ -1611,7 +1640,10 @@ static int init_super_ddf(struct supertype *st,
pd->max_pdes = __cpu_to_be16(max_phys_disks);
memset(pd->pad, 0xff, 52);
- posix_memalign((void**)&vd, 512, vdsize);
+ if (posix_memalign((void**)&vd, 512, vdsize) != 0) {
+ fprintf(stderr, Name ": %s could not allocate vd\n", __func__);
+ return 0;
+ }
ddf->virt = vd;
ddf->vdsize = vdsize;
memset(vd, 0, vdsize);
@@ -1839,8 +1871,11 @@ static int init_super_ddf_bvd(struct supertype *st,
__cpu_to_be16(__be16_to_cpu(ddf->virt->populated_vdes)+1);
/* Now create a new vd_config */
- posix_memalign((void**)&vcl, 512,
- (offsetof(struct vcl, conf) + ddf->conf_rec_len * 512));
+ if (posix_memalign((void**)&vcl, 512,
+ (offsetof(struct vcl, conf) + ddf->conf_rec_len * 512)) != 0) {
+ fprintf(stderr, Name ": %s could not allocate vd_config\n", __func__);
+ return 0;
+ }
vcl->lba_offset = (__u64*) &vcl->conf.phys_refnum[ddf->mppe];
vcl->vcnum = venum;
sprintf(st->subarray, "%d", venum);
@@ -2010,8 +2045,13 @@ static void add_to_super_ddf(struct supertype *st,
* a phys_disk entry and a more detailed disk_data entry.
*/
fstat(fd, &stb);
- posix_memalign((void**)&dd, 512,
- sizeof(*dd) + sizeof(dd->vlist[0]) * ddf->max_part);
+ if (posix_memalign((void**)&dd, 512,
+ sizeof(*dd) + sizeof(dd->vlist[0]) * ddf->max_part) != 0) {
+ fprintf(stderr, Name
+ ": %s could allocate buffer for new disk, aborting\n",
+ __func__);
+ abort();
+ }
dd->major = major(stb.st_rdev);
dd->minor = minor(stb.st_rdev);
dd->devname = devname;
@@ -2547,13 +2587,18 @@ static int load_super_ddf_all(struct supertype *st, int fd,
close(dfd);
/* Now we need the device-local bits */
for (sd = sra->devs ; sd ; sd = sd->next) {
+ int rv;
+
sprintf(nm, "%d:%d", sd->disk.major, sd->disk.minor);
dfd = dev_open(nm, keep_fd? O_RDWR : O_RDONLY);
if (dfd < 0)
return 2;
- load_ddf_headers(dfd, super, NULL);
- seq = load_ddf_local(dfd, super, NULL, keep_fd);
+ rv = load_ddf_headers(dfd, super, NULL);
+ if (rv == 0)
+ rv = load_ddf_local(dfd, super, NULL, keep_fd);
if (!keep_fd) close(dfd);
+ if (rv)
+ return 1;
}
if (st->subarray[0]) {
struct vcl *v;
@@ -2679,16 +2724,20 @@ static int store_zero_ddf(struct supertype *st, int fd)
{
unsigned long long dsize;
void *buf;
+ int rc;
if (!get_dev_size(fd, NULL, &dsize))
return 1;
- posix_memalign(&buf, 512, 512);
+ if (posix_memalign(&buf, 512, 512) != 0)
+ return 1;
memset(buf, 0, 512);
lseek64(fd, dsize-512, 0);
- write(fd, buf, 512);
+ rc = write(fd, buf, 512);
free(buf);
+ if (rc < 0)
+ return 1;
return 0;
}