All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] regmap: use debugfs even when no device
@ 2018-01-23 22:53 David Lechner
  2018-01-23 22:53 ` [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
  2018-01-23 22:53 ` [PATCH 2/2] regmap: use debugfs even when no device David Lechner
  0 siblings, 2 replies; 11+ messages in thread
From: David Lechner @ 2018-01-23 22:53 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.

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] 11+ messages in thread

* [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-23 22:53 [PATCH 0/2] regmap: use debugfs even when no device David Lechner
@ 2018-01-23 22:53 ` David Lechner
  2018-01-24 11:30   ` Mark Brown
  2018-01-24 16:14   ` Lars-Peter Clausen
  2018-01-23 22:53 ` [PATCH 2/2] regmap: use debugfs even when no device David Lechner
  1 sibling, 2 replies; 11+ messages in thread
From: David Lechner @ 2018-01-23 22:53 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.

Signed-off-by: David Lechner <david@lechnology.com>
---
 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 36ce351..0df7379 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 = 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;
-- 
2.7.4

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

* [PATCH 2/2] regmap: use debugfs even when no device
  2018-01-23 22:53 [PATCH 0/2] regmap: use debugfs even when no device David Lechner
  2018-01-23 22:53 ` [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
@ 2018-01-23 22:53 ` David Lechner
  2018-02-20 12:10   ` Applied "regmap: use debugfs even when no device" to the regmap tree Mark Brown
  1 sibling, 1 reply; 11+ messages in thread
From: David Lechner @ 2018-01-23 22:53 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>
---
 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 8d516a9..ebad970 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -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;
-- 
2.7.4

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-23 22:53 ` [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
@ 2018-01-24 11:30   ` Mark Brown
  2018-01-24 16:04     ` David Lechner
  2018-01-24 16:14   ` Lars-Peter Clausen
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2018-01-24 11:30 UTC (permalink / raw)
  To: David Lechner; +Cc: linux-kernel, Greg Kroah-Hartman

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]

On Tue, Jan 23, 2018 at 04:53:42PM -0600, David Lechner wrote:

> 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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-24 11:30   ` Mark Brown
@ 2018-01-24 16:04     ` David Lechner
  0 siblings, 0 replies; 11+ messages in thread
From: David Lechner @ 2018-01-24 16:04 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Greg Kroah-Hartman

On 01/24/2018 05:30 AM, Mark Brown wrote:
> On Tue, Jan 23, 2018 at 04:53:42PM -0600, David Lechner wrote:
> 
>> 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.

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-23 22:53 ` [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
  2018-01-24 11:30   ` Mark Brown
@ 2018-01-24 16:14   ` Lars-Peter Clausen
  2018-01-24 16:19     ` Mark Brown
  2018-01-24 16:24     ` David Lechner
  1 sibling, 2 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2018-01-24 16:14 UTC (permalink / raw)
  To: David Lechner, linux-kernel; +Cc: Mark Brown, Greg Kroah-Hartman

On 01/23/2018 11:53 PM, David Lechner wrote:
> 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 <david@lechnology.com>
> ---
>  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 36ce351..0df7379 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 = 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);

Won't this print "(null)" now? Not sure if that is the best approach.

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-24 16:14   ` Lars-Peter Clausen
@ 2018-01-24 16:19     ` Mark Brown
  2018-01-24 16:27       ` David Lechner
  2018-01-24 16:24     ` David Lechner
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2018-01-24 16:19 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: David Lechner, linux-kernel, Greg Kroah-Hartman

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

On Wed, Jan 24, 2018 at 05:14:50PM +0100, Lars-Peter Clausen wrote:
> On 01/23/2018 11:53 PM, David Lechner wrote:
> > This fixes a possible NULL pointer dereference oops in
> > regmap_name_read_file() when the regmap does not have a device
> > associated with it.

> > -	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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-24 16:14   ` Lars-Peter Clausen
  2018-01-24 16:19     ` Mark Brown
@ 2018-01-24 16:24     ` David Lechner
  1 sibling, 0 replies; 11+ messages in thread
From: David Lechner @ 2018-01-24 16:24 UTC (permalink / raw)
  To: Lars-Peter Clausen, linux-kernel; +Cc: Mark Brown, Greg Kroah-Hartman

On 01/24/2018 10:14 AM, Lars-Peter Clausen wrote:
> On 01/23/2018 11:53 PM, David Lechner wrote:
>> 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 <david@lechnology.com>
>> ---
>>   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 36ce351..0df7379 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 = 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);
> 
> 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.

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-24 16:19     ` Mark Brown
@ 2018-01-24 16:27       ` David Lechner
  2018-01-24 17:04         ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: David Lechner @ 2018-01-24 16:27 UTC (permalink / raw)
  To: Mark Brown, Lars-Peter Clausen; +Cc: linux-kernel, Greg Kroah-Hartman

On 01/24/2018 10:19 AM, Mark Brown wrote:
> On Wed, Jan 24, 2018 at 05:14:50PM +0100, Lars-Peter Clausen wrote:
>> On 01/23/2018 11:53 PM, David Lechner wrote:
>>> This fixes a possible NULL pointer dereference oops in
>>> regmap_name_read_file() when the regmap does not have a device
>>> associated with it.
> 
>>> -	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.
> 


Would it be better if it said "this regmap does not have driver" instead
of "(null)"?

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

* Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
  2018-01-24 16:27       ` David Lechner
@ 2018-01-24 17:04         ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2018-01-24 17:04 UTC (permalink / raw)
  To: David Lechner; +Cc: Lars-Peter Clausen, linux-kernel, Greg Kroah-Hartman

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

On Wed, Jan 24, 2018 at 10:27:22AM -0600, David Lechner wrote:
> On 01/24/2018 10:19 AM, Mark Brown wrote:

> > 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).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Applied "regmap: use debugfs even when no device" to the regmap tree
  2018-01-23 22:53 ` [PATCH 2/2] regmap: use debugfs even when no device David Lechner
@ 2018-02-20 12:10   ` Mark Brown
  0 siblings, 0 replies; 11+ 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: 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

>From 9b947a13e7f6017f18470f665992dbae267852b3 Mon Sep 17 00:00:00 2001
From: David Lechner <david@lechnology.com>
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.

Signed-off-by: David Lechner <david@lechnology.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 ee302ccdfbc8..f5fa1ddc65e9 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.16.1

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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23 22:53 [PATCH 0/2] regmap: use debugfs even when no device David Lechner
2018-01-23 22:53 ` [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file() David Lechner
2018-01-24 11:30   ` Mark Brown
2018-01-24 16:04     ` David Lechner
2018-01-24 16:14   ` Lars-Peter Clausen
2018-01-24 16:19     ` Mark Brown
2018-01-24 16:27       ` David Lechner
2018-01-24 17:04         ` Mark Brown
2018-01-24 16:24     ` David Lechner
2018-01-23 22:53 ` [PATCH 2/2] regmap: use debugfs even when no device David Lechner
2018-02-20 12:10   ` Applied "regmap: use debugfs even when no device" to the regmap tree Mark Brown

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.