On 23 September 2012 07:41, Alexander Graf <ag...@suse.de> wrote: > +void qemu_devtree_dumpdtb(void *fdt, int size) > +{ > + QemuOpts *machine_opts; > + > + machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); > + if (machine_opts) { > + const char *dumpdtb = qemu_opt_get(machine_opts, "dumpdtb");
...maybe we should have a utility function for QemuOpts *opts = qemu_opts_find(qemu_find_opts("machine"), 0); if (!opts) { return NULL; } return qemu_opt_get(opts, optname); because it seems to be quite a common thing and it's a bit dull to have to do that null-pointer check in every place that wants to read a machine option. > + if (dumpdtb) { > + /* Dump the dtb to a file and quit */ > + FILE *f = fopen(dumpdtb, "wb"); ...not checking return value from fopen(). > + size_t len; > + len = fwrite(fdt, size, 1, f); > + fclose(f); ...not checking return value from fclose() (important as it's where we're likely to do the actual writing!). > + if (len != size) { > + exit(1); > + } > + exit(0); Or we could let glib do the heavy lifting: exit(g_file_set_contents(dumpdtb, fdt, size, NULL) ? 0 : 1); -- PMM