linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Streetman <ddstreet@ieee.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Seth Jennings <sjennings@variantweb.net>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	kbuild test robot <fengguang.wu@intel.com>
Subject: Re: [PATCH 1/2] zpool: define and use max type length
Date: Tue, 18 Aug 2015 22:20:03 -0400	[thread overview]
Message-ID: <CALZtONCjUgUWxO6=SYui-cWE2m4hi9cJ-jKPHaRha707NimB0w@mail.gmail.com> (raw)
In-Reply-To: <20150818153818.cab58a99f60113c2aca2f006@linux-foundation.org>

On Tue, Aug 18, 2015 at 6:38 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Tue, 18 Aug 2015 16:06:00 -0400 Dan Streetman <ddstreet@ieee.org> wrote:
>
>> Add ZPOOL_MAX_TYPE_NAME define, and change zpool_driver *type field to
>> type[ZPOOL_MAX_TYPE_NAME].  Remove redundant type field from struct zpool
>> and use zpool->driver->type instead.
>>
>> The define will be used by zswap for its zpool param type name length.
>>
>
> Patchset is fugly.  All this putzing around with fixed-length strings,
> worrying about overflow and is-it-null-terminated-or-isnt-it.  Shudder.
>
> It's much better to use variable-length strings everywhere.  We're not
> operating in contexts which can't use kmalloc, we're not
> performance-intensive and these strings aren't being written to
> fixed-size fields on disk or anything.  Why do we need any fixed-length
> strings?
>
> IOW, why not just replace that alloca with a kstrdup()?

for the zpool drivers (zbud and zsmalloc), the type is actually just
statically assigned, e.g. .type = "zbud", so you're right the *type is
better than type[].  I'll update it.

>
>> --- a/include/linux/zpool.h
>> +++ b/include/linux/zpool.h
>>
>> ...
>>
>> @@ -79,7 +77,7 @@ static struct zpool_driver *zpool_get_driver(char *type)
>>
>>       spin_lock(&drivers_lock);
>>       list_for_each_entry(driver, &drivers_head, list) {
>> -             if (!strcmp(driver->type, type)) {
>> +             if (!strncmp(driver->type, type, ZPOOL_MAX_TYPE_NAME)) {
>
> Why strncmp?  Please tell me these strings are always null-terminated.

Yep, you're right.  The driver->type always is, and the type param is
passed in from sysfs, which we can rely on to be null-terminated.

>
>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2015-08-19  2:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 20:06 Dan Streetman
2015-08-18 20:06 ` [PATCH 2/2] zswap: use const max length for kparam names Dan Streetman
2015-08-18 22:38 ` [PATCH 1/2] zpool: define and use max type length Andrew Morton
2015-08-19  2:20   ` Dan Streetman [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='CALZtONCjUgUWxO6=SYui-cWE2m4hi9cJ-jKPHaRha707NimB0w@mail.gmail.com' \
    --to=ddstreet@ieee.org \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sjennings@variantweb.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox