]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
regmap: Allow multiple patches to be registered
authorMark Brown <broonie@linaro.org>
Thu, 11 Jul 2013 11:41:44 +0000 (12:41 +0100)
committerMark Brown <broonie@linaro.org>
Mon, 15 Jul 2013 10:17:18 +0000 (11:17 +0100)
It may be useful to register multiple patches with regmap, for example
one that depends on the device revision and one that depends on the system
configuration. Add support for doing this, appending any new patches to
the existing patches.

Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/base/regmap/regmap.c

index 95920583e31e6dfb5cd0ad18cd9a599e9e34e155..6944ee081220495097d7f1c3fc9171e0dcde4517 100644 (file)
@@ -1888,13 +1888,10 @@ EXPORT_SYMBOL_GPL(regmap_async_complete);
 int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
                          int num_regs)
 {
+       struct reg_default *p;
        int i, ret;
        bool bypass;
 
-       /* If needed the implementation can be extended to support this */
-       if (map->patch)
-               return -EBUSY;
-
        map->lock(map->lock_arg);
 
        bypass = map->cache_bypass;
@@ -1911,11 +1908,13 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
                }
        }
 
-       map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL);
-       if (map->patch != NULL) {
-               memcpy(map->patch, regs,
-                      num_regs * sizeof(struct reg_default));
-               map->patch_regs = num_regs;
+       p = krealloc(map->patch,
+                    sizeof(struct reg_default) * (map->patch_regs + num_regs),
+                    GFP_KERNEL);
+       if (p) {
+               memcpy(p + map->patch_regs, regs, num_regs);
+               map->patch = p;
+               map->patch_regs += num_regs;
        } else {
                ret = -ENOMEM;
        }