mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regmap: Ensure regmap_register_patch() is compatible with fast_io
@ 2014-03-18 12:02 Mark Brown
  2014-03-18 13:43 ` Levente Kurusa
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2014-03-18 12:02 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: linux-kernel, linaro-kernel, Mark Brown

From: Mark Brown <broonie@linaro.org>

With fast_io we use mutexes to lock the I/O operations so we would need
to do GFP_ATOMIC allocations if we wanted to do allocations inside the
lock as we do currently. Since it is unlikely that we will want to register
a patch outside of init where concurrency shouldn't be an issue move the
allocation of the patch data outside the lock.

Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
---
 drivers/base/regmap/regmap.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 554119535a64..2d7d55b3bedb 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2396,6 +2396,9 @@ EXPORT_SYMBOL_GPL(regmap_async_complete);
  * apply them immediately.  Typically this is used to apply
  * corrections to be applied to the device defaults on startup, such
  * as the updates some vendors provide to undocumented registers.
+ *
+ * The caller must ensure that this function cannot be called
+ * concurrently with either itself or regcache_sync().
  */
 int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 			  int num_regs)
@@ -2408,6 +2411,17 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 	    num_regs))
 		return 0;
 
+	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 * sizeof(*regs));
+		map->patch = p;
+		map->patch_regs += num_regs;
+	} else {
+		return -ENOMEM;
+	}
+
 	map->lock(map->lock_arg);
 
 	bypass = map->cache_bypass;
@@ -2419,17 +2433,6 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 	if (ret != 0)
 		goto out;
 
-	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 * sizeof(*regs));
-		map->patch = p;
-		map->patch_regs += num_regs;
-	} else {
-		ret = -ENOMEM;
-	}
-
 out:
 	map->async = false;
 	map->cache_bypass = bypass;
-- 
1.9.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regmap: Ensure regmap_register_patch() is compatible with fast_io
  2014-03-18 12:02 [PATCH] regmap: Ensure regmap_register_patch() is compatible with fast_io Mark Brown
@ 2014-03-18 13:43 ` Levente Kurusa
  2014-03-18 16:07   ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Levente Kurusa @ 2014-03-18 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: Takashi Iwai, linux-kernel, linaro-kernel, Mark Brown

Hi Mark,

Just a single, mini-comment.


2014-03-18 13:02 GMT+01:00 Mark Brown <broonie@kernel.org>:
> From: Mark Brown <broonie@linaro.org>
>
> With fast_io we use mutexes to lock the I/O operations so we would need
> to do GFP_ATOMIC allocations if we wanted to do allocations inside the
> lock as we do currently. Since it is unlikely that we will want to register
> a patch outside of init where concurrency shouldn't be an issue move the
> allocation of the patch data outside the lock.
>
> Reported-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Mark Brown <broonie@linaro.org>
> ---
>  drivers/base/regmap/regmap.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
> index 554119535a64..2d7d55b3bedb 100644
> --- a/drivers/base/regmap/regmap.c
> +++ b/drivers/base/regmap/regmap.c
> @@ -2396,6 +2396,9 @@ EXPORT_SYMBOL_GPL(regmap_async_complete);
>   * apply them immediately.  Typically this is used to apply
>   * corrections to be applied to the device defaults on startup, such
>   * as the updates some vendors provide to undocumented registers.
> + *
> + * The caller must ensure that this function cannot be called
> + * concurrently with either itself or regcache_sync().
>   */
>  int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
>                           int num_regs)
> @@ -2408,6 +2411,17 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
>             num_regs))
>                 return 0;
>
> +       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 * sizeof(*regs));
> +               map->patch = p;
> +               map->patch_regs += num_regs;
> +       } else {
> +               return -ENOMEM;
> +       }
> +

I think that is not checkpatch-safe :-)

> [...]

--
Regards,
Levente Kurusa

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regmap: Ensure regmap_register_patch() is compatible with fast_io
  2014-03-18 13:43 ` Levente Kurusa
@ 2014-03-18 16:07   ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-03-18 16:07 UTC (permalink / raw)
  To: Levente Kurusa; +Cc: Takashi Iwai, linux-kernel, linaro-kernel

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

On Tue, Mar 18, 2014 at 02:43:18PM +0100, Levente Kurusa wrote:
> 2014-03-18 13:02 GMT+01:00 Mark Brown <broonie@kernel.org>:

> > +       if (p) {
> > +               memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs));
> > +               map->patch = p;
> > +               map->patch_regs += num_regs;
> > +       } else {
> > +               return -ENOMEM;
> > +       }
> > +

> I think that is not checkpatch-safe :-)

What makes you say that?  If you think there's some problem say what it
is please...

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-18 16:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-18 12:02 [PATCH] regmap: Ensure regmap_register_patch() is compatible with fast_io Mark Brown
2014-03-18 13:43 ` Levente Kurusa
2014-03-18 16:07   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®