const struct argconfig_commandline_options *s;
int c, option_index = 0, short_index = 0, options_count = 0;
void *value_addr;
+ int ret = -EINVAL;
errno = 0;
for (s = options; s->option != NULL; s++)
long_opts = malloc(sizeof(struct option) * (options_count + 2));
short_opts = malloc(sizeof(*short_opts) * (options_count * 3 + 4));
+ if (!long_opts || !short_opts) {
+ fprintf(stderr, "failed to allocate memory for opts: %s\n",
+ strerror(errno));
+ ret = -errno;
+ goto out;
+ }
+
for (s = options; (s->option != NULL) && (option_index < options_count);
s++) {
if (s->short_option != 0) {
out:
free(short_opts);
free(long_opts);
- return -EINVAL;
+ return ret;
}
int argconfig_parse_subopt_string(char *string, char **options,
int i;
struct nvme_dsm_range *dsm = malloc(nr_ranges * sizeof(*dsm));
- if (!dsm)
+ if (!dsm) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
return NULL;
+ }
for (i = 0; i < nr_ranges; i++) {
dsm[i].cattr = cpu_to_le32(ctx_attrs[i]);
dsm[i].nlb = cpu_to_le32(llbas[i]);
int size = getpagesize();
*pbar = malloc(size);
- if (!*pbar)
- return ret;
+ if (!*pbar) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
+ return -ENOMEM;
+ }
memset(*pbar, 0xff, size);
for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ; offset += advance) {
goto error0;
line = malloc(1024);
- if (!line)
+ if (!line) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
goto error0;
+ }
while ((amnt = getline(&line, &size, file)) != -1) {
if (is_comment(line) && !is_class_info(line))
error0:
fclose(file);
error1:
- return strdup("Unknown Device");
+ return !line ? strdup("NULL") : strdup("Unknown Device");
}
hdr = malloc(bs);
page_log = malloc(bs);
if (!hdr || !page_log) {
- fprintf(stderr, "Failed to allocate %zu bytes for log\n", bs);
+ fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n",
+ bs, strerror(errno));
err = ENOMEM;
goto free_mem;
}
log = malloc(cfg.log_len);
if (!log) {
- fprintf(stderr, "could not alloc buffer for log\n");
+ fprintf(stderr, "could not alloc buffer for log: %s\n",
+ strerror(errno));
err = EINVAL;
goto close_fd;
}
if (cfg.metadata_size) {
mbuffer = malloc(cfg.metadata_size);
if (!mbuffer) {
- fprintf(stderr, "can not allocate io metadata payload\n");
+ fprintf(stderr, "can not allocate io metadata "
+ "payload: %s\n", strerror(errno));
err = ENOMEM;
goto free_buffer;
}
if (cfg.metadata_len) {
metadata = malloc(cfg.metadata_len);
if (!metadata) {
- fprintf(stderr, "can not allocate metadata payload\n");
+ fprintf(stderr, "can not allocate metadata "
+ "payload: %s\n", strerror(errno));
err = ENOMEM;
goto close_wfd;
}