Devicetree
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Loeliger <jdl@freescale.com>
Cc: linuxppc-dev@ozlabs.org, devicetree-discuss@ozlabs.org
Subject: dtc: Check return value from fwrite()
Date: Fri, 7 Nov 2008 11:41:11 +1100	[thread overview]
Message-ID: <20081107004111.GG6692@yookeroo.seuss> (raw)

There's one place in flattree.c where we currently ignore the return
value from fwrite().  On some gcc/glibc versions, where fwrite() is
declared with attribute warn_unused_result, this causes a warning.

This patch fixes the warning, by checking the fwrite() result.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Index: dtc/flattree.c
===================================================================
--- dtc.orig/flattree.c	2008-11-07 11:40:02.000000000 +1100
+++ dtc/flattree.c	2008-11-07 11:40:30.000000000 +1100
@@ -413,10 +413,13 @@ void dt_to_blob(FILE *f, struct boot_inf
 	if (padlen > 0)
 		blob = data_append_zeroes(blob, padlen);
 
-	fwrite(blob.val, blob.len, 1, f);
-
-	if (ferror(f))
-		die("Error writing device tree blob: %s\n", strerror(errno));
+	if (fwrite(blob.val, blob.len, 1, f) != 1) {
+		if (ferror(f))
+			die("Error writing device tree blob: %s\n",
+			    strerror(errno));
+		else
+			die("Short write on device tree blob\n");
+	}
 
 	/*
 	 * data_merge() frees the right-hand element so only the blob

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

             reply	other threads:[~2008-11-07  0:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-07  0:41 David Gibson [this message]
     [not found] ` <20081107004111.GG6692-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-11-17 20:08   ` dtc: Check return value from fwrite() Jon Loeliger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081107004111.GG6692@yookeroo.seuss \
    --to=david@gibson.dropbear.id.au \
    --cc=devicetree-discuss@ozlabs.org \
    --cc=jdl@freescale.com \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox