From nobody Thu Sep 24 20:37:47 2026 Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (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 817D83DB31D for ; Sun, 20 Sep 2026 07:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888510; cv=none; b=nZUf2crXV2nHGZfP0UnxWkxpIQAom5Dp5tBP3xUQ3C8lJYxFS7r5fdLXcDkgU3CEe4+kAB4R+tZptQCjVnAVzbRZ7v/gIyldJbzZZT3QJgmojVthZ/Wnbf/lTCNzt7NxXTpKi51TxxRiq0Zc4Q7JaZVOaUsZriQTH78OYnJqUfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888510; c=relaxed/simple; bh=HmVHovqaH2BWMmC0FN3oygzDg9d/5Qdk4fguOZEYDww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qobSPywRDiIrL8EpCRR++0yjRYbooEtaKJ7k5yFpD4XSqK0aERSCxs8p+XlFQjptk0gbZA0ZAa3MmlE4IQfSsP9a7U7E7WcD8zBta6CGpYN7MQqK9qs27dem3WRYcn0QCfGfNZUM16bF0/buvcUe+C6nKu/eZn9ENhF/oYpMwxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=VKtaahfY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ylr39KdW; arc=none smtp.client-ip=202.12.124.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="VKtaahfY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ylr39KdW" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id C621A1D00142; Sun, 20 Sep 2026 03:15:07 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sun, 20 Sep 2026 03:15:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1789888507; x= 1789974907; bh=yLiW47WDIGUjTiNv+xA9aubHfInemwuUAB8PJ3+rGcs=; b=V KtaahfYlOSJwL0zUGCwLduQAOGFimlT2yTCdK2JHIKmNdPNvrGMCXn/sSKGKtPGf +ytkBrdvOw+ZMC0O+LYbLt9rvU5J1dpiw1bTJFHqpuWlYl0rftrQB30mf0jadABx 3Sx9rqkCdodviW8oiwvWBcMEU5sQPb55HG8CYZrmo2K28Pyd8o2r7g67vQdmAGoe YgTyWIvADZLDft5Ja0kW+6GQZ4zrlQiuatspl1lPo2Gbs46doqIBtOhSTfI3dg1k 0Oe7YSnrmbbWOTdH2Yn9N6e23899+a2kuTPxtkBa0mIdgjkPZO5z4dMHQqULrtKj a24ftBSldd9Nt9ADX++jA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789888507; x=1789974907; bh=y LiW47WDIGUjTiNv+xA9aubHfInemwuUAB8PJ3+rGcs=; b=Ylr39KdW+D/krm96h nd/N9egkG5WQ1FUUcFYCJoucKB2ISWPQij5wUASYm6f3U+gwuEsghuQ6+/Z/aa/L kWIxhbEilqlkn2jFBGmzebFaRdUquwA7uxq830hjfRO6VgXyyxnhzBtswOf+MlwS 2oqlmZEL0a5q9AG0sitDRqTiLmra6r5kKet3i47G1sexjPH9ES2wDpspYSg0Vaiz SalL6p4M4qCpQTAsg0UPAXKdobe3S75NuBGFTxfcU9BTWxgvHcMDj7PuaG0M+snT 5hWeT9yk9kWOS5UAfxLVZgKLFbfAODUpu9AZBBQHqsPG2s4tlCfUI+JjLXvrv9lb wJrpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGyn/xqJvXtDE0aXPg7VTWwa6ZytMhAGR7nxGfLocNGHdWz0wX8vkRz8WdekLHOxF ueygXEtIzUz+6+8Nu5jOylzMouJEEmUtyHAiF3hAv/PQOii+fQIaA16F9rGbK5eIj+gHX2 7oWQRylPS9prm6P0pulDgCxjr7FHQNIloAyG1sC2/WA+6SlZoZfvrwyAbbTgLETU6XAsrH oSG/gVQ4B96IyAbe0lc8e/7OyBZYZjJJI2xl3NT5AIvarGgLVxYLAZiD4NlCbAozg+Dur+ szvikqwlwyyPnE8AnV3AbHNmxlz1ORsNjtHjAvxgWdsXLx1vkCYM0HOOrP6u1ZYIqTWEhu oKDeBhJFZrJ7k8s9CSnZUSkS+icbgzJdPJo70lP6GBss5zWaqNxtjBbrtEkTT1ZUtWvGU8 H/qoFqI6AzfwnyDTvgeWx6gGq9f9jjjwF18RewXuHQ6bmh8QP/DXmW+czwAP4vBjoMGfnC ugeWkFnhFG2a6bujeX6ppTY/RW7hLiRILPPeW6wh5D6JIUjQmMzD1lT1mP3Mz/Nx6QUbay Oz/Ewbsdv2KyhLINVTBhOnBBHOxENoHTbv1E+2H7jLUn5/U9DswOIctHODNM0oK4du/Frx xg+sH2faLfCkxW9vuaL4uaDRdurIvIkYabbA87kjIuwLf2mLUyTmz2ZPUqGA X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Sep 2026 03:15:06 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/5] firewire: cdev: use memory barrier to access fw_device members Date: Sun, 20 Sep 2026 16:14:57 +0900 Message-ID: <20260920071501.77785-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260920071501.77785-1-o-takashi@sakamocchi.jp> References: <20260920071501.77785-1-o-takashi@sakamocchi.jp> 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 Content-Type: text/plain; charset="utf-8" The core code uses a read memory barrier when accessing the generation and node_id members of the fw_device structure. It assumes that the latest value of the former is visible to a processor core when the latest value of the latter is visible, since these members are updated in reverse order with a write memory barrier. However, the function that fills the fw_cdev_event_bus_reset structure does not follow this approach. Use a read memory barrier when accessing these members. --- drivers/firewire/core-cdev.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index e49d8a58be09..9a3be1ceee2a 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -399,18 +399,21 @@ static ssize_t fw_device_op_read(struct file *file, c= har __user *buffer, static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, struct client *client) { - struct fw_card *card =3D client->device->card; - - guard(spinlock_irq)(&card->lock); - event->closure =3D client->bus_reset_closure; event->type =3D FW_CDEV_EVENT_BUS_RESET; + event->generation =3D client->device->generation; + smp_rmb(); event->node_id =3D client->device->node_id; - event->local_node_id =3D card->local_node->node_id; - event->bm_node_id =3D card->bm_node_id; - event->irm_node_id =3D card->irm_node->node_id; - event->root_node_id =3D card->root_node->node_id; + + struct fw_card *card =3D client->device->card; + + scoped_guard(spinlock_irq, &card->lock) { + event->local_node_id =3D card->local_node->node_id; + event->bm_node_id =3D card->bm_node_id; + event->irm_node_id =3D card->irm_node->node_id; + event->root_node_id =3D card->root_node->node_id; + } } =20 static void for_each_client(struct fw_device *device, --=20 2.53.0 From nobody Thu Sep 24 20:37:47 2026 Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 E29163DCDA3 for ; Sun, 20 Sep 2026 07:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888511; cv=none; b=u3RxvrHheOdy2PSZx0h2XzPMG8yu6tJhwFL8SA/osEBIuu3v2FGLi6XhXlqe2xvx2Gbf+mtVZi8C8QZ1mZ+pFZkrAyfX3W9LimEHoDhiznQc+eA/eGU/NsebAQbleZr8qTCddc1UofALxrbYEEKnVIiRxwxjNbuWy6qqvef1Rkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888511; c=relaxed/simple; bh=xCvX0r2+9DbN8KCqQqZIM9j9S7ktaldGgB7Y0AgYsx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hlCd++NZpeMsJizYc/2rMicF4Du76p85wb848M9T6A9zxec8VMvlFiOYf35tDxfmZvX8pFdKJKcNUOet2W0C4Iwz5ff3VUF0Uf0Fp5RV6Cu4gNSFZOxC0aHhzsoOoV8miwu4zU4k0QJu0hNShxNnIFoYtt94RZGNJSzJK++1bAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=6phidd7/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GLKbx8H3; arc=none smtp.client-ip=202.12.124.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="6phidd7/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GLKbx8H3" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 34A497A00C2; Sun, 20 Sep 2026 03:15:09 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sun, 20 Sep 2026 03:15:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1789888509; x= 1789974909; bh=6meny2E9weN/v00lFIjpwStwlHOauFcGKONCne7WeMg=; b=6 phidd7/QyHPNj9m/9qy6W51fI7m21q0GujzTXLXS2iIhvaOLJtw0Sa015pnkMct8 kizYWG8BDnrZHVZh96VP5DVEyIPS45l8ZPDtptMdrZJWyWxC4OeBOTBXv+zgPaRb 6+JpZ8BWUnG+OfZoeg6dpjrVAx2YJOgd0Zm9QUnHwmqjwEzRWWxCC001hDGk0pf/ 0xu7FS06Z22fuFWzoF+dYVF6TdoIxtA2t7GMW0uvr0R6HUNAvrDg6FiaqYBgw9vw ubwcrTgzHVhSX3QErR2RUJBOLjAIcRvfaFXVA6pwgTbvrxbY+5Ds67xKh9X3Ixue BAw4Jf7sNtx0NsUlUTkPw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789888509; x=1789974909; bh=6 meny2E9weN/v00lFIjpwStwlHOauFcGKONCne7WeMg=; b=GLKbx8H3MnG77FVYQ 2RvpV5t3PgD9uGSv4KIEfD4m44KyAD1MxdRtvJWw9w/7C/PLyWPD7UnAf6vFVHNy 5lcjrpjWaijcYTWFxRh3JuBtXGs2GAidCp+Jvn/03dqbOVyuoyrC402ezmej3Xjn a8SlRd9F0sSrNLP8voxOP4jbc3CJkJK5Q8J57UboFOlZK3jO7mP6oz1v1Uv3sEBM cOuTMH7toQITuCDAgPHXqDXwS5vw5X0Z+OTWJ1FzOFzk6iyFD2xCA493pguIGHQF zNsPZfQSVJV16wH0kpnR/dFIM+I7sRwDnTJvzA3mjOfXML/MklR7vEOn6DGIowXh Lc6mA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGyn/xqJvXtDE0aXPg7VTWwa6ZytMhAGR7nxGfLocNGHdWz0wX8vkRz8WdekLHOxF ueygXEtIzUz+6+8Nu5jOylzMouJEEmUtyHAiF3hAv/PQOii+fQIaA16F9rGbK5eIj+gHX2 7oWQRylPS9prm6P0pulDgCxjr7FHQNIloAyG1sC2/WA+6SlZoZfvrwyAbbTgLETU6XAsrH oSG/gVQ4B96IyAbe0lc8e/7OyBZYZjJJI2xl3NT5AIvarGgLVxYLAZiD4NlCbAozg+Dur+ szvikqwlwyyPnE8AnV3AbHNmxlz1ORsNjtHjAvxgWdsXLx1vkCYM0HOOrP6u1ZYIqTWEpR 6LQS1/0cs+rWuUhQ8MClIlX+PHOdTIf3vzNEJXf1LamyxLXjDGg1qERe9Iq7RT/4QcLeBr JRXkXTuyOrJRoQQheEVl1w/y+RCKlEeKBMvaTa9A4zNdNbMGLAgnSVKlH8/ijw8hKNAaGU dZn/7uYUN07IinM9kCEXiPQGVKokxg+xU2qhGq/PaoBSokjEBVz3N3hIh4Egu2G/CqRWfM hDVOnGK3JIxi3Nyb8a11eqjdcpcSMNZisuGHUPfOE3HLaFRt5Oau4Fx36qs7Uk9ymBbQtF Mh92iPrRFNo00mMAKgmWUoXwIJRR4z6dPkMRpUZFO6neu7FmcQJexP9hFplA X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Sep 2026 03:15:08 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/5] firewire: cdev: refactor using scoped_guard() for get_info ioctl call Date: Sun, 20 Sep 2026 16:14:58 +0900 Message-ID: <20260920071501.77785-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260920071501.77785-1-o-takashi@sakamocchi.jp> References: <20260920071501.77785-1-o-takashi@sakamocchi.jp> 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 Content-Type: text/plain; charset="utf-8" The scope of scoped_guard() corresponds to the code block, making it easier to understand which code is protected by the locking primitive. --- drivers/firewire/core-cdev.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 9a3be1ceee2a..bdc16207d743 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -491,7 +491,6 @@ union ioctl_arg { static int ioctl_get_info(struct client *client, union ioctl_arg *arg) { struct fw_cdev_get_info *a =3D &arg->get_info; - struct fw_cdev_event_bus_reset bus_reset; unsigned long ret =3D 0; =20 client->version =3D a->version; @@ -511,16 +510,21 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) a->rom_length =3D client->device->config_rom_length * 4; } =20 - guard(mutex)(&client->device->client_list_mutex); + scoped_guard(mutex, &client->device->client_list_mutex) { + client->bus_reset_closure =3D a->bus_reset_closure; =20 - client->bus_reset_closure =3D a->bus_reset_closure; - if (a->bus_reset !=3D 0) { - fill_bus_reset_event(&bus_reset, client); - /* unaligned size of bus_reset is 36 bytes */ - ret =3D copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36); + if (a->bus_reset !=3D 0) { + struct fw_cdev_event_bus_reset bus_reset; + + memset(&bus_reset, 0, sizeof(bus_reset)); + fill_bus_reset_event(&bus_reset, client); + + /* unaligned size of bus_reset is 36 bytes */ + ret =3D copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36); + } + if (ret =3D=3D 0 && list_empty(&client->link)) + list_add_tail(&client->link, &client->device->client_list); } - if (ret =3D=3D 0 && list_empty(&client->link)) - list_add_tail(&client->link, &client->device->client_list); =20 return ret ? -EFAULT : 0; } --=20 2.53.0 From nobody Thu Sep 24 20:37:47 2026 Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (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 710253DDDAF for ; Sun, 20 Sep 2026 07:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888513; cv=none; b=UTGuDVJAd+z8ysvI80bnokqcXusJVMTTpbf2G7M88SU2bgFZme0xjMutMeGrvncyvrlSb9KWmPyktlAFJG6woPfKwv2yvorftaMJB4wEDlbgYEhCEHHjSMJv5VGuygITCtf73Auxq2rhKBjLA0yULd5gPQ3Q3z49I3dDQVQYqg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888513; c=relaxed/simple; bh=40rlKOgfgYV0dDT+vCxjxoB+YCsrHOW8CY9MyyoFfqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B0DLkaEFGMwy8r8eu1Rtle7lKI/3uBb5X0DCeJ2PPohAJ6VyDky3YZJmxuWm8g8qKdl+/k8n6mgBMOvCZLaSuuIRcXYK/b0uuX+gWTDC3qf0KJ6+M+AwdrBNGvpalzOwQQo/LyOxdq+mpWxCfsqiKc3D1AuFNSNQOTbJzeWN4H0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=qsw9Lxq0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eoUTapFh; arc=none smtp.client-ip=202.12.124.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="qsw9Lxq0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eoUTapFh" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 9AB6B1D0016A; Sun, 20 Sep 2026 03:15:10 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sun, 20 Sep 2026 03:15:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1789888510; x= 1789974910; bh=7rwET8xn9DtwjdIjkAbpf+WcWyXALAWfahZ44Reyg8g=; b=q sw9Lxq0eWp7e24BzdDHfJ3Goue3dUb12QLrqlpDB2Nv1P4Bw4tOzbUdQtOe/0Jm2 wNx9nzYMqJDRfvKH0WeXuA+TrJW6AkogPFRKIAuU/0t8sBveFo97WaXkPzq/WaDo cD+2QT0HGvC3Zd3rWlZOt6AI29OgIAKoLVWwqxSiEV4Nuevbt0x6rBDoM2sa7WRP 952msPL5vNpRh6FRB+5LKdLT9RJ9dtI0ctkb73Z5/LWnntOKaVnFtGknsyPT3BD+ oomTxtscwAoHT6NzIl7hjimQByxqEQacmxOnhk5gIHKV3gsjsNSGoGeqykndNa3W qpOtphSmijN+R+q9Bb5Qw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789888510; x=1789974910; bh=7 rwET8xn9DtwjdIjkAbpf+WcWyXALAWfahZ44Reyg8g=; b=eoUTapFhKaeaZXCLX m7m2iND3RndZWlFbAztMHklcd59Sre699PrOcmMnumARc/uNUAFejGAFj5x6pzxX LwqmEMck3ZsMRDynyQLmIwhO0V+sDGTFGaWO1bHSjY27zVKWpQPoabrcMkO0lxgq OrTpa7OrVNya+bW2qZNt83jRzn1DTTa1kVEldYVKNeaCaMvV28Dz7hQVh7jypqqn +HRfvSKnZKEsnLWDXh74qwczrtjJkVWAg2IqkioY/eC7R6D23X7N5a4M1iJ1Vhgp Sdx4iROA+kcL4zPzrfYIoaPcdsyy+4az72P4CryR3sVOEQfv9Pbb483oelBwVnkz zfwhg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGyn/xqJvXtDE0aXPg7VTWwa6ZytMhAGR7nxGfLocNGHdWz0wX8vkRz8WdekLHOxF ueygXEtIzUz+6+8Nu5jOylzMouJEEmUtyHAiF3hAv/PQOii+fQIaA16F9rGbK5eIj+gHX2 7oWQRylPS9prm6P0pulDgCxjr7FHQNIloAyG1sC2/WA+6SlZoZfvrwyAbbTgLETU6XAsrH oSG/gVQ4B96IyAbe0lc8e/7OyBZYZjJJI2xl3NT5AIvarGgLVxYLAZiD4NlCbAozg+Dur+ szvikqwlwyyPnE8AnV3AbHNmxlz1ORsNjtHjAvxgWdsXLx1vkCYM0HOOrP6u1ZYIqTWEjA L/JwAairObteiKSqg55yM37AQyrdYrGBXsW6cJGL+94XKVPxOsqFupNa3IwvPlMfRpsDE5 4RTRESl+eq/k8O4NWPG2o7rU9JSsOEuUoUN/wUGBz0dCoC1q+0jkZLrO5BXLS+cO1HBEQF 4LSrA5BOuHs4pfPkBw7SL0REkgj4h+FOcUTlh1cQF0G4pYysFT7VyTdQ27uXuBe+f4ukKb QnQdQjVEFJfilDUU2C4sj2nLZPYaPrhLZIlOamSuzRgWGipvHykbs9h7B7R9a+cCnUqsv/ 8IM1OVT4kUN01fakDXdXcHjVxipvEGCRgQTXYFYinTcofIKuI5Zoh6QjRPKg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Sep 2026 03:15:09 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/5] firewire: cdev: refactor copy_to_user() in get_info ioctl call Date: Sun, 20 Sep 2026 16:14:59 +0900 Message-ID: <20260920071501.77785-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260920071501.77785-1-o-takashi@sakamocchi.jp> References: <20260920071501.77785-1-o-takashi@sakamocchi.jp> 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 Content-Type: text/plain; charset="utf-8" A non-zero return value from copy_to_user() is handled by returning -EFAULT. Using scoped_guard() simplifies this handling, since it eliminates the need for a local variable to store the return value and check it after the locking primitive is released. Refactor the code to remove the local variable. --- drivers/firewire/core-cdev.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index bdc16207d743..25590580b993 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -491,7 +491,6 @@ union ioctl_arg { static int ioctl_get_info(struct client *client, union ioctl_arg *arg) { struct fw_cdev_get_info *a =3D &arg->get_info; - unsigned long ret =3D 0; =20 client->version =3D a->version; a->version =3D FW_CDEV_KERNEL_VERSION; @@ -499,12 +498,10 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) =20 scoped_guard(rwsem_read, &fw_device_rwsem) { if (a->rom !=3D 0) { - size_t want =3D a->rom_length; - size_t have =3D client->device->config_rom_length * 4; + size_t length =3D min_t(size_t, a->rom_length, + client->device->config_rom_length * 4); =20 - ret =3D copy_to_user(u64_to_uptr(a->rom), client->device->config_rom, - min(want, have)); - if (ret !=3D 0) + if (copy_to_user(u64_to_uptr(a->rom), client->device->config_rom, lengt= h)) return -EFAULT; } a->rom_length =3D client->device->config_rom_length * 4; @@ -520,13 +517,15 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) fill_bus_reset_event(&bus_reset, client); =20 /* unaligned size of bus_reset is 36 bytes */ - ret =3D copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36); + if (copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36)) + return -EFAULT; } - if (ret =3D=3D 0 && list_empty(&client->link)) + + if (list_empty(&client->link)) list_add_tail(&client->link, &client->device->client_list); } =20 - return ret ? -EFAULT : 0; + return 0; } =20 static int add_client_resource(struct client *client, struct client_resour= ce *resource, --=20 2.53.0 From nobody Thu Sep 24 20:37:47 2026 Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 EA4F63DE457 for ; Sun, 20 Sep 2026 07:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888515; cv=none; b=KnggsMohXefxhItCV8MPKkD1KKZ4+WuNQNQ71WUC0jF3HPIimHKQJ0jX07cxWuJ3/YImrq33Cwr8Wvpoi02j7xznHvLzKeFz4I7az/4q6j0oUM36lZhi/mjPNmtWjk93GliKo+GEhjQVc02Y6FZHEqbZBSnSzY3+gK8xDRxZQJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888515; c=relaxed/simple; bh=mhjWhChiuAnCZR8l5HgOJ/bB1pv2SGyopst0H57wIjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHv+feRgL3vbfM1RrPgz5eU450HGLpE9RhSGa9sV+nQyzESjQ+cPuFk7lyiClCicVsbDvEYo1/k/H5UKQ/vjPMZ0ada3hCGrLJtHKMz5djjqDTk15iJwasJisDqCHmKbnntoa33cOnys6yfjB0UNlX38Pnp9wAz0sCy4hzIiklc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=crd6HPeX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=etqfXTHE; arc=none smtp.client-ip=202.12.124.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="crd6HPeX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="etqfXTHE" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 115F67A008A; Sun, 20 Sep 2026 03:15:12 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sun, 20 Sep 2026 03:15:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1789888511; x= 1789974911; bh=qYOw4ltOaLVIkhzvnpDdus7nC9MYXWuokkGw46VSc3k=; b=c rd6HPeXRDIZT+oj5SG35UhqX12QN6WB6OL2jZo1CsALts6HlBroJOvQXrWyolQ3J h/mVuP+5tXTLkZZrJ2GIwZiR5hZuR6x6C7egz4IJmoRuadfofj1jmhOjzwr8z0W4 RgZbesruN4XXIbHq/KYfKyUEBz9QcpXKzSczoQEUr53wI77jZ8rH193qiB9SJVyQ gE0oH713QnaMYmW/dtDaEGpAvZWGB2lvGLCdTdYG9g01o8CKbkuWR80+94w811mt wfD7o+jnQ8IwnFk+y1go5tSuNOu9Fu6+eMSsBuutjL8GXngZMYNZr/W3hMzlu3vM 8Mk3exsB41+R8+eA1GR7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789888511; x=1789974911; bh=q YOw4ltOaLVIkhzvnpDdus7nC9MYXWuokkGw46VSc3k=; b=etqfXTHEXdv1yKCQ2 I2oK2x06eDj+XSzP8Tw3KUmJBw9MHvbuwPkfmK9tI9ntX5AD73GdutHtV2DDBcpW /0S0wToIg0XxWm4YJRYCK+rkvsUprJNRk4Y+DeyLj+cBgpkv78XLbP0dtY5//nSq cY05egnI6eRThOednzC+7v27wtOrB62Mz9UKO/0L3mZ375XTj4EqwGG1BS2NNUaw ImQ75RL3t7SkRRe9DMx+vLSmYCjgAeT9uSFCWPmp3xssn07WdSJxZWB5pI3IdtuZ DLGqWpBTDoUl8lG7fb3LNjeNWUODfGJL3xuTzGn4TBaiBOPg2eecq4dVjwneExHf BwA3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGyn/xqJvXtDE0aXPg7VTWwa6ZytMhAGR7nxGfLocNGHdWz0wX8vkRz8WdekLHOxF ueygXEtIzUz+6+8Nu5jOylzMouJEEmUtyHAiF3hAv/PQOii+fQIaA16F9rGbK5eIj+gHX2 7oWQRylPS9prm6P0pulDgCxjr7FHQNIloAyG1sC2/WA+6SlZoZfvrwyAbbTgLETU6XAsrH oSG/gVQ4B96IyAbe0lc8e/7OyBZYZjJJI2xl3NT5AIvarGgLVxYLAZiD4NlCbAozg+Dur+ szvikqwlwyyPnE8AnV3AbHNmxlz1ORsNjtHjAvxgWdsXLx1vkCYM0HOOrP6u1ZYIqTWEcJ rIGUQYZZOhQJxrrhoEQ9mSNcjNAnBHOc+d4gDEve6WXyV9ZwlZXyHZw55i4WlJJgS6Utt8 4/LMep/3RGmYU3FacZLVXUkcOvSThTNwItEg99yFjWUhsMTFra9eCc4lyWqTbpUb35084x r16c9LPw3SCfRVGSLltCOQUyCXviDLlEalM3RecML9or3EDDSQbUOrNVsHBN73LQwR1/ZI 7odFrjA6+V7xcKXz2zcZcWgRE4Hmbr9G0ywHOjIymWGV+BSyE7Sla+Uu1DMNrk+mEChR3t LB6k1cE8R9ULwN13Ll7ObuG3Y5GD+9W5LpWPtXebcHhDejz2aogXvHDvRVYA X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Sep 2026 03:15:10 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/5] firewire: cdev: add annotations and comments about race condition of bus_reset_closure Date: Sun, 20 Sep 2026 16:15:00 +0900 Message-ID: <20260920071501.77785-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260920071501.77785-1-o-takashi@sakamocchi.jp> References: <20260920071501.77785-1-o-takashi@sakamocchi.jp> 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 Content-Type: text/plain; charset="utf-8" There is a race condition involving the bus_reset_closure member of the fw_cdev_event_bus_reset structure, which was addressed by commit 93b37905f70 ("firewire: cdev: prevent race between first get_info ioctl and bus reset event queuing"). Add code comments and annotations to document it. --- drivers/firewire/core-cdev.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 25590580b993..50c675113d5c 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -398,7 +398,12 @@ static ssize_t fw_device_op_read(struct file *file, ch= ar __user *buffer, =20 static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, struct client *client) +__must_hold(&client->device->client_list_mutex) { + lockdep_assert_held(&client->device->client_list_mutex); + + // This member is related to the above mutex. In detail, see 93b37905f70 = ("firewire: cdev: + // prevent race between first get_info ioctl and bus reset event queuing"= ). event->closure =3D client->bus_reset_closure; event->type =3D FW_CDEV_EVENT_BUS_RESET; =20 @@ -508,6 +513,9 @@ static int ioctl_get_info(struct client *client, union = ioctl_arg *arg) } =20 scoped_guard(mutex, &client->device->client_list_mutex) { + // Coordinate concurrent access to this member with bus reset event hand= ling, see + // 93b37905f70 ("firewire: cdev: prevent race between first get_info ioc= tl and bus + // reset event queuing"). client->bus_reset_closure =3D a->bus_reset_closure; =20 if (a->bus_reset !=3D 0) { --=20 2.53.0 From nobody Thu Sep 24 20:37:47 2026 Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (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 18038347BA9 for ; Sun, 20 Sep 2026 07:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888516; cv=none; b=Jf7EwfsjQnd0SEnJtQcLzwmFHL9poI7nlx8zEhaEI+vnbwpfPvKDtYIiJzz3XOJ94sdn74P+aDLS+srkHQ0ezbq/7fH08oemdeGmuKSPIzSeyDTeBL3vLXZ09pD06cMTGIvEm9eHbs0swzfySJExcoOvesGclewuYpypRMtNK8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789888516; c=relaxed/simple; bh=FVixjlluzEHTxx22SrIF+flCrrPxr57wS6rdNr4tA18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ajttw23ngFfcL1b35Vsj58tNO85FBYV3s+maeOtnoSKI6x/pyodg3PYfxZ3hGrcHWqUuWc+aPLjt7ZIDMaEaIm0y52b2/giWDzzCzUvhsF7CFvqaAoJlnXyhnfNC+kaWwF9oovRdoKAhnQ+mn7ZzuDEuup9odgHEojEjj+a6noY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=hnC3LTU2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c1Bns42P; arc=none smtp.client-ip=202.12.124.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="hnC3LTU2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c1Bns42P" Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 8FDBE1D0016E; Sun, 20 Sep 2026 03:15:13 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Sun, 20 Sep 2026 03:15:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1789888513; x= 1789974913; bh=CFpWsUUThGtI/AXZLA7sMxoGTX6R9XpPJUMuRn5W5VI=; b=h nC3LTU2w8lHxuP3tsrHOnxgcNDhCkVvmHVRm62HCtcevvgbHsQKZTiPfYghW2LC2 VyuLMAGOR3MupSs6is+uVJlaTpDtB7RH3LzSHPVppJKlpm+qPKPq4fxepBa+Xett pkNKhZtHEeMwqNz5SMGz8mNYfK7k8U8A6TaXYjCPWeNAEBoGK5tUDd8OP5iDN749 58nV16w2hTo+BWDkK/UM5eK9xZsQNbS0B4Uu4WizC3FOA6n5SSP9yuzILt/yahoN I6WgFpclbext3EbOcspdLmrqjgDIVLHVmlV1eYlpKlW6OIko/uOwEOcub89m/+B6 fhU8xlmIPUJVCEs7Iezwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1789888513; x=1789974913; bh=C FpWsUUThGtI/AXZLA7sMxoGTX6R9XpPJUMuRn5W5VI=; b=c1Bns42PGcw2mrg77 umNr6P6uGA/x85DodbzeAawRjpSAYWtPai386gr9vRd4m23d7mIaspMiEkhjhHtM os7XpAG4ZKgH6dnGsMNdgjnfVfaOCuTmBb5JbZ49HF1qVKK4nWw7PFpv+OgRbGmP rVh0T8Oi/aa7bZbz+qai1p68oSOEZenD5Eym7L8cU/6CAObX9tkNSrQB7HjOUtCr GHQoPqDXM37Re31X6ortpjpdmZKUJLx+9rho3xX1f3ToCR/sHkHj4Q04+djkSZCj R5tU4VODb8i0o9+Kb92xfT+QlJ9/qwVgzWUrn101ggw8MZE/r2LEM2jeLI2R/BES Y6qig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGyn/xqJvXtDE0aXPg7VTWwa6ZytMhAGR7nxGfLocNGHdWz0wX8vkRz8WdekLHOxF ueygXEtIzUz+6+8Nu5jOylzMouJEEmUtyHAiF3hAv/PQOii+fQIaA16F9rGbK5eIj+gHX2 7oWQRylPS9prm6P0pulDgCxjr7FHQNIloAyG1sC2/WA+6SlZoZfvrwyAbbTgLETU6XAsrH oSG/gVQ4B96IyAbe0lc8e/7OyBZYZjJJI2xl3NT5AIvarGgLVxYLAZiD4NlCbAozg+Dur+ szvikqwlwyyPnE8AnV3AbHNmxlz1ORsNjtHjAvxgWdsXLx1vkCYM0HOOrP6u1ZYIqTWEDr U5MT1QOXaiifx5iQypjwSIeJtLlrQmgAsrSD5H01QG0Mmjd/jhad3jKks4l0C3CdzvlIFg yBmcfRZlVAOq/qkdrq62piUXaORzSfnhIO2oiA5yhPNR9IA/SF+pEI/djG66Mllrf/4OXg dj9SQCN+uBCN0AlvSRTqpeu53pYS+ZUIAkh/WSaqKDLCgGHnRz9uWSsBkjqoDz4NImhwb9 3Ufd5nVipxO2JdiiCZhzm/CnvHpGcfvDjpGdkPyCQf+kWPXVbSnvclHhNIapa5iMVetcLL DFx6Iy11O0OINjHR+xg96uCvAaEEDQ7kBjbovGWlGqIr+YNNY8uhaOxHOsmA X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Sep 2026 03:15:12 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] firewire: cdev: add KUnit test for bus reset event UAPI structure Date: Sun, 20 Sep 2026 16:15:01 +0900 Message-ID: <20260920071501.77785-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260920071501.77785-1-o-takashi@sakamocchi.jp> References: <20260920071501.77785-1-o-takashi@sakamocchi.jp> 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 Content-Type: text/plain; charset="utf-8" The bus reset event structure exposed through the UAPI has a different size depending on the target architecture. Extra care is required when copying it to/from userspace. Add a KUnit test for the structure to ensure that it has the expected size and offsets. --- drivers/firewire/core-cdev.c | 5 ++++- drivers/firewire/uapi-test.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 50c675113d5c..6d91a6e7ad0d 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -524,7 +524,10 @@ static int ioctl_get_info(struct client *client, union= ioctl_arg *arg) memset(&bus_reset, 0, sizeof(bus_reset)); fill_bus_reset_event(&bus_reset, client); =20 - /* unaligned size of bus_reset is 36 bytes */ + // This structure has 4 bytes of trailing padding under the System V ABI + // on most architectures (due to 8-byte alignment of the long long type= ), + // except for Intel386 (where long long type is aligned to 4 bytes). In + // either case, the effective length is 36 bytes. if (copy_to_user(u64_to_uptr(a->bus_reset), &bus_reset, 36)) return -EFAULT; } diff --git a/drivers/firewire/uapi-test.c b/drivers/firewire/uapi-test.c index bc3f10a2e516..0bdacb1caeb8 100644 --- a/drivers/firewire/uapi-test.c +++ b/drivers/firewire/uapi-test.c @@ -72,11 +72,31 @@ static void structure_layout_event_phy_packet2(struct k= unit *test) KUNIT_EXPECT_EQ(test, 24, offsetof(struct fw_cdev_event_phy_packet2, data= )); } =20 +static void structure_layout_event_bus_reset(struct kunit *test) +{ +#if defined(CONFIG_X86_32) + // 4 bytes alignment for aggregate type including 8 bytes storage t= ypes. + KUNIT_EXPECT_EQ(test, 36, sizeof(struct fw_cdev_event_bus_reset)); +#else + KUNIT_EXPECT_EQ(test, 40, sizeof(struct fw_cdev_event_bus_reset)); +#endif + + KUNIT_EXPECT_EQ(test, 0, offsetof(struct fw_cdev_event_bus_reset, c= losure)); + KUNIT_EXPECT_EQ(test, 8, offsetof(struct fw_cdev_event_bus_reset, t= ype)); + KUNIT_EXPECT_EQ(test, 12, offsetof(struct fw_cdev_event_bus_reset, = node_id)); + KUNIT_EXPECT_EQ(test, 16, offsetof(struct fw_cdev_event_bus_reset, = local_node_id)); + KUNIT_EXPECT_EQ(test, 20, offsetof(struct fw_cdev_event_bus_reset, = bm_node_id)); + KUNIT_EXPECT_EQ(test, 24, offsetof(struct fw_cdev_event_bus_reset, = irm_node_id)); + KUNIT_EXPECT_EQ(test, 28, offsetof(struct fw_cdev_event_bus_reset, = root_node_id)); + KUNIT_EXPECT_EQ(test, 32, offsetof(struct fw_cdev_event_bus_reset, = generation)); +} + static struct kunit_case structure_layout_test_cases[] =3D { KUNIT_CASE(structure_layout_event_response), KUNIT_CASE(structure_layout_event_request3), KUNIT_CASE(structure_layout_event_response2), KUNIT_CASE(structure_layout_event_phy_packet2), + KUNIT_CASE(structure_layout_event_bus_reset), {} }; =20 --=20 2.53.0