From patchwork Fri Nov 7 00:41:11 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 7645 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id B426BDDECF for ; Fri, 7 Nov 2008 11:41:53 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: by ozlabs.org (Postfix, from userid 1007) id D9678DDE22; Fri, 7 Nov 2008 11:41:13 +1100 (EST) Date: Fri, 7 Nov 2008 11:41:11 +1100 From: David Gibson To: Jon Loeliger Subject: dtc: Check return value from fwrite() Message-ID: <20081107004111.GG6692@yookeroo.seuss> Mail-Followup-To: Jon Loeliger , devicetree-discuss@ozlabs.org, linuxppc-dev@ozlabs.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Cc: linuxppc-dev@ozlabs.org, devicetree-discuss@ozlabs.org X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org 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 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