From nobody Sun Feb 8 05:23:36 2026 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (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 8218D42A80 for ; Fri, 30 Jan 2026 21:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769807972; cv=none; b=m8YTKqLVlt+PSU7bHwEbh8StW9QSHkuwjcw6nrhCSZO2Y8glh+WtkMlvhIOAYWIjY5w8HS4TinJKN6lGOXF8r8Neiao+Kh8wOg5ztvrxYyltuZbBkZYLpBBdneUJlmEDtBk83mQcbOIzyXMgI382NuclxeHGHXuuFqrZbHpdC4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769807972; c=relaxed/simple; bh=vnk+gVQZ2FZz2jTOeGOxM3vkqmKHdb/HOO5Hb4ScMkM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ewGT5ABmynMbEAPPWh8o4YWtSjFX/Da6qEP0/DJ8y5mXm72YHc6/POC0nD0FiE8fDRkf2ZLsVpfz3Uo5rkewWDvJY4h3KuMTqoRbsSzVHFrAIupbGvPtSLBiqDO1H/la3VFjjWRtkG/QMa1xbh3VA1WFpx482EkndSfZVkQgvwg= 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=nBovkV68; arc=none smtp.client-ip=209.85.128.65 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="nBovkV68" Received: by mail-wm1-f65.google.com with SMTP id 5b1f17b1804b1-481188b7760so17819435e9.0 for ; Fri, 30 Jan 2026 13:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769807970; x=1770412770; 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; bh=g7emkTAOZf3RTCGxFWHqfyLFM5cRhc8/Waeh1SPd4fw=; b=nBovkV68BLIo2CKSk2VPVBBiADXmzn/IiO+nI0+ez2Qu6FK4gkwwkGF8qwZUG4clLQ 1VwlQ3G5N9Bn4ZKPuI2sNG3dfIYrASxHUvdDLYlGhm2EtgRPKumx9BJVGUWMzo9hcPP8 w8mTH9jDh5oMSWQzNl/UhbXpfW9q3QXh3pxoI5ULY/orw5EOq7uXippSlu1EtaUiS9GE x4ScRraTPS0z/Y8oS3YBUVsT6XuI69DnaPAZHgszmVT6jllaxIzYVyxWUCBYcyiVtpGk e48jJFT+U6/96myAdPiHpvVg0tSMgxMplOjW/GR5kADR2DnETDOYB6o+tKhan6EWw9Jk aTaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769807970; x=1770412770; 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; bh=g7emkTAOZf3RTCGxFWHqfyLFM5cRhc8/Waeh1SPd4fw=; b=TDjuKSQw0TmBWGNvM4j/F6YGFgeISj/05qsQre6PMfeZkPPa+cwvvNpCysXz+n1CSV l4H7AjfBq4eRNK8FxEBn6imeCZRUt3+vjY9Cx6oZNw9jW5Cr2ThBa4r9C/dqayaw3+up FSEUgkEfXs+9Vw9hUcJCiXkUURZ59Fe4P9vVikpltpt7rBLlHXdGuJBUL6RsKU+7aK21 WR1rWKRPashA/jrYdxa/YYNatfH+EMfEtBNPgLkNM0OCGylXlFkHaMn6OMfmCz1amADG i4R3f8li5II5tCh7Vp6/G7VG7UeiCAdAD0sLk4zcQnk1Cr1VbNIemmeRkqQKWp77oVbY 71/A== X-Forwarded-Encrypted: i=1; AJvYcCU8eZxpuX2k05VbRPB2jcD3HRXvpGb2OSEreHc1EpvZAgw+gaujl21fC5G9r4yyTRD26QKm1RXYtyg1NII=@vger.kernel.org X-Gm-Message-State: AOJu0Yzzu1R+d8XqUBDDxx5IpPFIYBA0zGMl1L+bDZJiyvWV4lfoQII3 G3XtjJj5OJRsowShbGWRm4GBX800itq1qWJQZnSpAVPJY0c7UtRX5kio X-Gm-Gg: AZuq6aKRI7wTAexwtiFK2VAPhTEh+8XMUsdMlQDiueyzL1BLfkfIrW1cZRlhA4tS3dG I/BItDX6RYKanUwsfTKomH6t9uewxz8CcJioGRaV3Cl4vc/8qsjeqj/zf996dz1jnnv0iCidCf4 k4Y674xbMknTpJW00zPYSR+aKCaoNogOiywnDCfmZ3s4iiwv0R3e7wbapCCuJEO6SImyG4bFOZE WLwDXvE2ytloAsU5HLauID9RB1SviMRG5LKni7zNNCNxY5Ca3rpbnLtnp5IvDONW201l/Q6ijnp f0dM9OKXeoaN/3B8CoiUXRDW36W20Kw/FcWcyW04mHhalhhYBwEZqNxYncao8aq8fazb1SSDNTg boTCuojv79B08LGEji7Hzixfm/WDuBr7oM7HZ3jaPjh3x1+9ZB+yUPi+oKA4l/RVXQPFPKavxaC LWVHh6cnOEN9v/B9n7efhEdsKz6cm016upDQNc X-Received: by 2002:a05:600c:b99:b0:47a:8154:33e3 with SMTP id 5b1f17b1804b1-482db49a483mr50562055e9.28.1769807969652; Fri, 30 Jan 2026 13:19:29 -0800 (PST) Received: from localhost.localdomain ([196.235.250.51]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482e256482esm22544215e9.12.2026.01.30.13.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 13:19:28 -0800 (PST) From: Salah Triki To: Koby Elbaz , Konstantin Sinyuk , Oded Gabbay Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Salah Triki Subject: [PATCH] accel/habanalabs: fix device lifecycle handling in device_init_cdev() Date: Fri, 30 Jan 2026 22:19:12 +0100 Message-ID: <20260130211912.220042-1-salah.triki@gmail.com> X-Mailer: git-send-email 2.43.0 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" `device_init_cdev()` calls device_initialize() on a newly allocated struct device. The current release callback, `device_release_func()`, frees the device directly with `kfree()`. This bypasses the device model reference counting and violates the expected device lifecycle. After `device_initialize()`, all cleanup must go `through put_device()` to properly manage the reference count and invoke the release callback. Fix the release callback to ensure that the device memory is freed only when the reference count reaches zero, preserving proper device model semantics and preventing potential use-after-free or double-free issues. Fixes: ea451f88ef9c8 ("habanalabs: Expose devices after initialization is done") Signed-off-by: Salah Triki --- drivers/accel/habanalabs/common/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/haban= alabs/common/device.c index 999c92d7036e..df20a0bb63e5 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -698,7 +698,7 @@ static const struct file_operations hl_ctrl_ops =3D { =20 static void device_release_func(struct device *dev) { - kfree(dev); + put_device(dev); } =20 /* --=20 2.43.0