All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regmap: replace multiple BUG_ON assertions with error return code
@ 2019-12-15 18:39 Aditya Pakki
  2019-12-15 19:08 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2019-12-15 18:39 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
	linux-kernel

Various register operations check for the validity of cache_ops
struct and crash in case of failure. However, by returning the error
to the callers, instead of assert, these functions can avoid the crash.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/base/regmap/regcache.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index a93cafd7be4f..855fa25ae595 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -238,7 +238,8 @@ int regcache_read(struct regmap *map,
 	if (map->cache_type == REGCACHE_NONE)
 		return -ENOSYS;
 
-	BUG_ON(!map->cache_ops);
+	if (!map->cache_ops)
+		return -EINVAL;
 
 	if (!regmap_volatile(map, reg)) {
 		ret = map->cache_ops->read(map, reg, value);
@@ -267,7 +268,8 @@ int regcache_write(struct regmap *map,
 	if (map->cache_type == REGCACHE_NONE)
 		return 0;
 
-	BUG_ON(!map->cache_ops);
+	if (!map->cache_ops)
+		return -EINVAL;
 
 	if (!regmap_volatile(map, reg))
 		return map->cache_ops->write(map, reg, value);
@@ -343,7 +345,8 @@ int regcache_sync(struct regmap *map)
 	const char *name;
 	bool bypass;
 
-	BUG_ON(!map->cache_ops);
+	if (!map->cache_ops)
+		return -EINVAL;
 
 	map->lock(map->lock_arg);
 	/* Remember the initial bypass state */
@@ -412,7 +415,8 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
 	const char *name;
 	bool bypass;
 
-	BUG_ON(!map->cache_ops);
+	if (!map->cache_ops)
+		return -EINVAL;
 
 	map->lock(map->lock_arg);
 
-- 
2.20.1


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

end of thread, other threads:[~2019-12-15 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-15 18:39 [PATCH] regmap: replace multiple BUG_ON assertions with error return code Aditya Pakki
2019-12-15 19:08 ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.