lkml.org 
[lkml]   [2008]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH 11/18] ihex: request_ihex_firmware() function to load and validate firmware
Provide a helper to load the file and validate it in one call, to
simplify error handling in the drivers which are going to use it.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
---
include/linux/ihex.h | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/include/linux/ihex.h b/include/linux/ihex.h
index 3da4855..2f3d8b4 100644
--- a/include/linux/ihex.h
+++ b/include/linux/ihex.h
@@ -9,6 +9,7 @@

#include <linux/types.h>
#include <linux/firmware.h>
+#include <linux/device.h>

struct ihex_binrec {
__be32 addr;
@@ -41,4 +42,27 @@ static inline int ihex_validate_fw(const struct firmware *fw)
}
return 0;
}
+
+/* Request firmware and validate it so that we can trust we won't
+ * run off the end while reading records... */
+static inline int request_ihex_firmware(const struct firmware **fw,
+ const char *fw_name,
+ struct device *dev)
+{
+ const struct firmware *lfw;
+ int ret;
+
+ ret = request_firmware(&lfw, fw_name, dev);
+ if (ret)
+ return ret;
+ ret = ihex_validate_fw(lfw);
+ if (ret) {
+ dev_err(dev, "Firmware \"%s\" not valid IHEX records\n",
+ fw_name);
+ release_firmware(lfw);
+ return ret;
+ }
+ *fw = lfw;
+ return 0;
+}
#endif /* __LINUX_IHEX_H__ */
--
1.5.4.5


\
 
 \ /
  Last update: 2008-06-05 12:01    [W:0.144 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site