public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Qu Wenruo' <quwenruo.btrfs@gmx.com>,
	'David Disseldorp' <ddiss@suse.de>, Qu Wenruo <wqu@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/2] lib/strtox: introduce kstrtoull_suffix() helper
Date: Wed, 20 Dec 2023 08:31:48 +0000	[thread overview]
Message-ID: <3f8ee41745ac40e58e0aa535029e8751@AcuMS.aculab.com> (raw)
In-Reply-To: <4fbcab63-347f-4cef-ad35-686844c983ed@gmx.com>

From: Qu Wenruo
> Sent: 19 December 2023 21:18
...
> > How about:
> > 	suffix = *endptr;
> > 	if (!strchr(suffixes, suffix))
> > 		return -ENIVAL;
> > 	shift = strcspn("KkMmGgTtPp", suffix)/2 * 10 + 10;
> 
> This means the caller has to provide the suffix string in this
> particular order.

No, The strchr() checks that the suffix is one the caller wanted.
The strcspn() is against a fixed list - so the order can be
selected to make the code shorter.

Actually strcspn() isn't the function you need.
There might be a function like strchr() that returns a count
but I can't remember its name and it may not be in kernel.
You might have to write:
	shift = 0;
	for (const char *sfp = "KkMmGgTtPp"; suffix != *sfp; sfp++, shift++) {
		if (!*sfp)
			return -EINVAL;
	}
	shift = shift/2 + 1 * 10;

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2023-12-20  8:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  8:39 [PATCH 0/2] lib/kstrtox: introduce kstrtoull_suffix() helper Qu Wenruo
2023-12-15  8:39 ` [PATCH 1/2] lib/strtox: " Qu Wenruo
2023-12-18 12:59   ` David Disseldorp
2023-12-18 19:52     ` Qu Wenruo
2023-12-19  3:17       ` David Disseldorp
2023-12-19 16:42     ` David Laight
2023-12-19 21:17       ` Qu Wenruo
2023-12-20  8:31         ` David Laight [this message]
2023-12-20  9:32           ` Qu Wenruo
2023-12-15  8:39 ` [PATCH 2/2] btrfs: sysfs: use kstrtoull_suffix() to replace memparse() Qu Wenruo
2023-12-18  7:49   ` David Disseldorp
2023-12-18  8:11     ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2023-12-18 13:44 [PATCH 1/2] lib/strtox: introduce kstrtoull_suffix() helper Andy Shevchenko
2023-12-20  9:54 Alexey Dobriyan
2023-12-20 10:01 ` Qu Wenruo
2023-12-20 14:24 Andy Shevchenko
2023-12-20 20:38 ` Qu Wenruo
2023-12-21 12:00   ` Andy Shevchenko
2023-12-21 20:37     ` Qu Wenruo
2023-12-21 20:55       ` Andy Shevchenko

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=3f8ee41745ac40e58e0aa535029e8751@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=ddiss@suse.de \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=wqu@suse.com \
    /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