qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-ppc] [PATCH 1/2] fdt: move dumpdtb interpretation code to devi


From: Peter Maydell
Subject: Re: [Qemu-ppc] [PATCH 1/2] fdt: move dumpdtb interpretation code to device_tree.c
Date: Mon, 24 Sep 2012 19:02:14 +0100

On 23 September 2012 07:41, Alexander Graf <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]