]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/wireless/p54/eeprom.c
drivers/net/wireless/p54/eeprom.c: Return -ENOMEM on memory allocation failure
[net-next-2.6.git] / drivers / net / wireless / p54 / eeprom.c
index e51650ed49f2ebf0d479785df6aa8071c22ee9bd..35b09aa0529bf6cb6f142680d045c0e894c44df9 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 
 #include <net/mac80211.h>
+#include <linux/crc-ccitt.h>
 
 #include "p54.h"
 #include "eeprom.h"
@@ -149,16 +150,15 @@ static int p54_generate_band(struct ieee80211_hw *dev,
                        continue;
 
                if (list->channels[i].data != CHAN_HAS_ALL) {
-                       printk(KERN_ERR "%s:%s%s%s is/are missing for "
-                                       "channel:%d [%d MHz].\n",
-                              wiphy_name(dev->wiphy),
-                              (list->channels[i].data & CHAN_HAS_CAL ? "" :
-                               " [iqauto calibration data]"),
-                              (list->channels[i].data & CHAN_HAS_LIMIT ? "" :
-                               " [output power limits]"),
-                              (list->channels[i].data & CHAN_HAS_CURVE ? "" :
-                               " [curve data]"),
-                              list->channels[i].index, list->channels[i].freq);
+                       wiphy_err(dev->wiphy,
+                                 "%s%s%s is/are missing for channel:%d [%d MHz].\n",
+                                 (list->channels[i].data & CHAN_HAS_CAL ? "" :
+                                  " [iqauto calibration data]"),
+                                 (list->channels[i].data & CHAN_HAS_LIMIT ? "" :
+                                  " [output power limits]"),
+                                 (list->channels[i].data & CHAN_HAS_CURVE ? "" :
+                                  " [curve data]"),
+                                 list->channels[i].index, list->channels[i].freq);
                        continue;
                }
 
@@ -168,9 +168,8 @@ static int p54_generate_band(struct ieee80211_hw *dev,
        }
 
        if (j == 0) {
-               printk(KERN_ERR "%s: Disabling totally damaged %s band.\n",
-                      wiphy_name(dev->wiphy), (band == IEEE80211_BAND_2GHZ) ?
-                      "2 GHz" : "5 GHz");
+               wiphy_err(dev->wiphy, "Disabling totally damaged %d GHz band\n",
+                         (band == IEEE80211_BAND_2GHZ) ? 2 : 5);
 
                ret = -ENODATA;
                goto err_out;
@@ -244,9 +243,9 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
 
        if ((priv->iq_autocal_len != priv->curve_data->entries) ||
            (priv->iq_autocal_len != priv->output_limit->entries))
-               printk(KERN_ERR "%s: Unsupported or damaged EEPROM detected. "
-                               "You may not be able to use all channels.\n",
-                               wiphy_name(dev->wiphy));
+               wiphy_err(dev->wiphy,
+                         "Unsupported or damaged EEPROM detected. "
+                         "You may not be able to use all channels.\n");
 
        max_channel_num = max_t(unsigned int, priv->output_limit->entries,
                                priv->iq_autocal_len);
@@ -262,8 +261,10 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
        list->max_entries = max_channel_num;
        list->channels = kzalloc(sizeof(struct p54_channel_entry) *
                                 max_channel_num, GFP_KERNEL);
-       if (!list->channels)
+       if (!list->channels) {
+               ret = -ENOMEM;
                goto free;
+       }
 
        for (i = 0; i < max_channel_num; i++) {
                if (i < priv->iq_autocal_len) {
@@ -419,15 +420,14 @@ static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
        int i;
 
        if (len != (entry_size * num_entries)) {
-               printk(KERN_ERR "%s: unknown rssi calibration data packing "
-                                " type:(%x) len:%d.\n",
-                      wiphy_name(dev->wiphy), type, len);
+               wiphy_err(dev->wiphy,
+                         "unknown rssi calibration data packing type:(%x) len:%d.\n",
+                         type, len);
 
                print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
                                     data, len);
 
-               printk(KERN_ERR "%s: please report this issue.\n",
-                       wiphy_name(dev->wiphy));
+               wiphy_err(dev->wiphy, "please report this issue.\n");
                return;
        }
 
@@ -445,15 +445,14 @@ static void p54_parse_default_country(struct ieee80211_hw *dev,
        struct pda_country *country;
 
        if (len != sizeof(*country)) {
-               printk(KERN_ERR "%s: found possible invalid default country "
-                               "eeprom entry. (entry size: %d)\n",
-                      wiphy_name(dev->wiphy), len);
+               wiphy_err(dev->wiphy,
+                         "found possible invalid default country eeprom entry. (entry size: %d)\n",
+                         len);
 
                print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
                                     data, len);
 
-               printk(KERN_ERR "%s: please report this issue.\n",
-                       wiphy_name(dev->wiphy));
+               wiphy_err(dev->wiphy, "please report this issue.\n");
                return;
        }
 
@@ -478,8 +477,8 @@ static int p54_convert_output_limits(struct ieee80211_hw *dev,
                return -EINVAL;
 
        if (data[0] != 0) {
-               printk(KERN_ERR "%s: unknown output power db revision:%x\n",
-                      wiphy_name(dev->wiphy), data[0]);
+               wiphy_err(dev->wiphy, "unknown output power db revision:%x\n",
+                         data[0]);
                return -EINVAL;
        }
 
@@ -544,6 +543,7 @@ int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
        int err;
        u8 *end = (u8 *)eeprom + len;
        u16 synth = 0;
+       u16 crc16 = ~0;
 
        wrap = (struct eeprom_pda_wrap *) eeprom;
        entry = (void *)wrap->data + le16_to_cpu(wrap->len);
@@ -587,10 +587,9 @@ int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                                err = p54_convert_rev1(dev, curve_data);
                                break;
                        default:
-                               printk(KERN_ERR "%s: unknown curve data "
-                                               "revision %d\n",
-                                               wiphy_name(dev->wiphy),
-                                               curve_data->cal_method_rev);
+                               wiphy_err(dev->wiphy,
+                                         "unknown curve data revision %d\n",
+                                         curve_data->cal_method_rev);
                                err = -ENODEV;
                                break;
                        }
@@ -660,20 +659,33 @@ int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                        }
                        break;
                case PDR_END:
-                       /* make it overrun */
-                       entry_len = len;
+                       crc16 = ~crc_ccitt(crc16, (u8 *) entry, sizeof(*entry));
+                       if (crc16 != le16_to_cpup((__le16 *)entry->data)) {
+                               wiphy_err(dev->wiphy, "eeprom failed checksum "
+                                        "test!\n");
+                               err = -ENOMSG;
+                               goto err;
+                       } else {
+                               goto good_eeprom;
+                       }
                        break;
                default:
                        break;
                }
 
-               entry = (void *)entry + (entry_len + 1)*2;
+               crc16 = crc_ccitt(crc16, (u8 *)entry, (entry_len + 1) * 2);
+               entry = (void *)entry + (entry_len + 1) * 2;
        }
 
+       wiphy_err(dev->wiphy, "unexpected end of eeprom data.\n");
+       err = -ENODATA;
+       goto err;
+
+good_eeprom:
        if (!synth || !priv->iq_autocal || !priv->output_limit ||
            !priv->curve_data) {
-               printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
-                       wiphy_name(dev->wiphy));
+               wiphy_err(dev->wiphy,
+                         "not all required entries found in eeprom!\n");
                err = -EINVAL;
                goto err;
        }
@@ -699,15 +711,15 @@ int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
        if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
                u8 perm_addr[ETH_ALEN];
 
-               printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
-                       wiphy_name(dev->wiphy));
+               wiphy_warn(dev->wiphy,
+                          "Invalid hwaddr! Using randomly generated MAC addr\n");
                random_ether_addr(perm_addr);
                SET_IEEE80211_PERM_ADDR(dev, perm_addr);
        }
 
-       printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
-               wiphy_name(dev->wiphy), dev->wiphy->perm_addr, priv->version,
-               p54_rf_chips[priv->rxhw]);
+       wiphy_info(dev->wiphy, "hwaddr %pM, MAC:isl38%02x RF:%s\n",
+                  dev->wiphy->perm_addr, priv->version,
+                  p54_rf_chips[priv->rxhw]);
 
        return 0;
 
@@ -719,8 +731,7 @@ err:
        priv->output_limit = NULL;
        priv->curve_data = NULL;
 
-       printk(KERN_ERR "%s: eeprom parse failed!\n",
-               wiphy_name(dev->wiphy));
+       wiphy_err(dev->wiphy, "eeprom parse failed!\n");
        return err;
 }
 EXPORT_SYMBOL_GPL(p54_parse_eeprom);