From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85FB735F610 for ; Sat, 20 Jun 2026 12:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781956912; cv=none; b=cjilg5esI2YsBB+zqAFhHOtxsms7HItjMMsaZBQuzgpJnI4wEnCgz3W5diEZhwJ8piNupNzx7zm/l9CmdcH87s71m5Yr+lxH+9adQhaxYTe8RgCbzQfGsVZDTCCjDKuycP9uyqgLSEzoXUJ1vYVq7Q167bR8XMNeb7zSPeuE3LM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781956912; c=relaxed/simple; bh=EgVtl9oiNz4N+uamt98jWr6FuM31DBZw2P5NQnUA+bw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o3+Egv15qaluS+fvB44khfZe2fjWOi+8hXf4rSwEraNm/+r6ykfR8jk8Uq6AvtbCgCnEJW1bHoGb7orOeVemG4G0hM337wAdtajriydXc2SzJMQlHoObW6ATAC5PwE/qvSc9HmkuMzZ8TEl0ejljM8hfJ3QaK6lQ8cCorWBv+XA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UjFS8arF; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UjFS8arF" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-490b7866869so28027955e9.2 for ; Sat, 20 Jun 2026 05:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781956910; x=1782561710; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cXqerCMbT1UNvyRXwghkpTOawV/8Cn1T7WXFqflNChE=; b=UjFS8arF4v/tSegKGHTaTmYRDkJeEgfmHk7JBPWzYjye5yygmzh5aLKyrDZL2QpVBz XROn1IcKkmx3iUDQiibk+MHFDoVypojBSfkPasQwMMkJFJIKjI0bEnhXjz/O26ZpVBtI LHIPNkn4oNDbrUTC8SIB2sENExtK/1zy+tFwvwzIvArH3pzK6Llw+Bgs08OcWY28UWge jVtee00M0ldjYM34Ew2rNrYVB8OpqyIuGLkCnTC6r63uZxJiBRz9jIFRR9roB3gIB4/6 UGNkUZ0YOCOiDuptR/qYy7S6xFHLYn7JnHTQETKoP/djUk8q6kVayyYdgx58XefCxUfB 0Y/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781956910; x=1782561710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=cXqerCMbT1UNvyRXwghkpTOawV/8Cn1T7WXFqflNChE=; b=glWrTL184Fi1avW/hEe46hiGqqp/3OWo4HqecN2pLkwuGcuVovYoePRkrztHwu+pG3 LWfITf/X5aSk9jRlYcVsORvw7D3JbfzLuyJE/NnjzaZA1rBwmyrosTiploWj1HpSgV+r FPXPegI5nMoADlf7EJfmOLCW3GcSbnkcBNHHZiN9AB0ctHtx2hH5ihEElHseFLygkjtm MdH0c48vY+DORd9JcCD/Aa2o1aIdbaitZPR9rwv5fyFawWsrdpGozusPpZYWHmiZu0x2 iyvJNYG+s2s9znTuC9rK2h/48SkGugy5m0iK08jBWm1ucYhBo5YFHOxv40yXWx1VOfM0 3MjA== X-Forwarded-Encrypted: i=1; AFNElJ8w4IiX2D0c2P53sxe7N1v1S9gf0HOsq7sXPRvnabHvXDCW5TcboxgD7fZAtxhptmpFORuVC+ay30/5P+Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzutrEL9Nnf7Y+ijwigtWSk+7EziTuY7+Dfes7t55RSJeyVVOR9 QO5HcX0Xkb5e/cSx5ei4/Mo0sJM5BY14HpocvS1DZKItEFsrZdWFqia4 X-Gm-Gg: AfdE7ckRV57o238zXAAvbqgoRoo18fFmBNiM+llbI6Y6Hv1D6xJl8EBmsGASu+X/g/u ivnjlDEkSwDdQa0bLQApQ9sQP88CTghzo/PyG03wo/CqEWCK9IT7o1sXFC7JOz+lK/Fh59EPpg+ 1TnHffhSs5fWP5Z3httScdDuApdC8Q78ucJQgkAlUaXZ4BVm8lKf6aD+rTk05lN1GOFDe67NsV3 8EyoIcd8B7KPPJtG/iQyGeEB8yPrlM8QgJkh97BGWL0k58jkvdt4G8Xza5/ZvJacDIf8VucR6R6 94jwtJ3zpY+lTidFaSeRmq8yXW3iS34J5/eSPsOecIe8PqJv2ERazS0vZHU8CTSHZqSgGTsrTCk G36MTrcHGaWrZuloxDUbAAz1HqOyD0u653rgZXQhp60KxGxsoLV3ATYaywBXkUudyfRjclfKGZ0 g9naJ1QhxQXjs9QfVeM/QWd7NzukLAVFTQGCWDt+SdRi8dJvT2N2BoA4L8lJAsOYOVjSodlw== X-Received: by 2002:a05:600c:314f:b0:490:a298:3859 with SMTP id 5b1f17b1804b1-492425706b9mr92064135e9.24.1781956909639; Sat, 20 Jun 2026 05:01:49 -0700 (PDT) Received: from camaron.. (147.red-88-9-50.dynamicip.rima-tde.net. [88.9.50.147]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49240ee9bc2sm93161565e9.1.2026.06.20.05.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 05:01:48 -0700 (PDT) From: Sergio Paracuellos To: linux-gpio@vger.kernel.org Cc: linusw@kernel.org, brgl@kernel.org, vicencb@gmail.com, linux-kernel@vger.kernel.org, Sashiko Subject: [PATCH 2/4] gpio: mt7621: more robust management of IRQ domain teardown Date: Sat, 20 Jun 2026 14:01:34 +0200 Message-ID: <20260620120136.2482872-3-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260620120136.2482872-1-sergio.paracuellos@gmail.com> References: <20260620120136.2482872-1-sergio.paracuellos@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The driver uses devm_gpiochip_add_data() to register the GPIO chips which means the devres subsystem will unregister them only after the function 'mt7621_gpio_remove()' returns. During the window between domain destruction and devres unregistering the GPIO chips, the chips are still fully active. If a consumer or userspace invokes gpiod_to_irq() during this window, 'mt7621_gpio_to_irq()' can dereference the already-freed irq domain pointer. Thus, manage the IRQ domain teardown using 'devm_add_action_or_reset()' to guarantee it is destroyed strictly after the GPIO chips are removed. Reported-by: Sashiko Signed-off-by: Sergio Paracuellos --- drivers/gpio/gpio-mt7621.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index ceb99641baee..57384ef74703 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c @@ -272,9 +272,9 @@ static const struct irq_chip mt7621_irq_chip = { }; static void -mt7621_gpio_remove(struct platform_device *pdev) +mt7621_gpio_remove(void *data) { - struct mtk *priv = platform_get_drvdata(pdev); + struct mtk *priv = data; int offset, virq; if (priv->gpio_irq > 0) @@ -475,14 +475,14 @@ mediatek_gpio_probe(struct platform_device *pdev) if (mtk->gpio_irq > 0) { ret = mt7621_gpio_irq_setup(pdev, mtk); if (ret) - goto fail; + return ret; } - return 0; + ret = devm_add_action_or_reset(dev, mt7621_gpio_remove, mtk); + if (ret) + return ret; -fail: - mt7621_gpio_remove(pdev); - return ret; + return 0; } static const struct of_device_id mediatek_gpio_match[] = { @@ -493,7 +493,6 @@ MODULE_DEVICE_TABLE(of, mediatek_gpio_match); static struct platform_driver mediatek_gpio_driver = { .probe = mediatek_gpio_probe, - .remove = mt7621_gpio_remove, .driver = { .name = "mt7621_gpio", .of_match_table = mediatek_gpio_match, -- 2.43.0