From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 AA3C048987F for ; Fri, 31 Jul 2026 06:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785480601; cv=none; b=I+G9gxdssjRPZAdp/EUM4jHBO5RBuaO7/elJAYNYz015V4gGkKA2pwGCL2drzrIc3H3hKE0b7VWH/dOpUUwPiKc22xiE+j+n+Vx+tQYfiogUVUpzpO51ANCl8W/H3tCOHwTkr3kpg4j9YiuK6V6LKo2LIky51BByXGLty8sK0B8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785480601; c=relaxed/simple; bh=llWdlr+xs7S6gqsIBcINC3VyGdGrXqFW1L+lsyJPbjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dURzM9jtokpyxz7PXVJgo2FGQ5O+6qIVDE6AFEL/2Nlrwb5mVy0b2Zc7MbsrReIjLv3oD162Qc65vtay5Sy4mKYCL0Ud2J8aYNPUiIVbO/CJk3hzBCP0nd0pKxoi/XMU7fiGZQU4TOBHc0oPiWXPcbdR1Xlzo53eei0mCdCRISo= 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=rjcs5Z7q; arc=none smtp.client-ip=209.85.221.41 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="rjcs5Z7q" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-47df6a5655aso71328f8f.1 for ; Thu, 30 Jul 2026 23:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785480598; x=1786085398; 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:content-type; bh=kXo8J24KrU8Vbaf2n2kgu1xGVPuRWaU3gl3iPntegac=; b=rjcs5Z7qyCUFOBi62rp6Qn76TYnQGP/+XSwpXy89zYyhK0T8NYLcPurwlrpLg300OT XD2DJbkWcQRXl+gm6CAP2UjFcvIqF+1w1Y8iI0DYvtbzav8rxJGHpK20zc/LeaqR4JvQ G6JzfB8YVefEMyj1eyFy6HIkAhYiQE91c1VtA2fPDiaD39jJHv+IA3A3pWYrjNeZ/dRW 0ExiWQGfrPZfcrgW8UdumlPvx4eryAXtkjrvCx4ga6GfPtZc86BaNvrPGYF4QBzlJ4XY hSF5p5LFq3Tqt51tKBm6WtASv7XmL3I03xnZkURT03LwgBJRpFhV/LCRV2ETzhL6bGqW oSiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785480598; x=1786085398; 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:content-type; bh=kXo8J24KrU8Vbaf2n2kgu1xGVPuRWaU3gl3iPntegac=; b=SLJHUVyyWd9K7qpyvuPHAJsTu6I7yXXT5jkBK7Iz1+ef6z86f8smBTq8ITGjGmAfeC me8Nclu0v1n6IspmwSyV5Ej+HnXfIX0r8Lr9FPlO6gxlxUHP2nWJ0/Z1C8C1I4DADKxT LnB4wdqBdmol6fcmaLK/Kppio9zMyS3B6zg5KMJOWmb9xZflFLEd8U4D2y2O+79RU9yl bP/zLgfNgvZrgJFtCQIUbXdkTH/NCVvWrqhc82/94Kj5qvBDyorrrevWKVZbfB5iHI2u BoKLBedjUGUeRKgJaRlDSdBASKIf7S/l8fxt6CnXSDUIePd3vRRerBxbbGQcZBPZGSzy 1tCg== X-Forwarded-Encrypted: i=1; AHgh+RrXd1+6aDWk31rLOAZxZ0X0/3OkiWh8BOaqabr+29fRroYCwQkB6NhZ2ZXYed/cMBdQ+0trvLq/t45QGOs=@vger.kernel.org X-Gm-Message-State: AOJu0YzJR9nMU9n83AV3Ah0/brGex3O4Kd3FymRFh5yleHVnEHC2heIt OkhmYMpIVe+LxlFy8spGvjLdR223mxG1K7lw2YeRYD3bp86D6/7K36/s X-Gm-Gg: AR+sD10y+zQMYmeVaOw6RoTOVf15JMG09qFn/l6qeFeHYRnSKoks9Fth0+2wSDQeiN4 qy4530XxdLTxEnRs0b0vHQ0+ywQhcjldiDSRH8itCwBMjrEDvUUNQ4gx00F3zYRSz14ie6pff6B FYzYJ02YhSxgZt4j8hlmtbOol9LYPKMsEZCl8wuuyWXq+ESdMRw6gqMm/U3i8GkDjS4UyUoAYR5 mMegQz8SeFUZ3mZjlrXaBxEsL/ifz+bRO5RuI78+AJUUQQVLdx1sT+ipA0g85oE+NiAo68QDxUB a3EeyQwwEW3WYFnuaFR7H4H1oAdUdigltXu1blKLZltq2An+lKnDQN0g6YyrMxaC1+psf14SeJb C/ZW7r5xxP5S+84b+Ays099j8Z2kLgIVXdr3IBzhqv6sWGohFXySV2NgHrfUHu7rryIIBBE8QaT +3Lp6cNrnv2IvA66DyCu+cZUtcRoOphmQbRjS5iQmI2rcXwvhavRZJjks/yOS8sRSk/GewOrgA4 YW6dNKEBJ3IEr7OfrGujFCYutu9moi9Tt02Sqo2kE43dYows6PpvW/THdgtIyc+noWbvQ== X-Received: by 2002:a05:6000:2401:b0:47f:96bc:e370 with SMTP id ffacd0b85a97d-47fd2b653fcmr2421972f8f.4.1785480597528; Thu, 30 Jul 2026 23:49:57 -0700 (PDT) Received: from OrangePi5-Plus.BB-HOME (20014C4E1B8B8B0053881A2C61CA978D.dsl.pool.telekom.hu. [2001:4c4e:1b8b:8b00:5388:1a2c:61ca:978d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd41e2abbsm1212753f8f.9.2026.07.30.23.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 23:49:57 -0700 (PDT) From: Igor Paunovic To: Tomeu Vizoso Cc: Oded Gabbay , Heiko Stuebner , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Guangshuo Li , Jiaxing Hu , Igor Paunovic Subject: [PATCH v2 1/2] accel/rocket: release the shared device's devres on teardown Date: Fri, 31 Jul 2026 08:49:32 +0200 Message-ID: <20260731064933.12548-2-royalnet026@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260731064933.12548-1-royalnet026@gmail.com> References: <20260731064933.12548-1-royalnet026@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 rocket_device_init() attaches its allocations to the shared "rknn" platform device via devres: devm_drm_dev_alloc(), devm_kcalloc() for the cores array and devm_mutex_init(). That device is registered at module init, never binds to a driver, and is only unregistered at module exit - so its devres list is not released for as long as the module is loaded. rocket_device_fini() only calls drm_dev_unregister(): it does not run the drm_dev_put() devres action or free any of the other entries. Every fini/re-init cycle therefore leaks the previous rocket_device (with its embedded drm_device and all drmm state, including the accel minor number), the cores array and the mutex devres node. The cycle is easy to trigger: unbind the last bound core and bind one again, or fail the first core's probe (-EPROBE_DEFER retries included). Observable symptom, RK3588 (Orange Pi 5 Plus): each unbind/rebind cycle of all three cores moves the accel node forward - /dev/accel/accel0 comes back as accel1, then accel2 - because every leaked drm_device keeps its minor pinned. Wrap the initialization in a devres group and release exactly that group wherever the device is torn down: on the rocket_device_init() error path, when the first core's rocket_core_init() fails, and when the last core is removed. Each fini now frees what the matching init allocated, and the accel minor is reusable again. Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU") Signed-off-by: Igor Paunovic --- v2: unchanged. v1: https://lore.kernel.org/dri-devel/20260730080355.177422-2-royalnet026@gmail.com/ This applies on top of Guangshuo Li's pending fix, which it depends on: "accel/rocket: clear rdev on device init failure" https://lore.kernel.org/dri-devel/20260708062845.716487-1-lgs201920130244@gmail.com/ Verified on RK3588 (Orange Pi 5 Plus): with the patch, repeated unbind/rebind cycles keep /dev/accel/accel0 stable (previously the minor incremented on every cycle); normal three-core probe, runtime PM and a MobileNetV1 inference run via the Teflon TFLite delegate are unaffected. drivers/accel/rocket/rocket_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c index 67e7f54..d29c5ee 100644 --- a/drivers/accel/rocket/rocket_drv.c +++ b/drivers/accel/rocket/rocket_drv.c @@ -24,6 +24,7 @@ */ static struct platform_device *drm_dev; static struct rocket_device *rdev; +static void *rdev_group; static void rocket_iommu_domain_destroy(struct kref *kref) @@ -163,14 +164,19 @@ static int rocket_probe(struct platform_device *pdev) if (rdev == NULL) { /* First core probing, initialize DRM device. */ + rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL); + if (!rdev_group) + return -ENOMEM; rdev = rocket_device_init(drm_dev, &rocket_drm_driver); if (IS_ERR(rdev)) { int err = PTR_ERR(rdev); dev_err(&pdev->dev, "failed to initialize rocket device\n"); rdev = NULL; + devres_release_group(&drm_dev->dev, rdev_group); return err; } + devres_close_group(&drm_dev->dev, rdev_group); } unsigned int core = rdev->num_cores; @@ -190,6 +196,7 @@ static int rocket_probe(struct platform_device *pdev) if (rdev->num_cores == 0) { rocket_device_fini(rdev); rdev = NULL; + devres_release_group(&drm_dev->dev, rdev_group); } } @@ -213,6 +220,7 @@ static void rocket_remove(struct platform_device *pdev) /* Last core removed, deinitialize DRM device. */ rocket_device_fini(rdev); rdev = NULL; + devres_release_group(&drm_dev->dev, rdev_group); } }