summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2023-03-14 20:32:29 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-03 00:31:28 +0000
commit14361dea4894f75646db14ec00f5e9cbe7a954f4 (patch)
tree0c1532356e60e85a3234de077033d609849e8135
parentb352faae79b45e24c178fa6ab03134662df84b41 (diff)
downloadvboot-14361dea4894f75646db14ec00f5e9cbe7a954f4.tar.gz
futility/cmd_*: Cleanups for maintainability
Fix many mistyping of indexers and other itermediate variables. BUG=b:268397597 TEST=`emerge-nissa vboot_reference`. TEST=`cros_run_unit_tests --host --packages vboot_reference`. TEST=`cros_run_unit_tests --board nissa --packages vboot_reference`. Change-Id: I49cc0e1a3e5d455c7f473e31cba528e8f227dfb6 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4349562 Reviewed-by: Sam McNally <sammc@chromium.org> Tested-by: Edward O'Callaghan <quasisec@chromium.org> Commit-Queue: Sam McNally <sammc@chromium.org> Auto-Submit: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/cmd_create.c4
-rw-r--r--futility/cmd_dump_fmap.c73
-rw-r--r--futility/cmd_gbb_utility.c57
-rw-r--r--futility/cmd_load_fmap.c37
-rw-r--r--futility/cmd_pcr.c12
-rw-r--r--futility/cmd_read.c6
-rw-r--r--futility/cmd_show.c2
-rw-r--r--futility/cmd_update.c3
-rw-r--r--futility/cmd_vbutil_kernel.c4
-rw-r--r--futility/cmd_vbutil_key.c6
10 files changed, 87 insertions, 117 deletions
diff --git a/futility/cmd_create.c b/futility/cmd_create.c
index a3b10bba..cf94a1b9 100644
--- a/futility/cmd_create.c
+++ b/futility/cmd_create.c
@@ -126,7 +126,7 @@ static int vb1_make_keypair(void)
/* Write it out */
strcpy(outext, ".vbprivk");
- if (0 != vb2_write_private_key(outfile, privkey)) {
+ if (vb2_write_private_key(outfile, privkey)) {
ERROR("Unable to write private key\n");
goto done;
}
@@ -187,7 +187,7 @@ static int vb2_make_keypair(void)
if (!rsa_key) {
/* Check if the PEM contains only a public key */
- if (0 != fseek(fp, 0, SEEK_SET)) {
+ if (fseek(fp, 0, SEEK_SET)) {
ERROR("Seeking in %s\n", infile);
goto done;
}
diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c
index f5e172e7..cd63b8db 100644
--- a/futility/cmd_dump_fmap.c
+++ b/futility/cmd_dump_fmap.c
@@ -32,10 +32,9 @@ static int opt_gaps;
/* Return 0 if successful */
static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
{
- int i, retval = 0;
+ int retval = 0;
char buf[80]; /* DWR: magic number */
- const FmapAreaHeader *ah;
- ah = (const FmapAreaHeader *) (fmh + 1);
+ const FmapAreaHeader *ah = (const FmapAreaHeader *) (fmh + 1);
/* Size must greater than 0, else behavior is undefined. */
char *extract_names[argc >= 1 ? argc : 1];
char *outname = 0;
@@ -44,7 +43,7 @@ static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
if (opt_extract) {
/* prepare the filenames to write areas to */
- for (i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; i++) {
char *a = argv[i];
char *f = strchr(a, ':');
if (!f)
@@ -75,13 +74,13 @@ static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
printf("fmap_nareas: %d\n", fmh->fmap_nareas);
}
- for (i = 0; i < fmh->fmap_nareas; i++, ah++) {
+ for (uint16_t i = 0; i < fmh->fmap_nareas; i++, ah++) {
snprintf(buf, FMAP_NAMELEN + 1, "%s", ah->area_name);
if (argc) {
- int j, found = 0;
+ int found = 0;
outname = NULL;
- for (j = 0; j < argc; j++)
+ for (int j = 0; j < argc; j++)
if (!strcmp(argv[j], buf)) {
found = 1;
outname = extract_names[j];
@@ -172,14 +171,11 @@ static struct node_s *all_nodes;
static void sort_nodes(int num, struct node_s *ary[])
{
- int i, j;
- struct node_s *tmp;
-
/* bubble-sort is quick enough with only a few entries */
- for (i = 0; i < num; i++) {
- for (j = i + 1; j < num; j++) {
+ for (unsigned int i = 0; i < num; i++) {
+ for (unsigned int j = i + 1; j < num; j++) {
if (ary[j]->start > ary[i]->start) {
- tmp = ary[i];
+ struct node_s *tmp = ary[i];
ary[i] = ary[j];
ary[j] = tmp;
}
@@ -190,8 +186,7 @@ static void sort_nodes(int num, struct node_s *ary[])
static void line(int indent, const char *name, uint32_t start, uint32_t end,
uint32_t size, const char *append)
{
- int i;
- for (i = 0; i < indent; i++)
+ for (int i = 0; i < indent; i++)
printf(" ");
printf("%-25s %08x %08x %08x%s\n", name, start, end, size,
append ? append : "");
@@ -210,7 +205,6 @@ static void empty(int indent, uint32_t start, uint32_t end, char *name)
static void show(struct node_s *p, int indent, int show_first)
{
- int i;
struct dup_s *alias;
if (show_first) {
line(indent, p->name, p->start, p->end, p->size, 0);
@@ -219,7 +213,7 @@ static void show(struct node_s *p, int indent, int show_first)
" // DUPLICATE");
}
sort_nodes(p->num_children, p->child);
- for (i = 0; i < p->num_children; i++) {
+ for (unsigned int i = 0; i < p->num_children; i++) {
if (i == 0 && p->end != p->child[i]->end)
empty(indent, p->child[i]->end, p->end, p->name);
show(p->child[i], indent + show_first, 1);
@@ -259,20 +253,16 @@ static int duplicates(int i, int j)
static void add_dupe(int i, int j, int numnodes)
{
- int k;
- struct dup_s *alias;
-
- alias = (struct dup_s *) malloc(sizeof(struct dup_s));
+ struct dup_s *alias = (struct dup_s *) malloc(sizeof(struct dup_s));
alias->name = all_nodes[j].name;
alias->next = all_nodes[i].alias;
all_nodes[i].alias = alias;
- for (k = j; k < numnodes; k++)
+ for (int k = j; k < numnodes; k++)
all_nodes[k] = all_nodes[k + 1];
}
static void add_child(struct node_s *p, int n)
{
- int i;
if (p->num_children && !p->child) {
p->child =
(struct node_s **)calloc(p->num_children,
@@ -282,20 +272,19 @@ static void add_child(struct node_s *p, int n)
exit(1);
}
}
- for (i = 0; i < p->num_children; i++)
+ for (unsigned int i = 0; i < p->num_children; i++) {
if (!p->child[i]) {
p->child[i] = all_nodes + n;
return;
}
+ }
}
static int human_fmap(const FmapHeader *fmh)
{
- FmapAreaHeader *ah;
- int i, j, errorcnt = 0;
- int numnodes;
+ int errorcnt = 0;
- ah = (FmapAreaHeader *) (fmh + 1);
+ FmapAreaHeader *ah = (FmapAreaHeader *) (fmh + 1);
/* The challenge here is to generate a directed graph from the
* arbitrarily-ordered FMAP entries, and then to prune it until it's as
@@ -303,7 +292,7 @@ static int human_fmap(const FmapHeader *fmh)
* Duplicate regions are okay, but may require special handling. */
/* Convert the FMAP info into our format. */
- numnodes = fmh->fmap_nareas;
+ uint16_t numnodes = fmh->fmap_nareas;
/* plus one for the all-enclosing "root" */
all_nodes = (struct node_s *) calloc(numnodes + 1,
@@ -312,7 +301,7 @@ static int human_fmap(const FmapHeader *fmh)
perror("calloc failed");
exit(1);
}
- for (i = 0; i < numnodes; i++) {
+ for (uint16_t i = 0; i < numnodes; i++) {
char buf[FMAP_NAMELEN + 1];
strncpy(buf, ah[i].area_name, FMAP_NAMELEN);
buf[FMAP_NAMELEN] = '\0';
@@ -332,8 +321,8 @@ static int human_fmap(const FmapHeader *fmh)
all_nodes[numnodes].end = fmh->fmap_base + fmh->fmap_size;
/* First, coalesce any duplicates */
- for (i = 0; i < numnodes; i++) {
- for (j = i + 1; j < numnodes; j++) {
+ for (uint16_t i = 0; i < numnodes; i++) {
+ for (uint16_t j = i + 1; j < numnodes; j++) {
if (duplicates(i, j)) {
add_dupe(i, j, numnodes);
numnodes--;
@@ -345,10 +334,10 @@ static int human_fmap(const FmapHeader *fmh)
* enclosing node. Duplicate nodes "enclose" each other, but if there's
* already a relationship in one direction, we won't create another.
*/
- for (i = 0; i < numnodes; i++) {
+ for (uint16_t i = 0; i < numnodes; i++) {
/* Find the smallest parent, which might be the root node. */
int k = numnodes;
- for (j = 0; j < numnodes; j++) { /* full O(N^2) comparison */
+ for (uint16_t j = 0; j < numnodes; j++) { /* full O(N^2) comparison */
if (i == j)
continue;
if (overlaps(i, j)) {
@@ -375,10 +364,10 @@ static int human_fmap(const FmapHeader *fmh)
return 1;
/* Force those deadbeat parents to recognize their children */
- for (i = 0; i < numnodes; i++) /* how many */
+ for (uint16_t i = 0; i < numnodes; i++) /* how many */
if (all_nodes[i].parent)
all_nodes[i].parent->num_children++;
- for (i = 0; i < numnodes; i++) /* here they are */
+ for (uint16_t i = 0; i < numnodes; i++) /* here they are */
if (all_nodes[i].parent)
add_child(all_nodes[i].parent, i);
@@ -425,9 +414,6 @@ static int do_dump_fmap(int argc, char *argv[])
{
int c;
int errorcnt = 0;
- struct stat sb;
- int fd;
- const FmapHeader *fmap;
int retval = 1;
opterr = 0; /* quiet, you */
@@ -473,14 +459,15 @@ static int do_dump_fmap(int argc, char *argv[])
return 1;
}
- fd = open(argv[optind], O_RDONLY);
+ int fd = open(argv[optind], O_RDONLY);
if (fd < 0) {
ERROR("%s: can't open %s: %s\n",
argv[0], argv[optind], strerror(errno));
return 1;
}
- if (0 != fstat(fd, &sb)) {
+ struct stat sb;
+ if (fstat(fd, &sb)) {
ERROR("%s: can't stat %s: %s\n",
argv[0], argv[optind], strerror(errno));
close(fd);
@@ -498,7 +485,7 @@ static int do_dump_fmap(int argc, char *argv[])
close(fd); /* done with this now */
size_of_rom = sb.st_size;
- fmap = fmap_find(base_of_rom, size_of_rom);
+ const FmapHeader *fmap = fmap_find(base_of_rom, size_of_rom);
if (fmap) {
switch (opt_format) {
case FMT_HUMAN:
@@ -515,7 +502,7 @@ static int do_dump_fmap(int argc, char *argv[])
}
}
- if (0 != munmap(base_of_rom, sb.st_size)) {
+ if (munmap(base_of_rom, sb.st_size)) {
ERROR("%s: can't munmap %s: %s\n",
argv[0], argv[optind], strerror(errno));
return 1;
diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c
index 5f957a59..8cd02de0 100644
--- a/futility/cmd_gbb_utility.c
+++ b/futility/cmd_gbb_utility.c
@@ -123,12 +123,12 @@ static const char *short_opts = ":gsc:o:k:b:r:e" SHARED_FLASH_ARGS_SHORTOPTS;
/* Change the has_arg field of a long_opts entry */
static void opt_has_arg(const char *name, int val)
{
- struct option *p;
- for (p = long_opts; p->name; p++)
+ for (struct option *p = long_opts; p->name; p++) {
if (!strcmp(name, p->name)) {
p->has_arg = val;
break;
}
+ }
}
#define GBB_SEARCH_STRIDE 4
@@ -139,8 +139,7 @@ static struct vb2_gbb_header *FindGbbHeader(uint8_t *ptr, size_t size)
int count = 0;
for (i = 0; i <= size - GBB_SEARCH_STRIDE; i += GBB_SEARCH_STRIDE) {
- if (0 != memcmp(ptr + i, VB2_GBB_SIGNATURE,
- VB2_GBB_SIGNATURE_SIZE))
+ if (memcmp(ptr + i, VB2_GBB_SIGNATURE, VB2_GBB_SIGNATURE_SIZE))
continue;
/* Found something. See if it's any good. */
@@ -163,21 +162,19 @@ static struct vb2_gbb_header *FindGbbHeader(uint8_t *ptr, size_t size)
static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
{
- char *str, *sizes, *param, *e = NULL;
+ char *param, *e = NULL;
size_t size = EXPECTED_VB2_GBB_HEADER_SIZE;
int i = 0;
/* Danger Will Robinson! four entries ==> four paramater blocks */
uint32_t val[] = { 0, 0, 0, 0 };
- uint8_t *buf;
- struct vb2_gbb_header *gbb;
- sizes = strdup(desc);
+ char *sizes = strdup(desc);
if (!sizes) {
ERROR("strdup() failed: %s\n", strerror(errno));
return NULL;
}
- for (str = sizes; (param = strtok(str, ", ")) != NULL; str = NULL) {
+ for (char *str = sizes; (param = strtok(str, ", ")) != NULL; str = NULL) {
val[i] = (uint32_t) strtoul(param, &e, 0);
if (e && *e) {
ERROR("Invalid creation parameter: \"%s\"\n", param);
@@ -189,7 +186,7 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
break;
}
- buf = (uint8_t *) calloc(1, size);
+ uint8_t *buf = (uint8_t *) calloc(1, size);
if (!buf) {
ERROR("Can't malloc %zu bytes: %s\n", size, strerror(errno));
free(sizes);
@@ -198,7 +195,7 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
if (sizeptr)
*sizeptr = size;
- gbb = (struct vb2_gbb_header *) buf;
+ struct vb2_gbb_header *gbb = (struct vb2_gbb_header *) buf;
memcpy(gbb->signature, VB2_GBB_SIGNATURE, VB2_GBB_SIGNATURE_SIZE);
gbb->major_version = VB2_GBB_MAJOR_VER;
gbb->minor_version = VB2_GBB_MINOR_VER;
@@ -228,18 +225,17 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
static uint8_t *read_entire_file(const char *filename, off_t *sizeptr)
{
- FILE *fp = NULL;
uint8_t *buf = NULL;
struct stat sb;
- fp = fopen(filename, "rb");
+ FILE *fp = fopen(filename, "rb");
if (!fp) {
ERROR("Unable to open %s for reading: %s\n", filename,
strerror(errno));
goto fail;
}
- if (0 != fstat(fileno(fp), &sb)) {
+ if (fstat(fileno(fp), &sb)) {
ERROR("Can't fstat %s: %s\n", filename, strerror(errno));
goto fail;
}
@@ -259,7 +255,7 @@ static uint8_t *read_entire_file(const char *filename, off_t *sizeptr)
goto fail;
}
- if (0 != fclose(fp)) {
+ if (fclose(fp)) {
ERROR("Unable to close %s: %s\n", filename, strerror(errno));
fp = NULL; /* Don't try to close it again */
goto fail;
@@ -271,7 +267,7 @@ fail:
if (buf)
free(buf);
- if (fp && 0 != fclose(fp))
+ if (fp && fclose(fp))
ERROR("Unable to close %s: %s\n", filename, strerror(errno));
return NULL;
}
@@ -279,19 +275,18 @@ fail:
static int read_from_file(const char *msg, const char *filename,
uint8_t *start, uint32_t size)
{
- FILE *fp;
struct stat sb;
size_t count;
int r = 0;
- fp = fopen(filename, "rb");
+ FILE *fp = fopen(filename, "rb");
if (!fp) {
r = errno;
ERROR("Unable to open %s for reading: %s\n", filename, strerror(r));
return r;
}
- if (0 != fstat(fileno(fp), &sb)) {
+ if (fstat(fileno(fp), &sb)) {
r = errno;
ERROR("Can't fstat %s: %s\n", filename, strerror(r));
goto done_close;
@@ -315,7 +310,7 @@ static int read_from_file(const char *msg, const char *filename,
}
done_close:
- if (0 != fclose(fp)) {
+ if (fclose(fp)) {
int e = errno;
ERROR("Unable to close %s: %s\n", filename, strerror(e));
if (!r)
@@ -461,15 +456,13 @@ static int do_gbb(int argc, char *argv[])
char *opt_recoverykey = NULL;
char *opt_hwid = NULL;
char *opt_flags = NULL;
- int sel_hwid = 0;
- int sel_digest = 0;
- int sel_flags = 0;
+ bool sel_hwid = false;
+ bool sel_digest = false;
+ bool sel_flags = false;
int explicit_flags = 0;
uint8_t *inbuf = NULL;
off_t filesize;
uint8_t *outbuf = NULL;
- struct vb2_gbb_header *gbb;
- uint8_t *gbb_base;
int i;
struct updater_config *cfg = NULL;
struct updater_config_arguments args = {0};
@@ -514,19 +507,19 @@ static int do_gbb(int argc, char *argv[])
case OPT_HWID:
/* --hwid is optional: null might be okay */
opt_hwid = optarg;
- sel_hwid = 1;
+ sel_hwid = true;
break;
case OPT_FLAGS:
/* --flags is optional: null might be okay */
opt_flags = optarg;
- sel_flags = 1;
+ sel_flags = true;
break;
case 'e':
- sel_flags = 1;
+ sel_flags = true;
explicit_flags = 1;
break;
case OPT_DIGEST:
- sel_digest = 1;
+ sel_digest = true;
break;
case OPT_FLASH:
#ifndef USE_FLASHROM
@@ -599,15 +592,15 @@ static int do_gbb(int argc, char *argv[])
/* With no args, show the HWID */
if (!opt_rootkey && !opt_bmpfv && !opt_recoverykey
&& !sel_flags && !sel_digest)
- sel_hwid = 1;
+ sel_hwid = true;
- gbb = FindGbbHeader(inbuf, filesize);
+ struct vb2_gbb_header *gbb = FindGbbHeader(inbuf, filesize);
if (!gbb) {
ERROR("No GBB found in %s\n", infile);
errorcnt++;
break;
}
- gbb_base = (uint8_t *) gbb;
+ uint8_t *gbb_base = (uint8_t *) gbb;
/* Get the stuff */
if (sel_hwid)
diff --git a/futility/cmd_load_fmap.c b/futility/cmd_load_fmap.c
index 4828415c..5e75d655 100644
--- a/futility/cmd_load_fmap.c
+++ b/futility/cmd_load_fmap.c
@@ -54,21 +54,20 @@ static const struct option long_opts[] = {
static const char *short_opts = ":o:";
-static int copy_to_area(char *file, uint8_t *buf, uint32_t len, char *area)
+static int copy_to_area(const char *file, uint8_t *buf,
+ const uint32_t len, const char *area)
{
- FILE *fp;
int retval = 0;
- int n;
- fp = fopen(file, "r");
+ FILE *fp = fopen(file, "r");
if (!fp) {
ERROR("area %s: can't open %s for reading: %s\n",
area, file, strerror(errno));
return 1;
}
- n = fread(buf, 1, len, fp);
- if (n == 0) {
+ size_t n = fread(buf, 1, len, fp);
+ if (!n) {
if (feof(fp))
ERROR("area %s: unexpected EOF on %s\n", area, file);
if (ferror(fp))
@@ -76,11 +75,11 @@ static int copy_to_area(char *file, uint8_t *buf, uint32_t len, char *area)
area, file, strerror(errno));
retval = 1;
} else if (n < len) {
- ERROR("Warning on area %s: only read %d "
+ ERROR("Warning on area %s: only read %zu "
"(not %d) from %s\n", area, n, len, file);
}
- if (0 != fclose(fp)) {
+ if (fclose(fp)) {
ERROR("area %s: error closing %s: %s\n",
area, file, strerror(errno));
retval = 1;
@@ -92,14 +91,9 @@ static int copy_to_area(char *file, uint8_t *buf, uint32_t len, char *area)
static int do_load_fmap(int argc, char *argv[])
{
- char *infile = 0;
- char *outfile = 0;
- uint8_t *buf;
- uint32_t len;
- FmapHeader *fmap;
- FmapAreaHeader *ah;
+ char *outfile = NULL;
int errorcnt = 0;
- int fd, i;
+ int i;
opterr = 0; /* quiet, you */
while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) {
@@ -139,20 +133,23 @@ static int do_load_fmap(int argc, char *argv[])
return 1;
}
- infile = argv[optind++];
+ const char *infile = argv[optind++];
/* okay, let's do it ... */
if (!outfile)
- outfile = infile;
+ outfile = (char *)infile;
else
if (futil_copy_file(infile, outfile) < 0)
exit(1);
+ int fd;
+ uint8_t *buf;
+ uint32_t len;
errorcnt |= futil_open_and_map_file(outfile, &fd, FILE_RW, &buf, &len);
if (errorcnt)
goto done;
- fmap = fmap_find(buf, len);
+ FmapHeader *fmap = fmap_find(buf, len);
if (!fmap) {
ERROR("Can't find an FMAP in %s\n", infile);
errorcnt++;
@@ -169,6 +166,8 @@ static int do_load_fmap(int argc, char *argv[])
break;
}
*f++ = '\0';
+
+ FmapAreaHeader *ah;
uint8_t *area_buf = fmap_find_by_name(buf, len, fmap, a, &ah);
if (!area_buf) {
ERROR("Can't find area \"%s\" in FMAP\n", a);
@@ -176,7 +175,7 @@ static int do_load_fmap(int argc, char *argv[])
break;
}
- if (0 != copy_to_area(f, area_buf, ah->area_size, a)) {
+ if (copy_to_area(f, area_buf, ah->area_size, a)) {
errorcnt++;
break;
}
diff --git a/futility/cmd_pcr.c b/futility/cmd_pcr.c
index eb514b3d..6662213b 100644
--- a/futility/cmd_pcr.c
+++ b/futility/cmd_pcr.c
@@ -40,10 +40,9 @@ static void print_help(int argc, char *argv[])
printf(usage, argv[0], argv[0], argv[0]);
}
-static void print_digest(const uint8_t *buf, int len)
+static void print_digest(const uint8_t *buf, size_t len)
{
- int i;
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
printf("%02x", buf[i]);
}
@@ -57,9 +56,8 @@ static const struct option long_opts[] = {
static int do_pcr(int argc, char *argv[])
{
uint8_t accum[VB2_MAX_DIGEST_SIZE * 2];
- uint8_t pcr[VB2_MAX_DIGEST_SIZE];
+ uint8_t pcr[VB2_MAX_DIGEST_SIZE] = {0};
int digest_alg = VB2_HASH_SHA1;
- int digest_size;
int opt_init = 0;
int errorcnt = 0;
int i;
@@ -104,9 +102,7 @@ static int do_pcr(int argc, char *argv[])
return 1;
}
- memset(pcr, 0, sizeof(pcr));
-
- digest_size = vb2_digest_size(digest_alg);
+ int digest_size = vb2_digest_size(digest_alg);
if (!digest_size) {
ERROR("Cannot determine digest size!\n");
return 1;
diff --git a/futility/cmd_read.c b/futility/cmd_read.c
index 46f4bfdb..84b82034 100644
--- a/futility/cmd_read.c
+++ b/futility/cmd_read.c
@@ -41,15 +41,13 @@ static void print_help(int argc, char *argv[])
static int do_read(int argc, char *argv[])
{
- struct updater_config *cfg;
struct updater_config_arguments args = {0};
int i, errorcnt = 0, update_needed = 1;
const char *prepare_ctrl_name = NULL;
char *servo_programmer = NULL;
- char *output_file_name = NULL;
char *region = NULL;
- cfg = updater_new_config();
+ struct updater_config *cfg = updater_new_config();
assert(cfg);
opterr = 0;
@@ -91,7 +89,7 @@ static int do_read(int argc, char *argv[])
print_help(argc, argv);
return 1;
}
- output_file_name = argv[optind++];
+ const char *output_file_name = argv[optind++];
if (optind < argc) {
errorcnt++;
ERROR("Unexpected arguments.\n");
diff --git a/futility/cmd_show.c b/futility/cmd_show.c
index 7fb1c849..cedd45de 100644
--- a/futility/cmd_show.c
+++ b/futility/cmd_show.c
@@ -161,7 +161,7 @@ int ft_show_keyblock(const char *name, void *data)
return 1;
/* Check the hash only first */
- if (0 != vb2_verify_keyblock_hash(block, len, &wb)) {
+ if (vb2_verify_keyblock_hash(block, len, &wb)) {
printf("%s is invalid\n", name);
retval = 1;
goto done;
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index 14858f33..554a8b4a 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -141,14 +141,13 @@ static void print_help(int argc, char *argv[])
static int do_update(int argc, char *argv[])
{
- struct updater_config *cfg;
struct updater_config_arguments args = {0};
int i, errorcnt = 0, update_needed = 1;
const char *prepare_ctrl_name = NULL;
char *servo_programmer = NULL;
char *endptr;
- cfg = updater_new_config();
+ struct updater_config *cfg = updater_new_config();
assert(cfg);
opterr = 0;
diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c
index 0f470ccc..27dfc380 100644
--- a/futility/cmd_vbutil_kernel.c
+++ b/futility/cmd_vbutil_kernel.c
@@ -168,7 +168,7 @@ static uint8_t *ReadOldKPartFromFileOrDie(const char *filename,
uint8_t *buf;
uint32_t file_size = 0;
- if (0 != stat(filename, &statbuf))
+ if (stat(filename, &statbuf))
FATAL("Unable to stat %s: %s\n", filename, strerror(errno));
if (S_ISBLK(statbuf.st_mode)) {
@@ -502,7 +502,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
ReadConfigFile(config_file, &t_config_size);
if (!t_config_data)
FATAL("Error reading config file.\n");
- if (0 != UpdateKernelBlobConfig(
+ if (UpdateKernelBlobConfig(
kblob_data, kblob_size,
t_config_data, t_config_size))
FATAL("Unable to update config\n");
diff --git a/futility/cmd_vbutil_key.c b/futility/cmd_vbutil_key.c
index e98066c1..9d2af87a 100644
--- a/futility/cmd_vbutil_key.c
+++ b/futility/cmd_vbutil_key.c
@@ -42,8 +42,6 @@ static const struct option long_opts[] = {
static void print_help(int argc, char *argv[])
{
- int i;
-
printf("\n"
"Usage: " MYNAME " %s --pack <outfile> [PARAMETERS]\n"
"\n"
@@ -55,7 +53,7 @@ static void print_help(int argc, char *argv[])
" --algorithm <number> "
"Signing algorithm to use with key:\n", argv[0]);
- for (i = 0; i < VB2_ALG_COUNT; i++) {
+ for (enum vb2_crypto_algorithm i = 0; i < VB2_ALG_COUNT; i++) {
printf(" %d = (%s)\n",
i, vb2_get_crypto_algorithm_name(i));
}
@@ -80,7 +78,7 @@ static int do_pack(const char *infile, const char *outfile, uint32_t algorithm,
struct vb2_packed_key *pubkey =
vb2_read_packed_keyb(infile, algorithm, version);
if (pubkey) {
- if (0 != vb2_write_packed_key(outfile, pubkey)) {
+ if (vb2_write_packed_key(outfile, pubkey)) {
ERROR("vbutil_key: Error writing key.\n");
free(pubkey);
return 1;