From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id E06E06B000A for ; Thu, 5 Jul 2018 15:52:09 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id e29-v6so8991414oiy.2 for ; Thu, 05 Jul 2018 12:52:09 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n127-v6sor4821100oia.199.2018.07.05.12.52.08 for (Google Transport Security); Thu, 05 Jul 2018 12:52:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180705194936.GA28447@bombadil.infradead.org> References: <153077334130.40830.2714147692560185329.stgit@dwillia2-desk3.amr.corp.intel.com> <153077341292.40830.11333232703318633087.stgit@dwillia2-desk3.amr.corp.intel.com> <20180705082931.echvdqipgvwhghf2@linux-x5ow.site> <20180705194936.GA28447@bombadil.infradead.org> From: Dan Williams Date: Thu, 5 Jul 2018 12:52:07 -0700 Message-ID: Subject: Re: [PATCH 13/13] libnvdimm, namespace: Publish page structure init state / control Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Matthew Wilcox Cc: Johannes Thumshirn , Andrew Morton , Ross Zwisler , Vishal Verma , Dave Jiang , Jeff Moyer , Christoph Hellwig , linux-nvdimm , Linux MM , Linux Kernel Mailing List On Thu, Jul 5, 2018 at 12:49 PM, Matthew Wilcox wrote: > On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: >> On Thu, Jul 5, 2018 at 1:29 AM, Johannes Thumshirn wrote: >> > On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: >> >> +static ssize_t memmap_state_store(struct device *dev, >> >> + struct device_attribute *attr, const char *buf, size_t len) >> >> +{ >> >> + int i; >> >> + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); >> >> + struct memmap_async_state *async = &nd_pfn->async; >> >> + >> >> + if (strcmp(buf, "sync") == 0) >> >> + /* pass */; >> >> + else if (strcmp(buf, "sync\n") == 0) >> >> + /* pass */; >> >> + else >> >> + return -EINVAL; >> > >> > Hmm what about: >> > >> > if (strncmp(buf, "sync", 4)) >> > return -EINVAL; >> > >> > This collapses 6 lines into 4. >> >> ...but that also allows 'echo "syncAndThenSomeGarbage" > >> /sys/.../memmap_state' to succeed. > > if (strncmp(buf, "sync", 4)) > return -EINVAL; > if (buf[4] != '\0' && buf[4] != '\n') > return -EINVAL; > Not sure that's a win either, I'd rather just: + if (strcmp(buf, "sync") == 0 || strcmp(buf, "sync\n") == 0) + /* pass */; + else + return -EINVAL; If we're trying to save those 2 lines.