[PATCH 11/18] ihex: request_ihex_firmware() function to load and validate firmware

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Date: Saturday, May 31, 2008 - 8:20 am

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

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 00/18] firmware: moving drivers to request_firmwa..., Arkadiusz Miskiewicz, (Thu Jun 5, 6:07 am)
[PATCH 18/18] whiteheat: use request_firmware(), David Woodhouse, (Fri May 30, 6:35 pm)
[PATCH 17/18] ti_usb_3410_5052: use request_firmware(), David Woodhouse, (Fri May 30, 11:49 am)
[PATCH 14/18] keyspan_pda: use request_firmware(), David Woodhouse, (Fri May 30, 8:15 am)
[PATCH 11/18] ihex: request_ihex_firmware() function to load..., David Woodhouse, (Sat May 31, 8:20 am)
[PATCH 10/18] ihex.h: binary representation of ihex records, David Woodhouse, (Fri May 30, 6:57 am)
[PATCH 09/18] ttusb-budget: use request_firmware(), David Woodhouse, (Thu May 29, 12:50 pm)
[PATCH 08/18] kaweth: use request_firmware(), David Woodhouse, (Thu May 29, 10:17 am)
[PATCH 07/18] smctr: use request_firmware(), David Woodhouse, (Thu May 29, 9:39 am)
[PATCH 03/18] firmware: Add 'firmware_install' make target, David Woodhouse, (Thu May 29, 4:01 am)
[PATCH 02/18] firmware: Add CONFIG_BUILTIN_FIRMWARE option, David Woodhouse, (Fri May 23, 8:58 am)