All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Cc: Thorsten Blum <thorsten.blum@linux.dev>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] fs: hpfs: calculate key length only once in hpfs_set_ea
Date: Tue, 19 May 2026 18:45:11 +0200	[thread overview]
Message-ID: <20260519164509.180686-5-thorsten.blum@linux.dev> (raw)
In-Reply-To: <20260519164509.180686-4-thorsten.blum@linux.dev>

Calculate the length of the read-only key only once and reuse it.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 fs/hpfs/ea.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/fs/hpfs/ea.c b/fs/hpfs/ea.c
index 3f0213486c21..1d7c1f67be9f 100644
--- a/fs/hpfs/ea.c
+++ b/fs/hpfs/ea.c
@@ -198,6 +198,8 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
 	unsigned char h[4];
 	struct extended_attribute *ea;
 	struct extended_attribute *ea_end = fnode_end_ea(fnode);
+	const size_t key_len = strlen(key);
+
 	for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
 		if (!strcmp(ea->name, key)) {
 			if (ea_indirect(ea)) {
@@ -245,15 +247,16 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
 		return;
 	}
 	if ((le16_to_cpu(fnode->ea_size_s) || !le32_to_cpu(fnode->ea_size_l)) &&
-	     le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) + strlen(key) + size + 5 <= 0x200) {
+	     le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) +
+	     le16_to_cpu(fnode->ea_size_s) + key_len + size + 5 <= 0x200) {
 		ea = fnode_end_ea(fnode);
 		*(char *)ea = 0;
-		ea->namelen = strlen(key);
+		ea->namelen = key_len;
 		ea->valuelen_lo = size;
 		ea->valuelen_hi = size >> 8;
 		strcpy(ea->name, key);
 		memcpy(ea_data(ea), data, size);
-		fnode->ea_size_s = cpu_to_le16(le16_to_cpu(fnode->ea_size_s) + strlen(key) + size + 5);
+		fnode->ea_size_s = cpu_to_le16(le16_to_cpu(fnode->ea_size_s) + key_len + size + 5);
 		goto ret;
 	}
 	/* Most the code here is 99.9993422% unused. I hope there are no bugs.
@@ -275,7 +278,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
 		mark_buffer_dirty(bh);
 		brelse(bh);
 	}
-	pos = le32_to_cpu(fnode->ea_size_l) + 5 + strlen(key) + size;
+	pos = le32_to_cpu(fnode->ea_size_l) + 5 + key_len + size;
 	len = (le32_to_cpu(fnode->ea_size_l) + 511) >> 9;
 	if (pos >= 30000) goto bail;
 	while (((pos + 511) >> 9) > len) {
@@ -325,7 +328,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
 		}
 	}
 	h[0] = 0;
-	h[1] = strlen(key);
+	h[1] = key_len;
 	h[2] = size & 0xff;
 	h[3] = size >> 8;
 	if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l), 4, h)) goto bail;
@@ -333,7 +336,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
 	if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l) + 5 + h[1], size, data)) goto bail;
 	fnode->ea_size_l = cpu_to_le32(pos);
 	ret:
-	hpfs_i(inode)->i_ea_size += 5 + strlen(key) + size;
+	hpfs_i(inode)->i_ea_size += 5 + key_len + size;
 	return;
 	bail:
 	if (le32_to_cpu(fnode->ea_secno))

  reply	other threads:[~2026-05-19 16:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 16:45 [PATCH 1/3] fs: hpfs: remove commented out code in hpfs_set_ea Thorsten Blum
2026-05-19 16:45 ` Thorsten Blum [this message]
2026-05-19 16:45 ` [PATCH 3/3] fs: hpfs: replace deprecated strcpy with memcpy " Thorsten Blum

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=20260519164509.180686-5-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikulas@artax.karlin.mff.cuni.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.