From nobody Sun Nov 24 11:32:07 2024 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 B55551D27B1 for ; Tue, 5 Nov 2024 10:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730802887; cv=none; b=FFG0D/SW3M0O8eMS7YDlLf/A7YU24CbUVeL+VdORnDNOyFmONBJpSgRWBxbZF83iMWk8YYbJ90iBEYRE5bgL8rgSO/i5oXZmcHCoNEmJGiCO3U9I3+XdIzsU67XnK1fEIz7fZY/qpgiWXB6vKAQjofZ4lKPF5Psz8KF7vz8Velk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730802887; c=relaxed/simple; bh=o19pOLVRuV8QLxfVNynlAUR3xvLHuQpqYZTC4QqMP9o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JAPPFnMizyaSrnv/OvCO4V8JL9y6t+yGqXOyfOeFtLS/vSS4BnC5YznblaeNPSuC+Ki39m73mlEXihVzFnVBd0MapRnEsFIH0ncoMT02dODn0DQRa7aKafmOoXF1+/t8msb83+aQNaBYG9Z1Pt+b6+T7kfF7hHbixDAot7cSJj8= 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=jQnA1uty; arc=none smtp.client-ip=91.218.175.189 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="jQnA1uty" 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=1730802882; 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; bh=6IhfWc24TP3aBHz+VeNS6qFTszlyYP3fBuPWQXFnk1I=; b=jQnA1uty0Hub5qO8V1aykRd1R518d12EIIDmgXMjRZFja35zFIXJ8j5dqZmZg6llfQ38tv uYPRNtz1K4s3zgh1YcbUHD+jFVlBGDjmgOWldEVgE0lgih80Z355hY684xYU3v5t0FKl28 7FAsUrIntRRTDVifktoLBxoTgtR9PgA= From: Thorsten Blum To: "Theodore Ts'o" , Andreas Dilger Cc: Greg KH , Thorsten Blum , Jan Kara , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ext4: Use struct_size() to improve ext4_htree_store_dirent() Date: Tue, 5 Nov 2024 11:33:54 +0100 Message-ID: <20241105103353.11590-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Inline and use struct_size() to calculate the number of bytes to allocate for new_fn and remove the local variable len. Reviewed-by: Jan Kara Signed-off-by: Thorsten Blum --- This change was originally part of another patch that was split into two separate patches after feedback from Greg KH - Link: https://lore.kernel.org/r/20241104234214.8094-2-thorsten.blum@linux= .dev/ --- fs/ext4/dir.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 233479647f1b..02d47a64e8d1 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __= u32 hash, struct rb_node **p, *parent =3D NULL; struct fname *fname, *new_fn; struct dir_private_info *info; - int len; =20 info =3D dir_file->private_data; p =3D &info->root.rb_node; =20 /* Create and allocate the fname structure */ - len =3D sizeof(struct fname) + ent_name->len + 1; - new_fn =3D kzalloc(len, GFP_KERNEL); + new_fn =3D kzalloc(struct_size(new_fn, name, ent_name->len + 1), + GFP_KERNEL); if (!new_fn) return -ENOMEM; new_fn->hash =3D hash; --=20 2.47.0