From nobody Tue Sep 29 06:59:47 2026 Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (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 E36BA3B4EB7 for ; Tue, 11 Aug 2026 12:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450176; cv=none; b=NXS4HPiuF+QCMDPEAJK0cVIZrhOpmzDi4dOrJ5JW/NN7w/7HiWqLkhikKR/ffG0keCCdXBNPEhRvWLoU8BL+thCFvV82vQuGHFypzG3aCsIc9EJ/sLmCfnZttd57gIzcqQjCmR640NYtmhPW6Rugwqb6Qq3MD4KKEA9sK6bmXFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450176; c=relaxed/simple; bh=/45cf/eV709ttboaVt4PLBeH1LW4+svpfJ3q9WMc+/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qLlr5fjltB2i45vU0T2uulmyPZfWZqXh6j8bEuGa37h382pW5b6iP4o6ydCaWInVU4UzIyIriBad+BxT4jySfdx+JsO/Cx/8+NWdx6INeKSqCyTeevo0hV2H915lI3QdWwWseQVkKWPpmsmNm5PLQHZKSxmxtMMCOhmHWc4ZZlU= 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=CtQX0rnk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cQtNhCcM; arc=none smtp.client-ip=202.12.124.152 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="CtQX0rnk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cQtNhCcM" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 274AB7A0158; Tue, 11 Aug 2026 08:09:34 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 11 Aug 2026 08:09:34 -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=fm3; t=1786450174; x= 1786536574; bh=kVLowPAtQ0NYcyMG/peht18nbLzardk0p3Xj3XVuZgE=; b=C tQX0rnkPIbdzkIgFAWkl8FOshoShVvBZTvBGDPGUP7bdeXwwoawkUh4IqyChKt98 W4lzGCbFW674Un4ScRujV9w12DrJP3/U+/EVvry/XlJ/UffYg0k/5xoCMyrOKE0Q tKNncbX14VevmUmjDcUPIrQ0ZBH2y30XU7RHpmI11X4WmQmpc8dZh9G9pv67QBbi /Q+TCcXYNmYE13nmiVww+OueJZrBbGFPWVo54aAO9lHky75PBMsng7B9No1+QyBG U15nw3idYZNoveeKO39dpDp/+BK4oHwOPI75zbXy/7tOd5qOHeQ44/b+x4OeBYlU CjMm+51qTa/oC9yBiqkWg== 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=fm3; t=1786450174; x=1786536574; bh=k VLowPAtQ0NYcyMG/peht18nbLzardk0p3Xj3XVuZgE=; b=cQtNhCcM6GtQj6AJm dzzBzU0kth5bkv1Z1zlXIjmTGg0XyLwdOcQphFSQSAAJpb0T1d4BYBZyyGOKq87g p3PCk7V0NYg4L8qQfiYeE8+rppq7/C4x4QTMm6IUeRPyKo58O9XCM8Ve174HWChE AM0uOdb/qmQhiZKjjbPBFYwtyKGyZURuLIbppwyysfsW8rwN6ITu+gvV//vxwRS7 Orzi9tr49o8YiSgP9xp3qusvfZcMbvkHYW7l8u+eXmhQPkcGl9FPS1uHGNx7wJeZ FBj4Jd/I86IOnC+lLwOPIdjUUbuPQF6hSZ+EUQkQkiEiTwvSZkmI1dGB8LPdllf4 sJUQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFGoY2dw0DpMVI1f4zYog0wO9mQ45ahUUh8PRDxnGUnQAllAbjzaLhcANVbrPr4LZ s0YskQAqXw/tX3/OLOhej2Fcnw/BtXi3WNwPpplE3nYpEikhrjWexZegZZygPzH9DF+W4G OrhgUTxBTUjQMPWMmSx2KkahMfgS74Dm8arbzahxH9aasbEWnIgR9ciITFVtG++XCiVr7c BIyPvNno6nrTzPD0IoY4VYlMQxaKGZ5pXbNYxrYMtlWH3lBsQUKZSW1sf3qaG4S7CWvQ8o Av+mmiu5oYJm+jFUGg4OS3Ond4c9dwgRXYXA4/nSOYP8pB5Ao/13bTAafPt3R86S4RiluC hzJDRP3LTlX0wzLvcONjiL0x541d25W8y7GUAnrIuDYQUiD/Aea97irh7uUByYODONygou aCAFgw1m9kwKEDmoKcT2xpWBobzzWI9V5MbOHxMa3ycOQ9iIWYOa6clqFlOA8296Lp+cqn b4Y8wKaoZ+7CRo370uLn17oG0BqFoTRu6ENiJ1TujiAfiRqMKheMoCEa+aRSFysJukRs+Q k4R+/YSkmf+vOQB5LtXrlmABxB1fo+xeLro6111v5BMlQeZx9GRjCSUNrkJ4ZtHqfz+eGF 7rjgUVPKHVLTi/dbA1LifFk4TJo+fp0Bg473ytsdqx2wQyogMT5mAjpgdUzQ X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 08:09:32 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: nihaal@cse.iitm.ac.in, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] firewire: core: consolidate port counting in build_tree() Date: Tue, 11 Aug 2026 21:09:26 +0900 Message-ID: <20260811120928.700577-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811120928.700577-1-o-takashi@sakamocchi.jp> References: <20260811120928.700577-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 self ID sequence describes the state of each port for each PHY. Currently, build_tree() counts the ports in two separate places. Consolidate the port counting in one place. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 1d3a4419f554..4f610205576c 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -119,8 +119,8 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self =20 while (enumerator.quadlet_count > 0) { unsigned int child_port_count =3D 0; + unsigned int parent_port_count =3D 0; unsigned int total_port_count =3D 0; - unsigned int parent_count =3D 0; unsigned int quadlet_count; const u32 *self_id_sequence; unsigned int port_capacity; @@ -148,16 +148,19 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self switch (port_status) { case PHY_PACKET_SELF_ID_PORT_STATUS_CHILD: ++child_port_count; - fallthrough; + break; case PHY_PACKET_SELF_ID_PORT_STATUS_PARENT: + ++parent_port_count; + break; case PHY_PACKET_SELF_ID_PORT_STATUS_NCONN: ++total_port_count; - fallthrough; + break; case PHY_PACKET_SELF_ID_PORT_STATUS_NONE: default: break; } } + total_port_count +=3D child_port_count + parent_port_count; =20 if (phy_id !=3D phy_packet_self_id_get_phy_id(self_id_sequence[0])) { fw_err(card, "PHY ID mismatch in self ID: %d !=3D %d\n", @@ -203,7 +206,6 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self // we temporarily abuse node->color for remembering the entry in // the node->ports array where the parent node should be. Later, // when we handle the parent node, we fix up the reference. - ++parent_count; node->color =3D port_index; break; =20 @@ -223,10 +225,10 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self =20 // Check that the node reports exactly one parent port, except for the r= oot, which // of course should have no parents. - if ((enumerator.quadlet_count =3D=3D 0 && parent_count !=3D 0) || - (enumerator.quadlet_count > 0 && parent_count !=3D 1)) { + if ((enumerator.quadlet_count =3D=3D 0 && parent_port_count !=3D 0) || + (enumerator.quadlet_count > 0 && parent_port_count !=3D 1)) { fw_err(card, "parent port inconsistency for node %d: " - "parent_count=3D%d\n", phy_id, parent_count); + "parent_count=3D%d\n", phy_id, parent_port_count); return NULL; } =20 @@ -235,7 +237,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self list_add_tail(&node->link, &stack); stack_depth +=3D 1 - child_port_count; =20 - if (node->phy_speed =3D=3D SCODE_BETA && parent_count + child_port_count= > 1) + if (node->phy_speed =3D=3D SCODE_BETA && parent_port_count + child_port_= count > 1) beta_repeaters_present =3D true; =20 // If PHYs report different gap counts, set an invalid count which will = force a gap --=20 2.53.0 From nobody Tue Sep 29 06:59:47 2026 Received: from fout-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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 86769440A2D for ; Tue, 11 Aug 2026 12:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450178; cv=none; b=RfZoPSxOxemYZEU0adqwlpj9n7JOdT0RKSPBEIlJ/ndV//WcvionREg3QCINWnzHWOXHNvIvem7IaqkQ/TKvGm19b91FkVn9xRayk3a5Xwt40ZDQ6ZYrdgEZp2RxWKKZjfix/Vj/U8aLTQLBuAImioYFfhA4b77hW2wEG9mh4no= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450178; c=relaxed/simple; bh=TPuK+7P2GeQ9rfxAUwwaTX6EG9lbaOS/O7X00ZpSFBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9jBDsGvwgCJ2SnINnpfLX1bwiXkEWA7jD18LDtJS8Y7tgYsKk3Ek9SuOV9vvPEzWVEn6l452SYadWwI4WeVrHsgh0/KQzoeu/nTTYZHfwGQIOOUIvMjqU+O1MxOKXRnkBg+LXI48wqn1K20Xvw9iv9TWRGH7QiQ4cL777X256k= 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=Kq/0ZD7O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j6b3fuP6; arc=none smtp.client-ip=202.12.124.150 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="Kq/0ZD7O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j6b3fuP6" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id C94BB1D00139; Tue, 11 Aug 2026 08:09:35 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Aug 2026 08:09:35 -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=fm3; t=1786450175; x= 1786536575; bh=OUemOkuur+azrAtPZ6RJjlC0W7vl9SyzNfZaDPO0yHY=; b=K q/0ZD7OF7LNm5SsFUg+bAxyMSnpxyh2JHrtTxl+Kb2Ukgulrx3Q/0313H24Fjpi8 JAG6KWPTEDxXfQBz7CtlMchRoGJ/R77X5CONrZ7HgEiekdkpIotfGeRKGAx9v/Dm wGlUinAPqaTRUAKenAijsuZgl+pHmVgzrpmw4vEG9qCDXmB5UevdIBYszPdyB/b5 rda2m6wo4gvbVC/RjlnRx1SxGX67s/yyg4mn/SczLmbMbCoeRh3SA9OrhbX3dwD/ 5l5iBkKjNOQ8xWOKiwfx23f8lWdmE22TWwYlvUCR/5lfRKlq7jUPyY6Wv7U+iF0z Xy/Zi+i2OJHOS5QfT5/pg== 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=fm3; t=1786450175; x=1786536575; bh=O UemOkuur+azrAtPZ6RJjlC0W7vl9SyzNfZaDPO0yHY=; b=j6b3fuP6j5hLRxsOy rHVtWjpqImpshM8QAPrUPeNpVG3Lw8bXzICYAVtTLhFErmpKMlB3lWZuQrcNphr4 2Kf/H0NClWYvWoPMQzhcf3G0WE2Hr4AFDRJUxjwt20Ous4wPVIYYkjg2RwkcKTWT i8MIf4ypqq3EUqFB7xUYWrhQy+x9Y3f+Ue2rA6mCma/6swqXT5xRiC/Ttopolg5k 1uFo1F6/m24AMQHckVRzCeTm1HulwP7yE33KdBaqk3zYWulsZ1gNvIeaFql9Azx7 AfNV5tm7TAgFLCuRyzwwKdEg+O38Jlrpqdk7mo190FFjusZR9DmxGoLjc+IkDR3t Dp9IQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFGoY2dw0DpMVI1f4zYog0wO9mQ45ahUUh8PRDxnGUnQAllAbjzaLhcANVbrPr4LZ s0YskQAqXw/tX3/OLOhej2Fcnw/BtXi3WNwPpplE3nYpEikhrjWexZegZZygPzH9DF+W4G OrhgUTxBTUjQMPWMmSx2KkahMfgS74Dm8arbzahxH9aasbEWnIgR9ciITFVtG++XCiVr7c BIyPvNno6nrTzPD0IoY4VYlMQxaKGZ5pXbNYxrYMtlWH3lBsQUKZSW1sf3qaG4S7CWvQ8o Av+mmiu5oYJm+jFUGg4OS3Ond4c9dwgRXYXA4/nSOYP8pB5Ao/13bTAafPt3R86S4Rilip iXkCDzO0F717yySF4Jt7LLjFOy3oXYdeCul2+wcortm3GMFZ2Uyf1lwDaqCT5lkl8qk0uW hl325nyWqiVVj2S6r+uB2yG/nAv01roZcC4t6IxP3KGlLB7WvG9YvnMp2iNhsHUHWgKIBo Uw0XPLjInntxp9qX1XhPHQzbk9Dhk/8b8/CyPNy5rXqlMh0DYqOy40C4sIndCDSLgYovAz 1VyqimkgD1CXPiQbLsK5BxnVSLd9V41z0nNb8NkXXP7uHBI0LMMJzYDQN16qhrSc0/PU0L bz2s0oG5cx8vrzd7o6hP1rcPGO08lShuZW8aawNlJ7eUpZWWrBwe/2VUhwKQ X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 08:09:34 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: nihaal@cse.iitm.ac.in, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] firewire: core: validate parent port count before allocating nodes in build_tree() Date: Tue, 11 Aug 2026 21:09:27 +0900 Message-ID: <20260811120928.700577-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811120928.700577-1-o-takashi@sakamocchi.jp> References: <20260811120928.700577-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 node tree requires each child node to have exactly one port connected to a parent node, while the root node must have no such port. This can be validated by comparing the parent port count for a PHY with the rest of the self ID sequence. Currently, this validation is done after the node has been allocated. Move it before the allocation so that an invalid self ID sequence can cause an error without having to clean up the newly allocated node. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 4f610205576c..e032497b2594 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -162,6 +162,15 @@ static struct fw_node *build_tree(struct fw_card *card= , const u32 *sid, int self } total_port_count +=3D child_port_count + parent_port_count; =20 + // Check that the node reports exactly one parent port, except for the r= oot, which + // of course should have no parents. + if ((enumerator.quadlet_count =3D=3D 0 && parent_port_count !=3D 0) || + (enumerator.quadlet_count > 0 && parent_port_count !=3D 1)) { + fw_err(card, "parent port inconsistency for node %d: parent_count=3D%d\= n", + phy_id, parent_port_count); + return NULL; + } + if (phy_id !=3D phy_packet_self_id_get_phy_id(self_id_sequence[0])) { fw_err(card, "PHY ID mismatch in self ID: %d !=3D %d\n", phy_id, phy_packet_self_id_get_phy_id(self_id_sequence[0])); @@ -223,15 +232,6 @@ static struct fw_node *build_tree(struct fw_card *card= , const u32 *sid, int self } } =20 - // Check that the node reports exactly one parent port, except for the r= oot, which - // of course should have no parents. - if ((enumerator.quadlet_count =3D=3D 0 && parent_port_count !=3D 0) || - (enumerator.quadlet_count > 0 && parent_port_count !=3D 1)) { - fw_err(card, "parent port inconsistency for node %d: " - "parent_count=3D%d\n", phy_id, parent_port_count); - return NULL; - } - /* Pop the child nodes off the stack and push the new node. */ __list_del(h->prev, &stack); list_add_tail(&node->link, &stack); --=20 2.53.0 From nobody Tue Sep 29 06:59:47 2026 Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (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 8F639439345 for ; Tue, 11 Aug 2026 12:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450180; cv=none; b=V9czQla/SjxpXfpQbG1FrhQMnALrAo0jnKHjXyW42sLn7IvIw2kTE1udva7VMy6+HUN4LDESqcVBbA3ymhqvgtRS4BMmUV10SEhUHreePZYufRWGKuvdAXvhu2d7+5wgxinl0mbwmYIMLA/WgGgEwYPjdVGNXuKJuHHy0vmnq9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450180; c=relaxed/simple; bh=RfBeOnrrFCXo4x71gDU8Y2JgGfAAFND/Sr3EGQ8MclY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=meZHdgg3qlRc3VgAVtlt0Pc4gI1yLRK+t6GJt3mrLrw9tyQgicFGVGPsvFRMqlk4ECt7dtW5nZ3cTMHkkz8wdHplrPBfK81c/k5O2BJL+8BNKKbFgexYmUnJZBiU6HHzaf1CGKZU22lGi35VzH6MdVplrC/HXtp9uqlmqwOtxpc= 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=vs5blk43; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DhOvPnZZ; arc=none smtp.client-ip=202.12.124.152 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="vs5blk43"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DhOvPnZZ" Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id B1C7D7A0162; Tue, 11 Aug 2026 08:09:37 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Tue, 11 Aug 2026 08:09:37 -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=fm3; t=1786450177; x= 1786536577; bh=U/4EzzlaLOePYLTXca7QpdlVqqxJ6JZ+L7khpIqpyOA=; b=v s5blk4386aZaWXW6T1f8Evr5vcc6LnmgUgPCdcPw5z03Q+98AnLeUejpn3aKDuzb J0zumENFu5heClvG/P4cdE3v8QGyhy9A9bfulYjL0nJSNfvwe3Cd9Trv88oX8y9N CwpcCzLPod5ZUx08qFjrmwAhGtT8M9G2q8H9dWKrp40hodS9xoKuikMvFIFz4ML4 GUMqpfh43HoI6unZUeOUhFDYlCHOLaahuIKx2Bg4lyxgB6ZPZJlxeyDG6ews0vyp pbd1hPKQNaDoA6mGQebOfkU2md5UEg7PPS3+g77djuttXUjMrMcyEGeAx9Zsf6Ju ZFwqmfvxw9GJulBa4EbSg== 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=fm3; t=1786450177; x=1786536577; bh=U /4EzzlaLOePYLTXca7QpdlVqqxJ6JZ+L7khpIqpyOA=; b=DhOvPnZZs62bdBh8Y fAcYCaGtawQqzD8CIH/c5eiTiBQr8T+187DOPpy9+U/mNZLnjbp1E7/Be6JvQ0pS tBThdpovlQJxVuaFeDQuZ1f28aKl5y+I0mb+I5m7psxu5H8m72NnbHo307sLWyu6 s1V2Mcd6u50XIhoYjuicA76Z+N7F6bJfB4z5TdLzHw41oCP8tBpSmX0c2dRSgtKY h7FkXc2Zl9015lSCSAEHuVQTqAvx5oJz5XgtpMwECrpB5niPFAQeDYiBJpMvM+aR yP+NIw/cxyv4AXlNSTax5oXDK4E8U+n56cUJYFv//Rzr8os+s7TZcEimzHTCCGv8 d0LTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE0/qBB0LeUC8WD53JyHMMSTJ+CyVCyYRpD7qLqFK3UgbCfWDJhDP8xb5rokPq5oy Byd3DI57wynbkceULGNUiI+izUJoR6C+kMZX6TqObHXyXNa/dPYXxmCbkx8DtAMGU8KghY C3fRUPSko61HnmXaaAg1c7n+SUbioxi7tJALTTdpZP89qs/HdzIGGUJgZSfMyZt7evtOgb JgsHX9ohWx8WcRounkINt2mjz9l9XdSBUPI3Z7HB9lfPQ9TnL1ae3wW5e7sHLq/XSfPsuR vCFsyvPD3UH0lwJUTbUGymC2lmRSnwLm/kyX/onTXQe+hIZlBc0gG2MtEJNq+plpdt9GUC y0ipmpsLAKwbyBm9cjVH0UfrynagSXKW357Mx7TZtujl/q2HiEf+DVHKoOgT2IQ3ngq2zR S5MU6AkdOzmGCpC5sHoKCfGJO5s0M1Ri6bw7DDIwtsXs5j/FautgYrU9XnIQjZqmHPGWun dRB6s1lFpYD26Rz3PhnyLeEqqZhnRGjx8TDIs6gF3431ithnN0PUQeI06LycEYWRRoIXBk uQLkViaWxC/DOGXhZ4yQg7+IO9xJRVXVbZ0HdmZUH1nUsIzkPemP7KN33k5QRAJytXY9+Z qRVwUUrZjLgZ8jULJFCgBGvMVwcvYLGbGzIaR+f0iZNBGz6hhgMBb8CnQqoQ X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Aug 2026 08:09:36 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: nihaal@cse.iitm.ac.in, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] firewire: core: fix memory leak in error path of build_tree() Date: Tue, 11 Aug 2026 21:09:28 +0900 Message-ID: <20260811120928.700577-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811120928.700577-1-o-takashi@sakamocchi.jp> References: <20260811120928.700577-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" In the error path of build_tree(), node instances can remain in the local linked list when the function returns. Whenever an invalid value is detected in the self ID sequence, each allocated node instance is either an entry in the linked list or an entry in the ports array of its parent node. Therefore, the allocate node instances can be safely released by traversing the linked list from its head. Release the remaining node instances with for_each_fw_node() before returning to the caller. Fixes: 3038e353cfaf ("firewire: Add core firewire stack.") Reported-by: Abdun Nihaal Link: https://lore.kernel.org/all/20260727095955.104972-1-nihaal@cse.iitm.a= c.in/ Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index e032497b2594..ee6b54f89859 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -88,6 +88,17 @@ static inline struct fw_node *fw_node(struct list_head *= l) return list_entry(l, struct fw_node, link); } =20 +typedef void (*fw_node_callback_t)(struct fw_card *card, struct fw_node *n= ode, + struct fw_node *parent); + +static void for_each_fw_node(struct fw_card *card, struct fw_node *root, + fw_node_callback_t callback); + +static void free_fw_node(struct fw_card *card, struct fw_node *node, struc= t fw_node *parent) +{ + kfree(node); +} + /* * This function builds the tree representation of the topology given * by the self IDs from the latest bus reset. During the construction @@ -134,7 +145,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self if (PTR_ERR(self_id_sequence) !=3D -ENODATA) { fw_err(card, "inconsistent extended self IDs: %ld\n", PTR_ERR(self_id_sequence)); - return NULL; + goto error; } break; } @@ -168,18 +179,18 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self (enumerator.quadlet_count > 0 && parent_port_count !=3D 1)) { fw_err(card, "parent port inconsistency for node %d: parent_count=3D%d\= n", phy_id, parent_port_count); - return NULL; + goto error; } =20 if (phy_id !=3D phy_packet_self_id_get_phy_id(self_id_sequence[0])) { fw_err(card, "PHY ID mismatch in self ID: %d !=3D %d\n", phy_id, phy_packet_self_id_get_phy_id(self_id_sequence[0])); - return NULL; + goto error; } =20 if (child_port_count > stack_depth) { fw_err(card, "topology stack underflow\n"); - return NULL; + goto error; } =20 /* @@ -197,7 +208,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self node =3D fw_node_create(self_id_sequence[0], total_port_count, card->col= or); if (node =3D=3D NULL) { fw_err(card, "out of memory while building topology\n"); - return NULL; + goto error; } =20 if (phy_id =3D=3D (card->node_id & 0x3f)) @@ -256,12 +267,13 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self card->beta_repeaters_present =3D beta_repeaters_present; =20 return local_node; +error: + ++card->color; + list_for_each_entry_safe(node, child, &stack, link) + for_each_fw_node(card, node, free_fw_node); + return NULL; } =20 -typedef void (*fw_node_callback_t)(struct fw_card * card, - struct fw_node * node, - struct fw_node * parent); - static void for_each_fw_node(struct fw_card *card, struct fw_node *root, fw_node_callback_t callback) { --=20 2.53.0