]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
trivial warn_unused_result squashing
authorDan Williams <dan.j.williams@intel.com>
Sun, 28 Sep 2008 19:12:07 +0000 (12:12 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 15 Oct 2008 21:15:52 +0000 (14:15 -0700)
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>
Assemble.c
Makefile
bitmap.c
config.c
mdmon.c
monitor.c
super-ddf.c
super0.c
super1.c

index a73e101ed047e75c139ab48b84a70f0c15270df2..c691ec9add727a0536cc0b32815ac8680be9ba7e 100644 (file)
@@ -396,6 +396,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                mdu_array_info_t inf;
                char *c;
                char nbuf[64];
+               int rc;
+
                if (!st || !st->sb) {
                        return 2;
                }
@@ -408,10 +410,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                }
                if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
                        /* /dev/md/d0 style for partitionable */
-                       asprintf(&mddev, "/dev/md/d%s", c);
+                       rc = asprintf(&mddev, "/dev/md/d%s", c);
+               else
+                       rc = asprintf(&mddev, "/dev/md/%s", c);
+               if (rc < 0)
+                       mdfd = -1;
                else
-                       asprintf(&mddev, "/dev/md/%s", c);
-               mdfd = open_mddev(mddev, ident->autof);
+                       mdfd = open_mddev(mddev, ident->autof);
                if (mdfd < 0) {
                        st->ss->free_super(st);
                        free(devices);
index 6b878cc1d160a5e2b74992e5314933968a7d8123..f26eeaceb0946d62802999b9505c8fb4f8042d1b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,9 @@ KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIB
 CC = $(CROSS_COMPILE)gcc
 CXFLAGS = -ggdb
 CWFLAGS = -Wall -Werror -Wstrict-prototypes
+ifdef WARN_UNUSED
+CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O
+endif
 
 ifdef DEBIAN
 CPPFLAGS= -DDEBIAN
index 86176696f957edef9d88955e869612ba6c47de85..0f8a26538ace6eb450c128c3af82b3ad11e9f9b0 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -125,7 +125,10 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
        void *buf;
        int n, skip;
 
-       posix_memalign(&buf, 512, 8192);
+       if (posix_memalign(&buf, 512, 8192) != 0) {
+               fprintf(stderr, Name ": failed to allocate 8192 bytes\n");
+               return NULL;
+       }
        n = read(fd, buf, 8192);
 
        info = malloc(sizeof(*info));
index f471cf36e73b1b5de8d3492b1dae2a38f0837df6..9aa8be4c6a94c8c6fdf20cd9ca6201473eca0d2e 100644 (file)
--- a/config.c
+++ b/config.c
@@ -564,10 +564,12 @@ void mailfromline(char *line)
                if (alert_mail_from == NULL)
                        alert_mail_from = strdup(w);
                else {
-                       char *t= NULL;
-                       asprintf(&t, "%s %s", alert_mail_from, w);
-                       free(alert_mail_from);
-                       alert_mail_from = t;
+                       char *t = NULL;
+
+                       if (asprintf(&t, "%s %s", alert_mail_from, w) > 0) {
+                               free(alert_mail_from);
+                               alert_mail_from = t;
+                       }
                }
        }
 }
diff --git a/mdmon.c b/mdmon.c
index 568264b38b8296660c6b8d3c6542e56b2388d353..3f5edbba78574db6efb5e4ff6cb602106ac35983 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -85,14 +85,18 @@ int make_pidfile(char *devname, int o_excl)
        char path[100];
        char pid[10];
        int fd;
+       int n;
+
        sprintf(path, "/var/run/mdadm/%s.pid", devname);
 
        fd = open(path, O_RDWR|O_CREAT|o_excl, 0600);
        if (fd < 0)
                return -errno;
        sprintf(pid, "%d\n", getpid());
-       write(fd, pid, strlen(pid));
+       n = write(fd, pid, strlen(pid));
        close(fd);
+       if (n < 0)
+               return -errno;
        return 0;
 }
 
@@ -199,6 +203,7 @@ int main(int argc, char *argv[])
        struct sigaction act;
        int pfd[2];
        int status;
+       int ignore;
 
        if (argc != 2) {
                fprintf(stderr, "Usage: md-manage /device/name/for/container\n");
@@ -218,7 +223,10 @@ int main(int argc, char *argv[])
 
        /* Fork, and have the child tell us when they are ready */
        if (do_fork()) {
-               pipe(pfd);
+               if (pipe(pfd) != 0) {
+                       fprintf(stderr, "mdmon: failed to create pipe\n");
+                       exit(1);
+               }
                switch(fork()) {
                case -1:
                        fprintf(stderr, "mdmon: failed to fork: %s\n",
@@ -324,18 +332,20 @@ int main(int argc, char *argv[])
        /* Ok, this is close enough.  We can say goodbye to our parent now.
         */
        status = 0;
-       write(pfd[1], &status, sizeof(status));
+       if (write(pfd[1], &status, sizeof(status)) < 0)
+               fprintf(stderr, "mdmon: failed to notify our parent: %d\n",
+                       getppid());
        close(pfd[1]);
 
-       chdir("/");
+       ignore = chdir("/");
        setsid();
        close(0);
        open("/dev/null", O_RDWR);
        close(1);
-       dup(0);
+       ignore = dup(0);
 #ifndef DEBUG
        close(2);
-       dup(0);
+       ignore = dup(0);
 #endif
 
        mlockall(MCL_FUTURE);
index bd67e1ad1e29798a117181cacc4c5d51ad89164e..1bf69a7e284888515a2ddcf247d9d693fb0fbcdf 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -486,6 +486,7 @@ static int wait_and_act(struct supertype *container, int nowait)
                container->ss->sync_metadata(container);
        }
 
+       rv = 0;
        for (a = *aap; a ; a = a->next) {
                if (a->replaces && !discard_this) {
                        struct active_array **ap;
index e8f80051042a52dfebcf9006334dd03f718ac354..eb9ccbbba28afa4edf257cb92954dd3d8ffab419 100644 (file)
@@ -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;
 }
 
index 24ea009a9354fa314058a8b0743f35abcd29d1fc..291ccdde4001eae90ea400163757199f11082f61 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -546,7 +546,10 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
        mdp_super_t *sb;
        int spares;
 
-       posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t));
+       if (posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t)) != 0) {
+               fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
+               return 0;
+       }
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
 
        st->sb = sb;
@@ -739,8 +742,12 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
        if (second->md_magic != MD_SB_MAGIC)
                return 1;
        if (!first) {
-               posix_memalign((void**)&first, 512, 
-                              MD_SB_BYTES + sizeof(struct bitmap_super_s));
+               if (posix_memalign((void**)&first, 512, 
+                              MD_SB_BYTES + sizeof(struct bitmap_super_s)) != 0) {
+                       fprintf(stderr, Name
+                               ": %s could not allocate superblock\n", __func__);
+                       return 1;
+               }
                memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
                st->sb = first;
                return 0;
@@ -809,7 +816,12 @@ static int load_super0(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       posix_memalign((void**)&super, 512, MD_SB_BYTES + sizeof(bitmap_super_t)+512);
+       if (posix_memalign((void**)&super, 512,
+                          MD_SB_BYTES + sizeof(bitmap_super_t)+512) != 0) {
+               fprintf(stderr, Name
+                       ": %s could not allocate superblock\n", __func__);
+               return 1;
+       }
 
        if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) {
                if (devname)
index b7cd962a7e375de6c0c7667749ccf60acaffc88e..a392cf6c5d9f0a1dc5f6b9162babc5bcd6f6bccd 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -689,8 +689,12 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
        int rfd;
        char defname[10];
 
-       posix_memalign((void**)&sb, 512, (1024 + 512 + 
-                                         sizeof(struct misc_dev_info)));
+       if (posix_memalign((void**)&sb, 512, (1024 + 512 + 
+                          sizeof(struct misc_dev_info))) != 0) {
+               fprintf(stderr, Name
+                       ": %s could not allocate superblock\n", __func__);
+               return 0;
+       }
        memset(sb, 0, 1024);
 
        st->sb = sb;
@@ -1036,9 +1040,13 @@ static int compare_super1(struct supertype *st, struct supertype *tst)
                return 1;
 
        if (!first) {
-               posix_memalign((void**)&first, 512,
+               if (posix_memalign((void**)&first, 512,
                               1024 + 512 +
-                              sizeof(struct misc_dev_info));
+                              sizeof(struct misc_dev_info)) != 0) {
+                       fprintf(stderr, Name
+                               ": %s could not allocate superblock\n", __func__);
+                       return 1;
+               }
                memcpy(first, second, 1024 + 512 + 
                       sizeof(struct misc_dev_info));
                st->sb = first;
@@ -1152,9 +1160,13 @@ static int load_super1(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       posix_memalign((void**)&super, 512,
+       if (posix_memalign((void**)&super, 512,
                       1024 + 512 +
-                      sizeof(struct misc_dev_info));
+                      sizeof(struct misc_dev_info)) != 0) {
+               fprintf(stderr, Name ": %s could not allocate superblock\n",
+                       __func__);
+               return 1;
+       }
 
        if (read(fd, super, 1024) != 1024) {
                if (devname)