All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH 3/3] regmap: duplicate the name string stored in regmap
Date: Wed, 13 Dec 2017 10:56:58 +0100	[thread overview]
Message-ID: <CAMRc=MfyURSh98ds0B2tO5xV9SK5d5D4FoZq5nOPhYH2aGJ9hg@mail.gmail.com> (raw)
In-Reply-To: <f7d92fa5-16b9-6e60-cd52-db3f848abe6c@metafoo.de>

2017-12-13 10:32 GMT+01:00 Lars-Peter Clausen <lars@metafoo.de>:
> On 12/13/2017 10:28 AM, Bartosz Golaszewski wrote:
>> Currently we just copy over the pointer passed to regmap_init() in
>> the regmap config struct. To be on the safe side: duplicate the string
>> so that if an unaware user passes an address to a stack-allocated
>> buffer, we won't crash.
>>
>> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
>> ---
>>  drivers/base/regmap/regmap.c | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
>> index a2a02ce58824..3952e5d7638a 100644
>> --- a/drivers/base/regmap/regmap.c
>> +++ b/drivers/base/regmap/regmap.c
>> @@ -672,6 +672,14 @@ struct regmap *__regmap_init(struct device *dev,
>>               goto err;
>>       }
>>
>> +     if (config->name) {
>> +             map->name = kstrdup(config->name, GFP_KERNEL);
>
> To get the best of both worlds: kstrdup_const(), this will not make a copy
> when it is in a read-only section (like most strings will be). Needs to be
> matched with kfree_const().
>

Nice! Another useful kernel interface I wasn't aware of. I'll wait
some more for any potential comments from others and include that in
v2.

Thanks,
Bartosz

>> +             if (!map->name) {
>> +                     ret = -ENOMEM;
>> +                     goto err_map;
>> +             }
>> +     }
>> +
>>       if (config->disable_locking) {
>>               map->locking_disabled = true;
>>               map->lock = map->unlock = regmap_lock_unlock_none;
>> @@ -763,7 +771,6 @@ struct regmap *__regmap_init(struct device *dev,
>>       map->volatile_reg = config->volatile_reg;
>>       map->precious_reg = config->precious_reg;
>>       map->cache_type = config->cache_type;
>> -     map->name = config->name;
>>
>>       spin_lock_init(&map->async_lock);
>>       INIT_LIST_HEAD(&map->async_list);
>> @@ -1308,6 +1315,7 @@ void regmap_exit(struct regmap *map)
>>       }
>>       if (map->hwlock)
>>               hwspin_lock_free(map->hwlock);
>> +     kfree(map->name);
>>       kfree(map);
>>  }
>>  EXPORT_SYMBOL_GPL(regmap_exit);
>>
>

      reply	other threads:[~2017-12-13  9:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13  9:28 [PATCH 0/3] regmap: follow-up for ("regmap: allow to disable all locking mechanisms") Bartosz Golaszewski
2017-12-13  9:28 ` [PATCH 1/3] regmap: rename regmap_lock_unlock_empty() to regmap_lock_unlock_none() Bartosz Golaszewski
2017-12-13  9:28 ` [PATCH 2/3] regmap: don't create the debugfs entries if locking is disabled Bartosz Golaszewski
2017-12-13 14:54   ` Andy Shevchenko
2017-12-13 14:59     ` Bartosz Golaszewski
2017-12-13 15:39   ` Mark Brown
2017-12-13 15:46     ` Bartosz Golaszewski
2017-12-13 16:00       ` Mark Brown
2017-12-13  9:28 ` [PATCH 3/3] regmap: duplicate the name string stored in regmap Bartosz Golaszewski
2017-12-13  9:32   ` Lars-Peter Clausen
2017-12-13  9:56     ` Bartosz Golaszewski [this message]

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='CAMRc=MfyURSh98ds0B2tO5xV9SK5d5D4FoZq5nOPhYH2aGJ9hg@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=andy.shevchenko@gmail.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.