From patchwork Sat Sep 28 15:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thorsten Blum X-Patchwork-Id: 1990489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NKpd00nq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-2942-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XG9XW16znz1xt9 for ; Sun, 29 Sep 2024 01:01:47 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4A66E1C20F67 for ; Sat, 28 Sep 2024 15:01:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAEC517999; Sat, 28 Sep 2024 15:01:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NKpd00nq" X-Original-To: linux-cifs@vger.kernel.org Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 9BD031CFBE for ; Sat, 28 Sep 2024 15:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727535696; cv=none; b=ZUMfDsNRQfe7xoph84w0MUi8KezRwBM96gKsuOzzkYhFqR8qa2OMplxN8eSmAA0ym84v5YcUdAs6p7N1VRYa94jdbPckXPJ49uMUxhBCWJtkb4sAzbxKVRHUJyKAHZud7ZxmuFko1piHUNHoceNsghD0QKpmU3gNFiinTd7YYnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727535696; c=relaxed/simple; bh=hQbNGU+VoX7SrygvtUBPpfRaQb5XWKk/IVkjxCjnCZs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SlRp7jyTytuRhlSXOFFXfZG67mf3ogY3HONXb1H0Vxgj0SVaKd/eK8Hz2BdWJAd4f9f7VVNLhx6W8NTjh3p/Bp4wTQlIOeKg1zh3d900tW/yxEwF4PYQYDKdLl5O504/vRrZVnvN0t0HM5jH+ScZ1s9fNCgxWqhJx+cIPY3v4gk= 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=NKpd00nq; arc=none smtp.client-ip=95.215.58.174 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 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=1727535692; 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=FEgxMd7iJWObOMaqxmGr+avDbf/vb2+1l6khmidZT+U=; b=NKpd00nqs1RcAhOEZMMQPj3AmVzP32EtusjN2EIY/PIeoH3KZFk/40qoHv8YMC9D6TxmoR zBO2SNzlwISr8ZOzHtSQuetPlY2rS0QkkZc2xnyXzm/ywEK3BvLsM/B2pYZHra/qj0E0cp 8kMpUR3Y6iWMRcosJDohLcb0sdF+yrA= From: Thorsten Blum To: Namjae Jeon , Steve French , Sergey Senozhatsky , Tom Talpey Cc: Thorsten Blum , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ksmbd: Use struct_size() to improve smb_direct_rdma_xmit() Date: Sat, 28 Sep 2024 17:00:30 +0200 Message-ID: <20240928150030.1217-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Use struct_size() to calculate the number of bytes to allocate for a new message. Signed-off-by: Thorsten Blum --- fs/smb/server/transport_rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/server/transport_rdma.c b/fs/smb/server/transport_rdma.c index 44c87e300c16..17c76713c6d0 100644 --- a/fs/smb/server/transport_rdma.c +++ b/fs/smb/server/transport_rdma.c @@ -1405,8 +1405,8 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t, /* build rdma_rw_ctx for each descriptor */ desc_buf = buf; for (i = 0; i < desc_num; i++) { - msg = kzalloc(offsetof(struct smb_direct_rdma_rw_msg, sg_list) + - sizeof(struct scatterlist) * SG_CHUNK_SIZE, GFP_KERNEL); + msg = kzalloc(struct_size(msg, sg_list, SG_CHUNK_SIZE), + GFP_KERNEL); if (!msg) { ret = -ENOMEM; goto out;