regmap: use debugfs even when no device
Subsystems (2)
cover regmap: use debugfs even when no device
This series allows regmaps without a device (e.g. syscon) to be registered in debugfs.
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(-)
Signature · 1 line
2.7.4
PATCH 1/2 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.
--- drivers/base/regmap/regmap-debugfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/base/regmap/regmap-debugfs.c +5 -1
@@ -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 =NULL ;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;
Signature · 1 line
2.7.4
Mark Brown
maintainerRe: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Quoted 3 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.
How are you managing to get a regmap without a device associated with it?
Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Quoted 9 lines · Mark Brown
Quoted 3 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.How are you managing to get a regmap without a device associated with it?
I'm using syscon_regmap_lookup_by_compatible(), which calls:
regmap_init_mmio(NULL, base, &syscon_config)
NULL being the struct device *dev parameter.
There are several clock drivers that do that as well. I'm writing another clock driver and will need to do the same thing for some non-DT boards. I tried using a device, but clocks are initialized fairly early in the boot process and kobject is not initialized yet, so you can't register a platform device at that point.
Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
In reply to David LechnerQuoted 22 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.Signed-off-by David Lechner <[email protected]>--- drivers/base/regmap/regmap-debugfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/base/regmap/regmap-debugfs.c +1
-0@@ -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 =NULL ;int ret;char *buf;
drivers/base/regmap/regmap-debugfs.c static ssize_t regmap_name_read_file(struct file *file, · line 54
Quoted 8 lines
drivers/base/regmap/regmap-debugfs.c +4
-1@@ -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);
Won't this print "(null)" now? Not sure if that is the best approach.
Mark Brown
maintainerRe: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Quoted 5 lines · Lars-Peter Clausen
Quoted 3 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.
Quoted 7 lines
drivers/base/regmap/regmap-debugfs.c static ssize_t regmap_name_read_file(struct file *file, · line 54
Quoted 5 lines
drivers/base/regmap/regmap-debugfs.c +4
-1- 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);Won't this print "(null)" now? Not sure if that is the best approach.
Indeed. It is an improvement but not exactly helpful.
Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Quoted 14 lines · Mark Brown
Quoted 5 lines · Lars-Peter Clausen
Quoted 3 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.Quoted 7 lines
drivers/base/regmap/regmap-debugfs.c static ssize_t regmap_name_read_file(struct file *file, · line 54
Quoted 5 lines
drivers/base/regmap/regmap-debugfs.c +4
-1- 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);Won't this print "(null)" now? Not sure if that is the best approach.
Quoted 2 lines
Indeed. It is an improvement but not exactly helpful.
Would it be better if it said "this regmap does not have driver" instead of "(null)"?
Mark Brown
maintainerRe: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Quoted 6 lines · David Lechner
Quoted 1 line · Mark Brown
Indeed. It is an improvement but not exactly helpful.
Would it be better if it said "this regmap does not have driver" instead of "(null)"?
That's both not idiomatically good and isn't even true... ideally we'd be able to get some sort of string out of the user, but otherwise "nodev" or perhaps printing the pointer to the regmap (to avoid collisions if there's more than one of these in a system).
Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
In reply to Lars-Peter ClausenQuoted 26 lines · Lars-Peter Clausen
Quoted 25 lines · David Lechner
This fixes a possible NULL pointer dereference oops in
regmap_name_read_file()when the regmap does not have a device associated with it.Signed-off-by David Lechner <[email protected]>--- drivers/base/regmap/regmap-debugfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/base/regmap/regmap-debugfs.c +1
-0@@ -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 =NULL ;int ret;char *buf;@@ -47,7 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file,if (!buf)return -ENOMEM ;
Quoted 8 lines
drivers/base/regmap/regmap-debugfs.c static ssize_t regmap_name_read_file(struct file *file, · line 54
Quoted 5 lines
drivers/base/regmap/regmap-debugfs.c +4
-1- 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);Won't this print "(null)" now? Not sure if that is the best approach.
The commit adding regmap_name_read_file() just says:
regmap: Expose the driver name in debugfs
Add a file called 'name' containing the name of the driver.
So, if a regmap doesn't have a driver, then "(null)" seems OK to me. This is just for debugging anyway.
PATCH 2/2 regmap: use debugfs even when no device
In reply to David LechnerThis registers regmaps with debugfs even when they do not have an associated device. For example, this is common for syscon regmaps.
--- drivers/base/regmap/regmap.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/base/regmap/regmap.c +2 -0
@@ -1106,6 +1106,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;
Signature · 1 line
2.7.4
Mark Brown
maintainerApplied "regmap: use debugfs even when no device" to the regmap tree
The patch
regmap: use debugfs even when no device
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
Quoted 1 line
From
9b947a13e7f6017f18470f665992dbae267852b3Mon Sep 17 00:00:00 2001
From: David Lechner <[email protected]>
Date: Mon, 19 Feb 2018 15:43:02 -0600
Subject: [PATCH] regmap: use debugfs even when no device
This registers regmaps with debugfs even when they do not have an associated device. For example, this is common for syscon regmaps.
--- drivers/base/regmap/regmap.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/base/regmap/regmap.c +2 -0
@@ -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;
Signature · 1 line
2.16.1