From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143834; b=q+PIayxTadVsy+sUe0NfmsZVHaABCfeNj5Q4TNEXNjeOdpIBT/d7z2ZaAbD94YAm3Fhm C7Vu9NzDX/uIedqPk30xVJZHUxbHFhatG0lt7VYAQiGaxYrAsdhN0TTSdfuE+SsROdFHN TAQGWi6EwnBf4bDIoNyn+2aHpGIn4veOOHehFJXBzEOlwIBD1v6Mp1ktkbVOOFcrzFpg5 PrJV0T05H8rFJzwJfbPNzv9JhnPfKQQp1Ls8kHGKysKL6VplLf68ILfrS2kFGL8hdWHXf +uqh/Aztr7B83QFHW9E09lIi4FA7+j4PexiB3DIvw+QQADhF+XBP9hhP2ltBeGCl5cA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143834; 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=SY2fKiClYjxSbhBE/k+3G63b1fPAqexERqj15UxEJuJ0HGtX3nfkzDHHpXYEvkh7ZW9S RcM+vJ2KqIpn5K9w4riQ/oxT4uTqAGGBZTADLMSJG44HMN5svC0zjtYLtO6tT7N26MUph jjMTkWx5tU73rhCYOWTO3n1aGmX902l8cgJcVtzJwVolVwZKDSaXvlYUcf9HGeylBBoJq lTwyl7olg1eiWML+D8qcXEzpmI3K0HQLjIxb3Wxb62bJIujjmBnxgEUyZibPmFz1SOYsC NBGba7GZTPnGq5lpi3l9J7SCq+vovZonUSe1qsGzqIH8Ye1OujBuO0DWKJWsQjOTL6w== 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.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (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 1DB77606A31A for ; Tue, 1 Dec 2026 16:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DB77606A31A 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-f52.google.com with SMTP id a92af1059eb24-1b5ade5e0c1so5974234c88.1 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=w0FxMicF0wlQRPD2h6brOOcypdkl4GSoe890UjvMjUlH2brJDEUlscQEmcHUaroCgy Rt39oxfC2aCoE9qE1QFX3IOaQstKfUylaGdiUATyI0NBvwjWJpLMcA25gg14hVFNWVr+ gYenOh5WInr2aSSNchE3x7Dtbw0YAvcajxpZSyiFip9Mu/tcbav/SC3px/AHsd1842Gl pn+ySkwej+yIqFqFziu6/OCgOWL6S8V4tEcq904vQ7eUaPZOo0alWeU//wp90F12eVJu 6Akawmork1kIEKm8hZ99btZCsCOQHLzUo57OhnEheCYXIoQkNe8d5TyKmRS2E9y/BqdV vLTg== X-Forwarded-Encrypted: i=1; AL+hErFkUWyYK7ghSlrtgdxixuoE2pCh3S1vUctr9S+Syl/Bqk9KW0964XMxYuzA733xElz1SIurQi2goMsuTTY=@vger.kernel.org X-Gm-Message-State: APuU4Z92xL8sq0dEWDNFQR8UqlEA65H/EeOIn1hHqot1tfSwa3n/jvHz zFern7YTEqbbwIfRrc8fgWj2itT07ketVtenvZrZUyKavRXhCJjjx7Q= X-Gm-Gg: AZFdTZd49AxHhaKkOxE8aTNSAhbDiaC9MKrLW7AKnvDhry6RcGoSXRJyy7n5kyfTaJX fO/kNCMtM66mMrcjXlM2cF6OwgvWDNNBDTzEF4iHKHZUrg60bXRt9OnvvBYve9UJ/v/c2QjMuUR GZb+pywXnLYcldM7bOvvBsZETOmr67lh5efwjUI+DkP76S28uM0v981OC+T9CXd5OKJfL4bQB/H 0RTSdwTO5NmO80llHIr1jITQrU0k1ytSPDDlelOAUqRDLfEjbUL89qfceA1zsN/Q9wiU0Q458Mq B+5bclgfrx1Psf/8qHv/0ZB24F3C5/bqAM5c3B90oshh3ex81DcDwvnuBDLiFD9HRUgOEYliI2e 3t05B5nPtTfPImYAq+fSZ7f92ikxCgZ6YwQyiCn9nm85PrtnAG97qb0k9GNmjX+WbrhgfFEuC/k zGhKz6opZNsGBPU9Lsrcg4tZs+6JnYpjgc+jAKdiqTq9VNWJhVkTYJHDIHKiKdzAxzWiwVlczXs qxbUtt0z1agyTCojMpAEJl0mYyMM/9cbj6xgqmk0ROqMA5KwsI5h7HHlewwenfMhwOUL7Y5jjIH J/pxexyXWKNP6P5O2IK7C/ubmg09huIj1MKdDkYfEUmUhgjoYabGidJPhNilW/9Qy2uN 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: linux-kernel@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); }