Double pointers obfuscate code, die
authorLuis R. Rodriguez <lrodriguez@atheros.com>
Wed, 29 Oct 2008 08:53:13 +0000 (01:53 -0700)
committerLuis R. Rodriguez <lrodriguez@atheros.com>
Wed, 29 Oct 2008 08:53:13 +0000 (01:53 -0700)
Lets make country2rd() easier to read by not using
double pointers.

Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
dump.c
reglib.c
reglib.h

diff --git a/dump.c b/dump.c
index 0ddf659..51f99bc 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -76,8 +76,9 @@ int main(int argc, char **argv)
        for (i = 0; i < num_countries; i++) {
                struct regdb_file_reg_country *country = countries + i;
 
-               r = country2rd(db, dblen, country, &rd);
-               if (r) {
+               rd = country2rd(db, dblen, country);
+               if (!rd) {
+                       r = -ENOMEM;
                        fprintf(stderr, "Could not covert country "
                        "(%.2s) to rd\n", country->alpha2);
                        goto out;
index feb4af8..e6b9b3f 100644 (file)
--- a/reglib.c
+++ b/reglib.c
@@ -158,9 +158,8 @@ void reg_rule2rd(__u8 *db, int dblen,
 }
 
 /* Converts a file regdomain to ieee80211_regdomain, easier to manage */
-int country2rd(__u8 *db, int dblen,
-       struct regdb_file_reg_country *country,
-       struct ieee80211_regdomain **rdp)
+struct ieee80211_regdomain *country2rd(__u8 *db, int dblen,
+       struct regdb_file_reg_country *country)
 {
        struct regdb_file_reg_rules_collection *rcoll;
        struct ieee80211_regdomain *rd;
@@ -177,11 +176,9 @@ int country2rd(__u8 *db, int dblen,
        size_of_rd = sizeof(struct ieee80211_regdomain) +
                num_rules * sizeof(struct ieee80211_reg_rule);
 
-       *rdp = malloc(size_of_rd);
-       if (!*rdp)
-               return -ENOMEM;
-
-       rd = *rdp;
+       rd = malloc(size_of_rd);
+       if (!rd)
+               return NULL;
 
        memset(rd, 0, size_of_rd);
 
@@ -194,7 +191,7 @@ int country2rd(__u8 *db, int dblen,
                        &rd->reg_rules[i]);
        }
 
-       return 0;
+       return rd;
 }
 
 /* Sanity check on a regulatory rule */
index 22a9fb4..65e0ad6 100644 (file)
--- a/reglib.h
+++ b/reglib.h
@@ -90,9 +90,8 @@ int crda_verify_db_signature(__u8 *db, int dblen, int siglen);
 /* File reg db entry -> rd converstion utilities */
 void reg_rule2rd(__u8 *db, int dblen,
        __be32 ruleptr, struct ieee80211_reg_rule *rd_reg_rule);
-int country2rd(__u8 *db, int dblen,
-       struct regdb_file_reg_country *country,
-       struct ieee80211_regdomain **rdp);
+struct ieee80211_regdomain *country2rd(__u8 *db, int dblen,
+       struct regdb_file_reg_country *country);
 
 /* reg helpers */
 int is_valid_reg_rule(const struct ieee80211_reg_rule *rule);