Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751562AbbHSCUp (ORCPT ); Tue, 18 Aug 2015 22:20:45 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]:33505 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750923AbbHSCUn (ORCPT ); Tue, 18 Aug 2015 22:20:43 -0400 MIME-Version: 1.0 In-Reply-To: <20150818153818.cab58a99f60113c2aca2f006@linux-foundation.org> References: <1439928361-31294-1-git-send-email-ddstreet@ieee.org> <20150818153818.cab58a99f60113c2aca2f006@linux-foundation.org> From: Dan Streetman Date: Tue, 18 Aug 2015 22:20:03 -0400 X-Google-Sender-Auth: G5YYOKq5d3JkTBu9wIpR2m8v4Bo Message-ID: Subject: Re: [PATCH 1/2] zpool: define and use max type length To: Andrew Morton Cc: Seth Jennings , linux-kernel , Linux-MM , Sergey Senozhatsky , kbuild test robot Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1947 Lines: 51 On Tue, Aug 18, 2015 at 6:38 PM, Andrew Morton wrote: > On Tue, 18 Aug 2015 16:06:00 -0400 Dan Streetman 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 from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/