* [PATCH] nfsd: Replace open-coded conversion of bytes to hex
@ 2025-08-03 21:24 Eric Biggers
2025-08-04 11:55 ` Jeff Layton
2025-08-04 14:01 ` Chuck Lever
0 siblings, 2 replies; 4+ messages in thread
From: Eric Biggers @ 2025-08-03 21:24 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, linux-nfs
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Eric Biggers
Since the Linux kernel's sprintf() has conversion to hex built-in via
"%*phN", delete md5_to_hex() and just use that. Also add an explicit
array bound to the dname parameter of nfs4_make_rec_clidname() to make
its size clear. No functional change.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
fs/nfsd/nfs4recover.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index 2231192ec33f5..54f5e5392ef9d 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -90,26 +90,12 @@ static void
nfs4_reset_creds(const struct cred *original)
{
put_cred(revert_creds(original));
}
-static void
-md5_to_hex(char *out, char *md5)
-{
- int i;
-
- for (i=0; i<16; i++) {
- unsigned char c = md5[i];
-
- *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
- *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
- }
- *out = '\0';
-}
-
static int
-nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
+nfs4_make_rec_clidname(char dname[HEXDIR_LEN], const struct xdr_netobj *clname)
{
struct xdr_netobj cksum;
struct crypto_shash *tfm;
int status;
@@ -131,11 +117,11 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
cksum.data);
if (status)
goto out;
- md5_to_hex(dname, cksum.data);
+ sprintf(dname, "%*phN", 16, cksum.data);
status = 0;
out:
kfree(cksum.data);
crypto_free_shash(tfm);
base-commit: 186f3edfdd41f2ae87fc40a9ccba52a3bf930994
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: Replace open-coded conversion of bytes to hex
2025-08-03 21:24 [PATCH] nfsd: Replace open-coded conversion of bytes to hex Eric Biggers
@ 2025-08-04 11:55 ` Jeff Layton
2025-08-04 14:01 ` Chuck Lever
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2025-08-04 11:55 UTC (permalink / raw)
To: Eric Biggers, Chuck Lever, linux-nfs
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey
On Sun, 2025-08-03 at 14:24 -0700, Eric Biggers wrote:
> Since the Linux kernel's sprintf() has conversion to hex built-in via
> "%*phN", delete md5_to_hex() and just use that. Also add an explicit
> array bound to the dname parameter of nfs4_make_rec_clidname() to make
> its size clear. No functional change.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> fs/nfsd/nfs4recover.c | 18 ++----------------
> 1 file changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
> index 2231192ec33f5..54f5e5392ef9d 100644
> --- a/fs/nfsd/nfs4recover.c
> +++ b/fs/nfsd/nfs4recover.c
> @@ -90,26 +90,12 @@ static void
> nfs4_reset_creds(const struct cred *original)
> {
> put_cred(revert_creds(original));
> }
>
> -static void
> -md5_to_hex(char *out, char *md5)
> -{
> - int i;
> -
> - for (i=0; i<16; i++) {
> - unsigned char c = md5[i];
> -
> - *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
> - *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
> - }
> - *out = '\0';
> -}
> -
> static int
> -nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> +nfs4_make_rec_clidname(char dname[HEXDIR_LEN], const struct xdr_netobj *clname)
> {
> struct xdr_netobj cksum;
> struct crypto_shash *tfm;
> int status;
>
> @@ -131,11 +117,11 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
> cksum.data);
> if (status)
> goto out;
>
> - md5_to_hex(dname, cksum.data);
> + sprintf(dname, "%*phN", 16, cksum.data);
>
> status = 0;
> out:
> kfree(cksum.data);
> crypto_free_shash(tfm);
>
> base-commit: 186f3edfdd41f2ae87fc40a9ccba52a3bf930994
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: Replace open-coded conversion of bytes to hex
2025-08-03 21:24 [PATCH] nfsd: Replace open-coded conversion of bytes to hex Eric Biggers
2025-08-04 11:55 ` Jeff Layton
@ 2025-08-04 14:01 ` Chuck Lever
2025-08-04 22:51 ` Eric Biggers
1 sibling, 1 reply; 4+ messages in thread
From: Chuck Lever @ 2025-08-04 14:01 UTC (permalink / raw)
To: Eric Biggers, Jeff Layton, linux-nfs
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey
On 8/3/25 5:24 PM, Eric Biggers wrote:
> Since the Linux kernel's sprintf() has conversion to hex built-in via
> "%*phN", delete md5_to_hex() and just use that. Also add an explicit
> array bound to the dname parameter of nfs4_make_rec_clidname() to make
> its size clear. No functional change.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> fs/nfsd/nfs4recover.c | 18 ++----------------
> 1 file changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
> index 2231192ec33f5..54f5e5392ef9d 100644
> --- a/fs/nfsd/nfs4recover.c
> +++ b/fs/nfsd/nfs4recover.c
> @@ -90,26 +90,12 @@ static void
> nfs4_reset_creds(const struct cred *original)
> {
> put_cred(revert_creds(original));
> }
>
> -static void
> -md5_to_hex(char *out, char *md5)
> -{
> - int i;
> -
> - for (i=0; i<16; i++) {
> - unsigned char c = md5[i];
> -
> - *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
> - *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
> - }
> - *out = '\0';
> -}
> -
> static int
> -nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> +nfs4_make_rec_clidname(char dname[HEXDIR_LEN], const struct xdr_netobj *clname)
> {
> struct xdr_netobj cksum;
> struct crypto_shash *tfm;
> int status;
>
> @@ -131,11 +117,11 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
> cksum.data);
> if (status)
> goto out;
>
> - md5_to_hex(dname, cksum.data);
> + sprintf(dname, "%*phN", 16, cksum.data);
Hello Eric,
Can the raw "16" be replaced with "HEXDIR_LEN / 2" ?
> status = 0;
> out:
> kfree(cksum.data);
> crypto_free_shash(tfm);
>
> base-commit: 186f3edfdd41f2ae87fc40a9ccba52a3bf930994
--
Chuck Lever
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: Replace open-coded conversion of bytes to hex
2025-08-04 14:01 ` Chuck Lever
@ 2025-08-04 22:51 ` Eric Biggers
0 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2025-08-04 22:51 UTC (permalink / raw)
To: Chuck Lever
Cc: Jeff Layton, linux-nfs, NeilBrown, Olga Kornievskaia, Dai Ngo,
Tom Talpey
On Mon, Aug 04, 2025 at 10:01:49AM -0400, Chuck Lever wrote:
> On 8/3/25 5:24 PM, Eric Biggers wrote:
> > Since the Linux kernel's sprintf() has conversion to hex built-in via
> > "%*phN", delete md5_to_hex() and just use that. Also add an explicit
> > array bound to the dname parameter of nfs4_make_rec_clidname() to make
> > its size clear. No functional change.
> >
> > Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> > ---
> > fs/nfsd/nfs4recover.c | 18 ++----------------
> > 1 file changed, 2 insertions(+), 16 deletions(-)
> >
> > diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
> > index 2231192ec33f5..54f5e5392ef9d 100644
> > --- a/fs/nfsd/nfs4recover.c
> > +++ b/fs/nfsd/nfs4recover.c
> > @@ -90,26 +90,12 @@ static void
> > nfs4_reset_creds(const struct cred *original)
> > {
> > put_cred(revert_creds(original));
> > }
> >
> > -static void
> > -md5_to_hex(char *out, char *md5)
> > -{
> > - int i;
> > -
> > - for (i=0; i<16; i++) {
> > - unsigned char c = md5[i];
> > -
> > - *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
> > - *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
> > - }
> > - *out = '\0';
> > -}
> > -
> > static int
> > -nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> > +nfs4_make_rec_clidname(char dname[HEXDIR_LEN], const struct xdr_netobj *clname)
> > {
> > struct xdr_netobj cksum;
> > struct crypto_shash *tfm;
> > int status;
> >
> > @@ -131,11 +117,11 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
> > status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
> > cksum.data);
> > if (status)
> > goto out;
> >
> > - md5_to_hex(dname, cksum.data);
> > + sprintf(dname, "%*phN", 16, cksum.data);
>
> Hello Eric,
>
> Can the raw "16" be replaced with "HEXDIR_LEN / 2" ?
>
>
> > status = 0;
> > out:
> > kfree(cksum.data);
> > crypto_free_shash(tfm);
> >
> > base-commit: 186f3edfdd41f2ae87fc40a9ccba52a3bf930994
It's the same 16 as was there before. It really should be
MD5_DIGEST_SIZE, but there are a few more things to clean up regarding
that. I didn't want to bloat the scope of this patch.
I sent a new series with this patch unchanged, but the digest size stuff
cleaned up in another patch.
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-04 22:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-03 21:24 [PATCH] nfsd: Replace open-coded conversion of bytes to hex Eric Biggers
2025-08-04 11:55 ` Jeff Layton
2025-08-04 14:01 ` Chuck Lever
2025-08-04 22:51 ` Eric Biggers
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).