OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / net / wireless / rt2x00 / rt2x00firmware.c
blobf316aad30612d53ac70e22874740f02a09091273
1 /*
2 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3 Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
4 <http://rt2x00.serialmonkey.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the
18 Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Module: rt2x00lib
24 Abstract: rt2x00 firmware loading routines.
27 #include <linux/kernel.h>
28 #include <linux/module.h>
30 #include "rt2x00.h"
31 #include "rt2x00lib.h"
33 static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
35 struct device *device = wiphy_dev(rt2x00dev->hw->wiphy);
36 const struct firmware *fw;
37 char *fw_name;
38 int retval;
41 * Read correct firmware from harddisk.
43 fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev);
44 if (!fw_name) {
45 ERROR(rt2x00dev,
46 "Invalid firmware filename.\n"
47 "Please file bug report to %s.\n", DRV_PROJECT);
48 return -EINVAL;
51 INFO(rt2x00dev, "Loading firmware file '%s'.\n", fw_name);
53 retval = request_firmware(&fw, fw_name, device);
54 if (retval) {
55 ERROR(rt2x00dev, "Failed to request Firmware.\n");
56 return retval;
59 if (!fw || !fw->size || !fw->data) {
60 ERROR(rt2x00dev, "Failed to read Firmware.\n");
61 release_firmware(fw);
62 return -ENOENT;
65 INFO(rt2x00dev, "Firmware detected - version: %d.%d.\n",
66 fw->data[fw->size - 4], fw->data[fw->size - 3]);
67 snprintf(rt2x00dev->hw->wiphy->fw_version,
68 sizeof(rt2x00dev->hw->wiphy->fw_version), "%d.%d",
69 fw->data[fw->size - 4], fw->data[fw->size - 3]);
71 retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size);
72 switch (retval) {
73 case FW_OK:
74 break;
75 case FW_BAD_CRC:
76 ERROR(rt2x00dev, "Firmware checksum error.\n");
77 goto exit;
78 case FW_BAD_LENGTH:
79 ERROR(rt2x00dev,
80 "Invalid firmware file length (len=%zu)\n", fw->size);
81 goto exit;
82 case FW_BAD_VERSION:
83 ERROR(rt2x00dev,
84 "Current firmware does not support detected chipset.\n");
85 goto exit;
88 rt2x00dev->fw = fw;
90 return 0;
92 exit:
93 release_firmware(fw);
95 return -ENOENT;
98 int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
100 int retval;
102 if (!test_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags))
103 return 0;
105 if (!rt2x00dev->fw) {
106 retval = rt2x00lib_request_firmware(rt2x00dev);
107 if (retval)
108 return retval;
112 * Send firmware to the device.
114 retval = rt2x00dev->ops->lib->load_firmware(rt2x00dev,
115 rt2x00dev->fw->data,
116 rt2x00dev->fw->size);
119 * When the firmware is uploaded to the hardware the LED
120 * association status might have been triggered, for correct
121 * LED handling it should now be reset.
123 rt2x00leds_led_assoc(rt2x00dev, false);
125 return retval;
128 void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
130 release_firmware(rt2x00dev->fw);
131 rt2x00dev->fw = NULL;