From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Sat, 8 Feb 2014 15:16:26 +0100 Subject: [U-Boot] [PATCH 6/7] tools, fit: add fit_info host command In-Reply-To: <1390632269-8971-7-git-send-email-hs@denx.de> References: <1390632269-8971-1-git-send-email-hs@denx.de> <1390632269-8971-7-git-send-email-hs@denx.de> Message-ID: <201402081516.26168.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Saturday, January 25, 2014 at 07:44:28 AM, Heiko Schocher wrote: > add fit_info command to the host tools. This command prints > the name, offset and the len from a property from a node in > a fit file. This info can be used to extract a properties > data with linux tools, for example "dd". > > Signed-off-by: Heiko Schocher [...] > +int mmap_fdt(char *cmdname, const char *fname, void **blobp, > + struct stat *sbuf) > +{ > + void *ptr; > + int fd; > + > + /* Load FIT blob into memory (we need to write hashes/signatures) */ > + fd = open(fname, O_RDWR | O_BINARY); > + > + if (fd < 0) { > + fprintf(stderr, "%s: Can't open %s: %s\n", > + cmdname, fname, strerror(errno)); > + unlink(fname); Are you sure about this unlink() call here ? The unlink() might delete the file, dunno if that was intended ;-) > + return -1; > + } > + > + if (fstat(fd, sbuf) < 0) { > + fprintf(stderr, "%s: Can't stat %s: %s\n", > + cmdname, fname, strerror(errno)); > + unlink(fname); > + return -1; > + } > + > + ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); > + if (ptr == MAP_FAILED) { > + fprintf(stderr, "%s: Can't read %s: %s\n", > + cmdname, fname, strerror(errno)); > + unlink(fname); Here this might be a problem ;-) Also, make sure to set errno = 0 before mmap() and check the errno afterwards here too. [...] Best regards, Marek Vasut