Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92ab1aab authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown
Browse files

regmap: Make regmap-mmio usable from atomic contexts



regmap-mmio uses a spinlock with spin_lock() and spin_unlock() for locking.
To be able to use the regmap API from different contexts (atomic vs non-atomic),
without the risk of race conditions, we need to use spin_lock_irqsave() and
spin_lock_irqrestore() instead. A new field, the spinlock_flags field, is added
to regmap struct to store the flags between regmap_{,un}lock_spinlock(). The
spinlock_flags field itself is also protected by the spinlock.

Thanks to Stephen Warren for the suggestion of this particular solution.

Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Reviewed-by: default avatarStephen Warren <swarren@nvidia.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 81485f52
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ struct regmap_async {
struct regmap {
struct regmap {
	struct mutex mutex;
	struct mutex mutex;
	spinlock_t spinlock;
	spinlock_t spinlock;
	unsigned long spinlock_flags;
	regmap_lock lock;
	regmap_lock lock;
	regmap_unlock unlock;
	regmap_unlock unlock;
	void *lock_arg; /* This is passed to lock/unlock functions */
	void *lock_arg; /* This is passed to lock/unlock functions */
+5 −2
Original line number Original line Diff line number Diff line
@@ -302,13 +302,16 @@ static void regmap_unlock_mutex(void *__map)
static void regmap_lock_spinlock(void *__map)
static void regmap_lock_spinlock(void *__map)
{
{
	struct regmap *map = __map;
	struct regmap *map = __map;
	spin_lock(&map->spinlock);
	unsigned long flags;

	spin_lock_irqsave(&map->spinlock, flags);
	map->spinlock_flags = flags;
}
}


static void regmap_unlock_spinlock(void *__map)
static void regmap_unlock_spinlock(void *__map)
{
{
	struct regmap *map = __map;
	struct regmap *map = __map;
	spin_unlock(&map->spinlock);
	spin_unlock_irqrestore(&map->spinlock, map->spinlock_flags);
}
}


static void dev_get_regmap_release(struct device *dev, void *res)
static void dev_get_regmap_release(struct device *dev, void *res)