diff
+static void cleanup_coalesce(struct cfg80211_coalesce *coalesce)
+{
+    if (coalesce->rules) {
+        int i, j;
+        struct cfg80211_coalesce_rules *tmp_rule;
+        for (i = 0; i < coalesce->n_rules; i++) {
+            tmp_rule = &coalesce->rules[i];
+            for (j = 0; j < tmp_rule->n_patterns; j++)
+                kfree(tmp_rule->patterns[j].mask);
+            kfree(tmp_rule->patterns);
+        }
+        kfree(coalesce->rules);
+    }
+}

 // ... (in the main function)

 error:
-    for (i = 0; i < new_coalesce.n_rules; i++) {
-        tmp_rule = &new_coalesce.rules[i];
-        for (j = 0; j < tmp_rule->n_patterns; j++)
-            kfree(tmp_rule->patterns[j].mask);
-        kfree(tmp_rule->patterns);
-    }
-    kfree(new_coalesce.rules);
+    cleanup_coalesce(&new_coalesce);
