From nobody Fri Oct 3 03:20:12 2025 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 6CBDF2F60D6 for ; Mon, 8 Sep 2025 08:27:56 +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=1757320076; cv=none; b=OBieDMfx/cQvcUK3q8ar5g5usKhQybMBn31BtlS131PsYlF1t78XDH7u9aOujjY9k3maoBbSSGN8Q1LZE7xbm8UHmSRcOCQVxMaY+gX14Z9OOEdwHTW/lzJrbGe2bbm3EvhMIG7RqLRzbPgECNfskQpeRWFPMEnzRsetnx+EWvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757320076; c=relaxed/simple; bh=CFvvTrfa1t92F7NxctUBMm3QJnsOF0WWxyPhVXxwhCc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AtV07iXgyqSTyjS5oaM+KsbS0pXCLFhiBgn56c1MFaPxEgcDgiUom2XNLGeP1FlkYvdvxs1UP5hOSjaolf71aSkKY29uRfp/CVI4wtits2ioEAn0iUOdSG1+wt9xsno65xd/R9ZT8nSZcLXtkVB1cK1vXx4esTA34Q/W9TTIlWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LnXTGIP3; 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="LnXTGIP3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89D98C4CEF5; Mon, 8 Sep 2025 08:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757320076; bh=CFvvTrfa1t92F7NxctUBMm3QJnsOF0WWxyPhVXxwhCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LnXTGIP3pULjVEAepJ6qCrd3NuT65KHO7JLgPYCK6GiyxGGYrjnWF6Ox2dxar9Lca i4z/sEg/UtTUZoC9gi488+kRJ3j8liXpyILqPJo69l08TFMSlcZFeVAkWB2lvIZkU6 tvLP5ljWIokQmgVfkhfcieOQg0Y0Mc7U/lAgAPOGskryGwdef+naU19kHGFnLf3nFd 9W8SIQ26Fa9FeabH022g5Nyq5oftskXyMo4qzCjMfZ2mBIB4B1pHkcagYiAzZIpee2 T/cG27wqP1z/4003cPjWGsyJ9Baw3KXaKsFLBAgVdChIdU8B3pOpV9LG+fyaEHtrs2 xJe+nThBVRFYg== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Dan Carpenter , Zenghui Yu , Thomas Gleixner , Marc Zyngier Subject: [PATCH v2 RESEND 3/3] irqchip/gic-v5: Fix error handling in gicv5_its_irq_domain_alloc() Date: Mon, 8 Sep 2025 10:27:45 +0200 Message-ID: <20250908082745.113718-4-lpieralisi@kernel.org> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250908082745.113718-1-lpieralisi@kernel.org> References: <20250908082745.113718-1-lpieralisi@kernel.org> 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" From: Dan Carpenter Code in gicv5_its_irq_domain_alloc() has two issues: - it checks the wrong return value/variable when calling gicv5_alloc_lpi() - The cleanup code does not take previous loop iterations into account Fix both issues at once by adding the right gicv5_alloc_lpi() variable check and by reworking the function cleanup code to take into account current and previous iterations. [lpieralisi: reworded commit log] Fixes: 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support") Signed-off-by: Dan Carpenter Signed-off-by: Lorenzo Pieralisi Reviewed-by: Zenghui Yu Cc: Thomas Gleixner Cc: Marc Zyngier --- drivers/irqchip/irq-gic-v5-its.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-= its.c index 4701ef62b8b2..2fb58d76f521 100644 --- a/drivers/irqchip/irq-gic-v5-its.c +++ b/drivers/irqchip/irq-gic-v5-its.c @@ -949,15 +949,18 @@ static int gicv5_its_irq_domain_alloc(struct irq_doma= in *domain, unsigned int vi device_id =3D its_dev->device_id; =20 for (i =3D 0; i < nr_irqs; i++) { - lpi =3D gicv5_alloc_lpi(); + ret =3D gicv5_alloc_lpi(); if (ret < 0) { pr_debug("Failed to find free LPI!\n"); - goto out_eventid; + goto out_free_irqs; } + lpi =3D ret; =20 ret =3D irq_domain_alloc_irqs_parent(domain, virq + i, 1, &lpi); - if (ret) - goto out_free_lpi; + if (ret) { + gicv5_free_lpi(lpi); + goto out_free_irqs; + } =20 /* * Store eventid and deviceid into the hwirq for later use. @@ -977,8 +980,13 @@ static int gicv5_its_irq_domain_alloc(struct irq_domai= n *domain, unsigned int vi =20 return 0; =20 -out_free_lpi: - gicv5_free_lpi(lpi); +out_free_irqs: + while (--i >=3D 0) { + irqd =3D irq_domain_get_irq_data(domain, virq + i); + gicv5_free_lpi(irqd->parent_data->hwirq); + irq_domain_reset_irq_data(irqd); + irq_domain_free_irqs_parent(domain, virq + i, 1); + } out_eventid: gicv5_its_free_eventid(its_dev, event_id_base, nr_irqs); return ret; --=20 2.48.0