From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21452189F20 for ; Tue, 19 May 2026 16:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779209178; cv=none; b=Wszu0MPHwBnLdfWz0GQQCJ4pBGlpKqVYKfYG6BRtUt50rPO8pznvqb3a+mUnUOQbFBiAjx83h1aS4rwG1rpJLf1xvuLhMEfFhGYHZM19+QCijyEgCdLg2pKQfbF0H7gAsFku2OamvShyh/10iWbb4sXUS8oqWZMa+/FRqfY9FO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779209178; c=relaxed/simple; bh=xMfe17ZAWL4y5+1LYARCxPBjNUSIczhXRIEnRNa1Nbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRjFDE/uWlSJcVOlsxNch5/GT7CJTCOc+e2gojCCj5Ns0a6noO2sQ6ZAyjc88ZaSaVPIXU0LLRqbFFmAxBxiacM7IJ5kOObOsKEd8hVLCOTboWHCthq4eCnmDoGBAPf92eYvkErhYyeMai9ooKEdQjBsCWr7zO7kyPgSrRcHrd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tAtS9Fuv; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tAtS9Fuv" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779209174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dRge98VoC6LHlxse0LqTomziCzc5EOB3uv8kN0kTPMA=; b=tAtS9FuvTYxYFdvK8r04Aek71fj0lN/IeWmGRUHlI3F6FpuXJ6cvCkIP/xlpHa4za58Mul dvndbF59c0x+Cilzrpv5aRkgul5nSwN6iHTcQSPtbZghGpoLka4QLJrg/uzWDQVtKSnTfr M8k3e8/L1ngw4d01Nc/oB9IH6WNDFgo= From: Thorsten Blum To: Mikulas Patocka Cc: Thorsten Blum , 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 Message-ID: <20260519164509.180686-5-thorsten.blum@linux.dev> In-Reply-To: <20260519164509.180686-4-thorsten.blum@linux.dev> References: <20260519164509.180686-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2877; i=thorsten.blum@linux.dev; h=from:subject; bh=xMfe17ZAWL4y5+1LYARCxPBjNUSIczhXRIEnRNa1Nbg=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFk8k+fIyT+LZz1kdJl96vPSVYevf/z8/eeWaVNuHPVIP 7oiS/dZSUcpC4MYF4OsmCLLg1k/ZviW1lRuMonYCTOHlQlkCAMXpwBMZKonI8Okpneu33rN7z9V iVdlz1klUbtdQ1HkVj5/mJT7lqv2TacZGf4WKmz7n6q5atrnmw+fL7GviCn4Jr/2m8uJFsd9m1p Vk3kA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Calculate the length of the read-only key only once and reuse it. Signed-off-by: Thorsten Blum --- 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))