From nobody Sun Feb 8 00:26:13 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 D41FE38A2BE for ; Fri, 30 Jan 2026 22:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769812528; cv=none; b=rNcpg8GpgqGunVzkkeZWAGKUNTD3BW7noFLpBD2gcrhY9is5XjHZqmJIlRI7jZHhJVL8c/69foyJmo49BFtBtFUerWwnbhhchBzY50THAkLINlT2z6ksI6iKZsJTisQ6Z1ZEqMfQ0VKIlH/XHszFpbz/XmD2un9trxSFImSWHJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769812528; c=relaxed/simple; bh=MyqzVqqhpne7ZfFIkcTpYZmN9+BYLsqFVzFulkr7G8Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RXQswab5ZSxdQyQIAkibSNE1Hnc5hgfEBvW53wkji5JA7BhdUq6gRvBLRQKcmP2CQHiQaFVSL5lyLxaeI631sd07S4qYki6Z9J1FhzOrmDAROti+DEl71nLc3hng+e/2bvAPFMArQJivWfW5LjvTCbLfwTAVYdMXtmjhE9/97f0= 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=F9xep1Su; arc=none smtp.client-ip=209.85.128.54 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="F9xep1Su" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-47ee0291921so23880775e9.3 for ; Fri, 30 Jan 2026 14:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769812525; x=1770417325; 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=Kdl/rOgVXHfXgcAd/rJu+u96UCjzlI6iVNNA6zmtQpk=; b=F9xep1Su/LIwWaEu+lmiPAn23+OrQ0PgZ+IFj4h7cFW8n7OkzwLmJjccWMJcSmVLEc xOQmT8yToqPr7u8wI2kD105Z32j/AvdNoVfhUSqejuHnEL+VcfIBbIbtzxMMuuW36qar yP8s3Ytj77bY+Gszbr8mlx8/W95od5MkKkmsm1HJO1XRwOPu0jVCh0AaBviydROLBaIi 4YREMebO7lNB3f7OzV46Bd/6ll9dW3W0bgiTx2zW28oWPpnetsubrEgCHDSWu28EDYD6 0iQOyH87RLu4XuTE7cqjDL+LDjaE7sQvggRtPQvl/ByMjoqMiWpFR3rrT68Ruj383PYp jOKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769812525; x=1770417325; 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=Kdl/rOgVXHfXgcAd/rJu+u96UCjzlI6iVNNA6zmtQpk=; b=sSW/OO0OpvhKuhN3nkpZlYeDyGDKW0MDGMS2KbS7+syLv1FaMc03CyBXpqn9PLPqXQ pRttawYhU9++xPhQ+hqXw/QmzaZxnslflS/m/scW4aRFY1GIsMTl60GnvVVLUDm/F/Yr pAbCh1bx6c3qZyOjVaq3SobAEzLQPG0ZiZi3hxpdfDK3aBKjXy9s08Gd/8NFMZUufqNe nmFnx2Ht31DEWkoNl37gOFfGCY7cui3t3X7kAvYa3IfAeLt3jzdf0MW7gEZk1WdU8bR3 8X1cKr0JrQFC5S72DZZq/Y96KPoGX9XYBQr/ZtnQhznvQVTFmsqVAZY2QrLiCRQms8Xk LYsg== X-Gm-Message-State: AOJu0YxVmDPD08/G8XuTPQ6STL+XfNBvVOZiFsHkdfRDI/01OMUaoVWi 5vFkQmBCcU8EKgX9h3le5SWnI0POGOEgwhv+WudS7yleFOKTWcuuw3VX X-Gm-Gg: AZuq6aLgONcupHazdX5ZYsBGyJyfZzjfFhXrASORrZzkqdMJx4pnu0RKdlAQ8tRBpYG 8yA8Q1n5l63JuA+rm5yfCsvGczIvTaihlY3sOdPEDGPzPi14EEYYWSqpNFc9sqd8aqZX6hlmHKe NhWS4WfNnWXwg7V/fUasgY8DmnovS2DEu5ykwbqcy67Q0WCUWHItXbimHi2Dvg/TMWgKgnF6H64 ZuZwYHroBnh6/Dagh6ETzjg7TUIsWHCKwUz8mqJmlbqlcQrBrqySqBQvJ2Bxi899aSBBIGkAiDz Vhg+AhQBzrO75juWpxkD1AHRRDa4yMSBmZXdBHYo8UUrzaCXz561nAgjSJUF3EqlWHV/4pZTCY/ yp/zFeyrGn4EHNOq8ez8qzxM/zX6nA7ibuqoW8mdX9TypKXswO/UX0QXoBcGDxJwrRgdlB0LcXe 20tAR7UKs0/fJacYHAIR8Evkx5Lzr9LJvQp2Fw X-Received: by 2002:a05:600c:6814:b0:480:69ae:f0e9 with SMTP id 5b1f17b1804b1-482db4ac0b0mr56073155e9.16.1769812524857; Fri, 30 Jan 2026 14:35:24 -0800 (PST) Received: from localhost.localdomain ([196.235.250.51]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482e2e3beadsm23654375e9.20.2026.01.30.14.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 14:35:24 -0800 (PST) From: Salah Triki To: Ian Abbott , H Hartley Sweeten Cc: linux-kernel@vger.kernel.org, Salah Triki Subject: [PATCH] comedi: fix device lifecycle handling in comedi_dev_kref_release() Date: Fri, 30 Jan 2026 23:35:17 +0100 Message-ID: <20260130223517.223996-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" `comedi_dev_kref_release()` calls `put_device()` on `dev->class_dev` and then immediately frees the `comedi_device` structure with `kfree()`. If the device reference count reaches zero, the device model release callback may be invoked, potentially accessing or freeing parts of the structure. Calling `kfree()` directly after `put_device()` can cause a use-after-free or double-free. After `device_initialize()` and once the struct device is in the device model, all cleanup must go through `put_device()` and the release callback. The kref release should not free the structure directly, ensuring that `comedi_device` lifetime is properly managed through device reference counting and preventing potential memory corruption. Fixes: 5b13ed94a7d24 ("staging: comedi: add a kref to comedi device") Signed-off-by: Salah Triki --- drivers/comedi/comedi_fops.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c index 2c3eb9e89571..24bb06fe6b45 100644 --- a/drivers/comedi/comedi_fops.c +++ b/drivers/comedi/comedi_fops.c @@ -118,7 +118,6 @@ static void comedi_dev_kref_release(struct kref *kref) =20 mutex_destroy(&dev->mutex); put_device(dev->class_dev); - kfree(dev); } =20 /** --=20 2.43.0