All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Lars-Peter Clausen <lars@metafoo.de>, linux-kernel@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 1/2] regmap: fix NULL pointer dereference in regmap_name_read_file()
Date: Wed, 24 Jan 2018 10:24:46 -0600	[thread overview]
Message-ID: <65bf4e98-21c3-0d52-f25b-2ad78b4d0d06@lechnology.com> (raw)
In-Reply-To: <c7919cd8-447c-6eee-184a-0d40efbcbe75@metafoo.de>

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.

  parent reply	other threads:[~2018-01-24 16:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65bf4e98-21c3-0d52-f25b-2ad78b4d0d06@lechnology.com \
    --to=david@lechnology.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.