linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] regmap: use debugfs even when no device
@ 2018-02-19 21:43 David Lechner
  2018-02-19 21:43 ` [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
  2018-02-19 21:43 ` [PATCH v2 2/2] regmap: use debugfs even when no device David Lechner
  0 siblings, 2 replies; 4+ messages in thread
From: David Lechner @ 2018-02-19 21:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Lechner, Mark Brown, Greg Kroah-Hartman

This series allows regmaps without a device (e.g. syscon) to be registered
in debugfs.

v2 changes:
- address review comments in patch 1/2

David Lechner (2):
  regmap: fix NULL pointer dereference in regmap_name_read_file()
  regmap: use debugfs even when no device

 drivers/base/regmap/regmap-debugfs.c | 6 +++++-
 drivers/base/regmap/regmap.c         | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

-- 
2.7.4

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

* [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-02-19 21:43 [PATCH v2 0/2] regmap: use debugfs even when no device David Lechner
@ 2018-02-19 21:43 ` David Lechner
  2018-02-20 12:10   ` Applied "regmap: Allow missing device in regmap_name_read_file()" to the regmap tree Mark Brown
  2018-02-19 21:43 ` [PATCH v2 2/2] regmap: use debugfs even when no device David Lechner
  1 sibling, 1 reply; 4+ messages in thread
From: David Lechner @ 2018-02-19 21:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Lechner, Mark Brown, Greg Kroah-Hartman

This fixes a possible NULL pointer dereference oops in
regmap_name_read_file() when the regmap does not have a device
associated with it. For example syscon regmaps retrieved with
syscon_regmap_lookup_by_compatible() don't have a device.

Signed-off-by: David Lechner <david@lechnology.com>
---

v2 changes:
- point out case where this can actually happen in the commit message
- print "nodev" instead of "(null)" if there is no device

 drivers/base/regmap/regmap-debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index f326633..7eb512b 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -40,6 +40,7 @@ static ssize_t regmap_name_read_file(struct file *file,
 				     loff_t *ppos)
 {
 	struct regmap *map = file->private_data;
+	const char *name = "nodev";
 	int ret;
 	char *buf;
 
@@ -47,7 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file,
 	if (!buf)
 		return -ENOMEM;
 
-	ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name);
+	if (map->dev && map->dev->driver)
+		name = map->dev->driver->name;
+
+	ret = snprintf(buf, PAGE_SIZE, "%s\n", name);
 	if (ret < 0) {
 		kfree(buf);
 		return ret;
-- 
2.7.4

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

* [PATCH v2 2/2] regmap: use debugfs even when no device
  2018-02-19 21:43 [PATCH v2 0/2] regmap: use debugfs even when no device David Lechner
  2018-02-19 21:43 ` [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
@ 2018-02-19 21:43 ` David Lechner
  1 sibling, 0 replies; 4+ messages in thread
From: David Lechner @ 2018-02-19 21:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Lechner, Mark Brown, Greg Kroah-Hartman

This registers regmaps with debugfs even when they do not have an
associated device. For example, this is common for syscon regmaps.

Signed-off-by: David Lechner <david@lechnology.com>
---

v2 changes:
- none

 drivers/base/regmap/regmap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302cc..f5fa1dd 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1116,6 +1116,8 @@ struct regmap *__regmap_init(struct device *dev,
 		ret = regmap_attach_dev(dev, map, config);
 		if (ret != 0)
 			goto err_regcache;
+	} else {
+		regmap_debugfs_init(map, config->name);
 	}
 
 	return map;
-- 
2.7.4

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

* Applied "regmap: Allow missing device in regmap_name_read_file()" to the regmap tree
  2018-02-19 21:43 ` [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
@ 2018-02-20 12:10   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2018-02-20 12:10 UTC (permalink / raw)
  To: David Lechner
  Cc: Mark Brown, linux-kernel, Mark Brown, Greg Kroah-Hartman, linux-kernel

The patch

   regmap: Allow missing device in regmap_name_read_file()

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 12ae3808c160b7be0de3c633ac4cbe8c5f2937bf Mon Sep 17 00:00:00 2001
From: David Lechner <david@lechnology.com>
Date: Mon, 19 Feb 2018 15:43:01 -0600
Subject: [PATCH] regmap: Allow missing device in regmap_name_read_file()

This fixes a possible NULL pointer dereference oops in
regmap_name_read_file() when the regmap does not have a device
associated with it. For example syscon regmaps retrieved with
syscon_regmap_lookup_by_compatible() don't have a device.

Signed-off-by: David Lechner <david@lechnology.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap-debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index f3266334063e..7eb512ba2828 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -40,6 +40,7 @@ static ssize_t regmap_name_read_file(struct file *file,
 				     loff_t *ppos)
 {
 	struct regmap *map = file->private_data;
+	const char *name = "nodev";
 	int ret;
 	char *buf;
 
@@ -47,7 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file,
 	if (!buf)
 		return -ENOMEM;
 
-	ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name);
+	if (map->dev && map->dev->driver)
+		name = map->dev->driver->name;
+
+	ret = snprintf(buf, PAGE_SIZE, "%s\n", name);
 	if (ret < 0) {
 		kfree(buf);
 		return ret;
-- 
2.16.1

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

end of thread, other threads:[~2018-02-20 12:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-19 21:43 [PATCH v2 0/2] regmap: use debugfs even when no device David Lechner
2018-02-19 21:43 ` [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
2018-02-20 12:10   ` Applied "regmap: Allow missing device in regmap_name_read_file()" to the regmap tree Mark Brown
2018-02-19 21:43 ` [PATCH v2 2/2] regmap: use debugfs even when no device David Lechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).