From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143833; b=WIslLxfrA3mwEmgEENCzvfD5dpIjGzaLNdrz42YLuEZBLaCnsCOf2X5YCNv5TjroJAVN aQrgBL7vkgjQo8AGhnAnv/Tw5wpHSLgPPXvH1HjKwuJJWQ/mwKwtclzM3+FYaB9nImQPy ADc0Ymeo4cDO5k0o34lVKkLQQpcCbY22XjZEaG04w2VcUUux0wdDUkaub9oTgXEOns1ke ddoGVzr1RrTn31DMbz4YtbEgixGzfFw5IwveuhHOYndTij67W/xoLujf5tI7VUVuinXw6 jYGiei6J/S3cVyXG5rasZarpF72DlAW8DSynBUk0S+QLyjd0gTlW3B86t7LVSV9gA/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143833; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=144EEBcJ6W1Pd3SW8eEp5qJwyySVvEQ0rWxG5MlEe4s=; b=ya2YaMRi97UckzHuPlrDlAn3i0ZeFcoZQdE0L9lLPhKyav4tMRJP+06VPc5A65Aom4Tr 2/3X08CtioQ1cQj7+O+tye8vVaBvD/kVmhqoU8gLEexJfIiLIHxT/amLKaVMzWGm6Wgxb r2DrQbvkswnYH8bNtrrqWfiTXcY1F+r38LbdWTyl67e8kQewgs9A8So20ytVaxHkNMaIr tYs/d9FQub+9rKJbo5xrfOlqnCHB40kSrQUeZpLkcWntTpDIQKNv1mbzeLCXzIB24UEXa PGPmX55r+4YWwmpfwcH2W7eduNiC8WxXacJSD1xZBHtGSK4P49pK3ejIDxs851fKZag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=WyD8NaNO; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2153C606A320 for ; Tue, 1 Dec 2026 16:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2153C606A320 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.a=rsa-sha256 header.s=20260707 header.b=WyD8NaNO Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-15ea896ddc8so19607250c88.0 for ; Tue, 01 Dec 2026 08:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796143832; x=1796748632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=144EEBcJ6W1Pd3SW8eEp5qJwyySVvEQ0rWxG5MlEe4s=; b=WyD8NaNOmWvPkWeaeqpNYCsk3VM+/QAuWoFBPgn1+ZwSsVpBMdx7g7nYHiF6zCEZ1T 3C1Sm70CQrRzOqahtguGszDbFxd5ZY/9ZSNpKHuta0qx/01TjVIhyDMvyksG9XtdYBTH OSXUYaL7go4fEDt0gTJ1IjkZoZtLA7ChTJh0uWDmfiP6kt0LCGqpISp9bHBn+dltimAe nL/GS7pGce36237PUq0WezdU0zfivWrbKw2Y3PhuqYaXO1QJbUZp4J2mKKM4OUUhMpAz rJ4rRMtM8REVfik7TyvOjS2QnJ8kN+eWakDJd2GR4i6seP4WA0Z2wCskjoOXPG1r3ieI 8DwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796143832; x=1796748632; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=144EEBcJ6W1Pd3SW8eEp5qJwyySVvEQ0rWxG5MlEe4s=; b=thpRGNwt90nsjZPV9hOj5ObaUnt4C7jH4JANHqf8Zvvw9nBIGkwUxZ5915SIYyf5gy R9rO9zeEWFgcFQnJZP1gzaGSFsmXSavEOdtNT81Av4ibV5DINdXwxZ8eoJRSPZuSABzH 8WaGBFAXQsSgGWvZx4UxBim4MW5KD6mkjdpdcsqgOk45piVG0pgNSK5zoyObp58h0Lni PscgqeVWFsb+wmGB8RjFEM4q2XbTlc3/ev5krkn4qOb8eDjmvq19FQ4UO6ieg3hqtgg0 seFXiT9tKJvqrz7Fqed98vSJjzXyNZovEUyKqRdbBU7cdIAIh/TFhdtQ3bj87cnBVzCf AJFg== X-Forwarded-Encrypted: i=1; AL+hErGTnBHYSqdo8VZBbvxBICKRPXqC88TzuTWa7ayBCjfxgN05uPBcPWAGKjLrOvm21OATJcUqZzA=@vger.kernel.org X-Gm-Message-State: APuU4Z/5RtTAtXvfU0eQG3LLMTu4ke9q9GUdDC7M1hQA2vOGsw3c+nf6 KbiUunC8rjcWoYKBl9wrc1rb6UbSXvQzryDItlR3sy/+Xxy1MESAOvY= X-Gm-Gg: AZFdTZcUmlAIovuttEWgToe9FTICPcgqdvzxyuStSzGDNwyX52yHvV4QrAz5AXCsl+5 vO9GjpdUnecMglBXWATvCB4nA9O7FsBCL1hT268D9frfk8dikto+nEazV9+2sCTq1UdKOfzXGa/ AVtOOdfpOas7+81SjO6bx822pJjkufvyxFlxG/jiSGHknGBtA7/tDOQtVPT2Gjjd7DkGP2UBe0y KZbLgQ2eEOoTTHbWCZczIMG86N0BUsSytnz30YaTeaTf6MMA8VwFQAKbEbZBZwKWIRiwfkBiWfJ FStxOstUNbqG0U3xRSMtYLE4udMDyqdUIHM8tFaFcA10tZ3Vl2glPrUWH8BrrkaGrATQJP6RahR x1UiCuKJPA5O6QUf1EnMl/GEFD9SkmPNMAQ5NoVWtI8pc0Vbx5/g9rDuaAZY84nWtC/Pi27a8Q4 AezBOAhipNGQY4AU6O577OesnKJEhHbZMOkpYfc76kAGNTng4BfbNHL1B29PEUhODtkB2tyrWV3 4lniHRs5d/ETRuTeRdobsGT+M0LHTcOxYaqz8MlgAwAcWtnN7SXJ569qC/cfIO7ixTyaTopEDLU 0XbylrTmXlt5oUbLMJGmg3FggxiD/AEwwdcQzFr3Hq5UiomG4h9rkoONsN8pFOIhANg3 X-Received: by 2002:a05:7022:e981:b0:1b4:caae:3324 with SMTP id a92af1059eb24-1b5568ac1d5mr48166677c88.21.1796143831902; Tue, 01 Dec 2026 08:50:31 -0800 (PST) Received: from localhost.localdomain ([2406:3003:2002:639c:cdc7:5dd9:6daf:e8c9]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm106925419c88.5.2026.12.01.08.50.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 08:50:31 -0800 (PST) From: Yige Jiang To: Krzysztof Kozlowski Cc: Yige Jiang , Santosh Shilimkar , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] memory: emif: Unlink controllers before releasing their data Date: Wed, 2 Dec 2026 00:50:25 +0800 Message-ID: <20261201192850.687859214a59.emif@gmail.com> X-Mailer: git-send-email 2.50.1 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit emif_probe() adds a controller to device_list before probe can fail. Neither a subsequent error nor driver removal deletes the entry. The list then points into released device-managed storage. The pointer to the first controller, emif1, also outlives that controller on removal. Link the controller after its registers are ready and before requesting its interrupt. Unlink it if the IRQ request fails and when the driver is removed. Use the same spinlock as the interrupt-side list walkers. Serialize probe, unlink and register-cache dumps so that another controller cannot use emif1 during teardown. When emif1 goes away, stop its peers from looking up their cache through it. Create the debugfs files only after registration succeeds. Fixes: 7ec944538dde ("memory: emif: add basic infrastructure for EMIF driver") Cc: stable@vger.kernel.org Signed-off-by: Yige Jiang --- Compile-tested on arm64 with GCC 14.2 and W=1 against v7.4-rc5. No hardware or runtime test was performed for this revision. Related DDR-node cleanup in the same probe function: https://lore.kernel.org/r/confirmed-20261105-11-5d830ffabcd8@gmail.com/ drivers/memory/emif.c | 48 +++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c index b5d41ebb19f3..a829d7532fe6 100644 --- a/drivers/memory/emif.c +++ b/drivers/memory/emif.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "emif.h" @@ -68,6 +69,8 @@ struct emif_data { struct device_node *np_ddr; }; +/* Protect emif1 and the instances that share its register cache. */ +static DEFINE_MUTEX(emif_instance_lock); static struct emif_data *emif1; static DEFINE_SPINLOCK(emif_lock); static LIST_HEAD(device_list); @@ -114,6 +117,7 @@ static int emif_regdump_show(struct seq_file *s, void *unused) struct emif_regs **regs_cache; int i; + guard(mutex)(&emif_instance_lock); if (emif->duplicate) regs_cache = emif1->regs_cache; else @@ -670,9 +674,26 @@ static void disable_and_clear_all_interrupts(struct emif_data *emif) clear_all_interrupts(emif); } -static int setup_interrupts(struct emif_data *emif, u32 irq) +static void emif_unlink(struct emif_data *emif) +{ + struct emif_data *peer; + + lockdep_assert_held(&emif_instance_lock); + scoped_guard(spinlock_irqsave, &emif_lock) + list_del(&emif->node); + + if (emif1 == emif) { + emif1 = NULL; + /* A later first instance may have different DDR geometry. */ + list_for_each_entry(peer, &device_list, node) + peer->duplicate = false; + } +} + +static int emif_register_instance(struct emif_data *emif, u32 irq) { u32 interrupts, type; + int ret; void __iomem *base = emif->base; type = emif->plat_data->device_info->type; @@ -692,13 +713,17 @@ static int setup_interrupts(struct emif_data *emif, u32 irq) writel(interrupts, base + EMIF_LL_OCP_INTERRUPT_ENABLE_SET); } - /* setup IRQ handlers */ - return devm_request_threaded_irq(emif->dev, irq, - emif_interrupt_handler, - emif_threaded_isr, - 0, dev_name(emif->dev), - emif); + /* The IRQ handlers can walk the list as soon as they are registered. */ + scoped_guard(spinlock_irqsave, &emif_lock) + list_add(&emif->node, &device_list); + ret = devm_request_threaded_irq(emif->dev, irq, emif_interrupt_handler, + emif_threaded_isr, 0, dev_name(emif->dev), + emif); + if (ret) + emif_unlink(emif); + + return ret; } static void emif_onetime_settings(struct emif_data *emif) @@ -1086,6 +1111,7 @@ static int emif_probe(struct platform_device *pdev) struct emif_data *emif; int irq, ret; + guard(mutex)(&emif_instance_lock); if (pdev->dev.of_node) emif = of_get_memory_device_details(pdev->dev.of_node, &pdev->dev); else @@ -1096,8 +1122,6 @@ static int emif_probe(struct platform_device *pdev) goto error; } - list_add(&emif->node, &device_list); - /* Save pointers to each other in emif and device structures */ emif->dev = &pdev->dev; platform_set_drvdata(pdev, emif); @@ -1111,9 +1135,8 @@ static int emif_probe(struct platform_device *pdev) goto error; emif_onetime_settings(emif); - emif_debugfs_init(emif); disable_and_clear_all_interrupts(emif); - ret = setup_interrupts(emif, irq); + ret = emif_register_instance(emif, irq); if (ret) goto error; @@ -1128,6 +1151,7 @@ static int emif_probe(struct platform_device *pdev) */ } + emif_debugfs_init(emif); dev_info(&pdev->dev, "%s: device configured with addr = %p and IRQ%d\n", __func__, emif->base, irq); @@ -1141,6 +1165,8 @@ static void emif_remove(struct platform_device *pdev) struct emif_data *emif = platform_get_drvdata(pdev); emif_debugfs_exit(emif); + scoped_guard(mutex, &emif_instance_lock) + emif_unlink(emif); of_node_put(emif->np_ddr); }