[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1519076582-7687-2-git-send-email-david@lechnology.com>
Date: Mon, 19 Feb 2018 15:43:01 -0600
From: David Lechner <david@...hnology.com>
To: linux-kernel@...r.kernel.org
Cc: David Lechner <david@...hnology.com>,
Mark Brown <broonie@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH v2] regmap: fix NULL pointer dereference 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@...hnology.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
Powered by blists - more mailing lists