Check return value when open the plugin file.

Coverity report:
** CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
/tools/imximage.c: 542 in copy_plugin_code()

   ifd = open(plugin_file, O_RDONLY|O_BINARY);
>>>  CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
>>> "ifd" is passed to a parameter that cannot be negative.

Signed-off-by: Peng Fan <peng....@nxp.com>
Cc: Stefano Babic <sba...@denx.de>
Cc: Tom Rini <tr...@konsulko.com>
---
 tools/imximage.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/imximage.c b/tools/imximage.c
index 615a64e..c9e42ec 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -533,12 +533,19 @@ static void print_hdr_v2(struct imx_header *imx_hdr)
 
 static void copy_plugin_code(struct imx_header *imxhdr, char *plugin_file)
 {
-       int ifd = -1;
+       int ifd;
        struct stat sbuf;
        char *plugin_buf = imxhdr->header.hdr_v2.data.plugin_code;
        char *ptr;
 
        ifd = open(plugin_file, O_RDONLY|O_BINARY);
+       if (ifd < 0) {
+               fprintf(stderr, "Can't open %s: %s\n",
+                       plugin_file,
+                       strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
        if (fstat(ifd, &sbuf) < 0) {
                fprintf(stderr, "Can't stat %s: %s\n",
                        plugin_file,
-- 
2.6.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to