From patchwork Fri Feb 28 10:01:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13996128 X-Patchwork-Delegate: geliang@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 92B2025D559; Fri, 28 Feb 2025 10:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736925; cv=none; b=uXXOywi08e/ZG/8MxZujS7TtkSaZYD3fIUcglInRMDc7W/Ej7RMahqsFZzikiCp9yNJubxfkUUR4kerHM9Ox2lx2I1O45S5cDtmabfkQbasyT7er1ZsnsC9Mt6YGaBh9SNYglOgkGXylmdxm+IrYSeCwNjo8hT17cqre3ERaejE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736925; c=relaxed/simple; bh=74yTkQnIWdu4oYvGKAnTJbzZweABw7andTw5FBDDA0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qymdGocGvZMVLjKtiZcAWFyDUyFO+fEtfIMJsAeQ1oXk+GAqOe4gi8bkaxn23I0hXdhKFxPLkrxNrRZUoVBrjkmYT535VnfhRVGSvqjJiVWeNia+CrhZ0kDX9WJzyHWq0AxhHjxQGbXigI31Jsba7zImlohETDYQGhK8eICgjfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=msaZkFAQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="msaZkFAQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89B2DC4CED6; Fri, 28 Feb 2025 10:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740736925; bh=74yTkQnIWdu4oYvGKAnTJbzZweABw7andTw5FBDDA0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=msaZkFAQ05HmgjecjY/WhP+zGeTMJp4HL4248ndjfD5M08oukgGTEQRe2T8GuSe9P do77QMYgbdpZ8pMI92WkCf9fCbJ0oL8jD+wlsNPg0kWDqolOXBC7+oNpSrPDyUpd6e KRFUX2HmznwZghMzLRMj17g59luy05CHwSeafwVq5PvoYgYYEEElrPLZ1BDaIe71SA 8li0sPLUpJGDCp7OwqLSLYlJEmI7Kn6MGKRc9bUwbbjptxLK+3neswa37wflVRY+Nb S6tqLlT0A6nvUoCDCr1VdUS+DtPJ1lPoJIT0mzXw2NxNlw0rbyGgdCzrcgCLC5sebd 0MpXDWDe6mYsA== From: Geliang Tang To: Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Neal Cardwell , David Ahern , Matthieu Baerts , Mat Martineau , Marcelo Ricardo Leitner , Xin Long Cc: Geliang Tang , netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org Subject: [PATCH net-next v2 3/3] mptcp: use sock_kmemdup for address entry Date: Fri, 28 Feb 2025 18:01:33 +0800 Message-ID: <3e5a307aed213038a87e44ff93b5793229b16279.1740735165.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Instead of using sock_kmalloc() to allocate an address entry "e" and then immediately duplicate the input "entry" to it, the newly added sock_kmemdup() helper can be used in mptcp_userspace_pm_append_new_local_addr() to simplify the code. More importantly, the code "*e = *entry;" that assigns "entry" to "e" is not easy to implemented in BPF if we use the same code to implement an append_new_local_addr() helper of a BFP path manager. This patch avoids this type of memory assignment operation. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6bf6a20ef7f3..7e7d01bef5d4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -71,13 +71,12 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, /* Memory for the entry is allocated from the * sock option buffer. */ - e = sock_kmalloc(sk, sizeof(*e), GFP_ATOMIC); + e = sock_kmemdup(sk, entry, sizeof(*entry), GFP_ATOMIC); if (!e) { ret = -ENOMEM; goto append_err; } - *e = *entry; if (!e->addr.id && needs_id) e->addr.id = find_next_zero_bit(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1,