public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regmap: Fix 'ret' would return an uninitialized value
@ 2013-11-18 12:29 Caizhiyong
  2013-11-18 12:35 ` Mark Brown
  2013-11-18 13:24 ` Geyslan Gregório Bem
  0 siblings, 2 replies; 12+ messages in thread
From: Caizhiyong @ 2013-11-18 12:29 UTC (permalink / raw)
  To: Mark Brown
  Cc: Greg Kroah-Hartman, linux-kernel@vger.kernel.org,
	Wanglin (Albert), Levente Kurusa, Geyslan Gregório Bem,
	levex@linux.com

From: Cai Zhiyong <caizhiyong@huawei.com>
Date: Mon, 18 Nov 2013 20:21:49 +0800
Subject: [PATCH] regmap: Fix 'ret' would return an uninitialized value

This patch give a warning when calling regmap_register_patch with
parameter num_regs <= 0.

When the num_regs parameter is zero and krealloc doesn't fail,
then the code would return an uninitialized value. However,
calling this function with num_regs == 0, would be a waste as it
essentially does nothing.

Signed-off-by: Cai Zhiyong <caizhiyong@huawei.com>
---
 drivers/base/regmap/regmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 9c021d9..9a36ac1 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2173,6 +2173,10 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 	int i, ret;
 	bool bypass;
 
+	if (WARN_ONCE(num_regs <= 0, "invalid registers number (%d)\n",
+	    num_regs))
+		return 0;
+
 	map->lock(map->lock_arg);
 
 	bypass = map->cache_bypass;
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] regmap: Fix 'ret' would return an uninitialized value
@ 2013-11-15 11:30 Caizhiyong
  2013-11-15 13:00 ` Geyslan Gregório Bem
  0 siblings, 1 reply; 12+ messages in thread
From: Caizhiyong @ 2013-11-15 11:30 UTC (permalink / raw)
  To: Mark Brown
  Cc: Greg Kroah-Hartman, linux-kernel@vger.kernel.org,
	Wanglin (Albert), Levente Kurusa

From: Cai Zhiyong <caizhiyong@huawei.com>
Date: Mon, 11 Nov 2013 19:26:14 +0800
Subject: [PATCH] regmap: Fix 'ret' would return an uninitialized value

This patch give a warning when calling regmap_register_patch with
parameter num_regs <= 0.

When the num_regs parameter is zero and krealloc doesn't fail,
then the code would return an uninitialized value. However,
calling this function with num_regs == 0, would be a waste as it
essentially does nothing.

Signed-off-by: Cai Zhiyong <caizhiyong@huawei.com>
---
 drivers/base/regmap/regmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 9c021d9..7b5c28a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2170,9 +2170,12 @@ 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 (WARN_ONCE(num_regs <= 0))
+		return 0;
+
 	map->lock(map->lock_arg);
 
 	bypass = map->cache_bypass;
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] regmap: Fix 'ret' would return an uninitialized value
@ 2013-11-11 11:35 Caizhiyong
  2013-11-14 12:58 ` Mark Brown
  0 siblings, 1 reply; 12+ messages in thread
From: Caizhiyong @ 2013-11-11 11:35 UTC (permalink / raw)
  To: Mark Brown
  Cc: Greg Kroah-Hartman, linux-kernel@vger.kernel.org,
	Wanglin (Albert), Levente Kurusa, Levente Kurusa

From: Cai Zhiyong <caizhiyong@huawei.com>
Date: Mon, 11 Nov 2013 19:26:14 +0800
Subject: [PATCH] regmap: Fix 'ret' would return an uninitialized value

 - Fix 'ret' would return an uninitialized value.
 - Add a warning avoid invalid 'num_regs' value passed in.

When the num_regs parameter is zero and krealloc doesn't fail,
then the code would return an uninitialized value. However,
calling this function with num_regs == 0, would be a waste as it
essentially does nothing.

Signed-off-by: Cai Zhiyong <caizhiyong@huawei.com>
---
 drivers/base/regmap/regmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 9c021d9..7b5c28a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2170,9 +2170,15 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 			  int num_regs)
 {
 	struct reg_default *p;
-	int i, ret;
+	int i;
+	int ret = 0;
 	bool bypass;
 
+	if (num_regs <= 0) {
+		WARN_ONCE(1, "Call regmap_register_patch with num_regs <= 0.");
+		return 0;
+	}
+
 	map->lock(map->lock_arg);
 
 	bypass = map->cache_bypass;
-- 
1.8.1.5


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

end of thread, other threads:[~2013-11-18 13:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-18 12:29 [PATCH] regmap: Fix 'ret' would return an uninitialized value Caizhiyong
2013-11-18 12:35 ` Mark Brown
2013-11-18 13:24 ` Geyslan Gregório Bem
  -- strict thread matches above, loose matches on Subject: below --
2013-11-15 11:30 Caizhiyong
2013-11-15 13:00 ` Geyslan Gregório Bem
2013-11-15 13:27   ` Levente Kurusa
2013-11-15 15:52     ` Geyslan Gregório Bem
2013-11-15 15:58       ` Mark Brown
2013-11-15 16:09         ` Geyslan Gregório Bem
2013-11-15 16:03       ` Levente Kurusa
2013-11-11 11:35 Caizhiyong
2013-11-14 12:58 ` Mark Brown

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