linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	dm-devel@redhat.com
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH] dm-crypt: Slightly simplify crypt_set_keyring_key()
Date: Sat, 28 Jan 2023 16:43:00 +0100	[thread overview]
Message-ID: <c3d25e24503d9e625cf46e9fb4ee55f10bfdd398.1674920529.git.christophe.jaillet@wanadoo.fr> (raw)

Use strchr() instead of strpbrk() when there is only 1 element in the set
of characters to look for.
This potentially saves a few cycles.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
On my machine, the diff of the .s file shows that the generated code is
the same:

-- drivers/md/dm-crypt.old.s	2023-01-28 16:28:08.968026902 +0100
++ drivers/md/dm-crypt.s	2023-01-28 16:28:32.056027335 +0100
@@ -17950,7 +17950,7 @@
 	call	__sanitizer_cov_trace_const_cmp1	#
 	testb	%bl, %bl	# _56
 	jne	.L928	#,
-# drivers/md/dm-crypt.c:2490: 	key_desc = strpbrk(key_string, ":");
+# drivers/md/dm-crypt.c:2490: 	key_desc = strchr(key_string, ':');
 	call	__sanitizer_cov_trace_pc	#
 	movl	$58, %esi	#,
 	movq	%r12, %rdi	# key_string,

This is done thanks to fold_builtin_strpbrk() in gcc which already
transforms such patterns.
(https://github.com/gcc-mirror/gcc/blob/master/gcc/builtins.cc#L10238)
---
 drivers/md/dm-crypt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 2653516bcdef..b9c41fd42e8a 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2487,7 +2487,7 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
 	}
 
 	/* look for next ':' separating key_type from key_description */
-	key_desc = strpbrk(key_string, ":");
+	key_desc = strchr(key_string, ':');
 	if (!key_desc || key_desc == key_string || !strlen(key_desc + 1))
 		return -EINVAL;
 
-- 
2.34.1


                 reply	other threads:[~2023-01-28 15:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=c3d25e24503d9e625cf46e9fb4ee55f10bfdd398.1674920529.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).