From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=213.167.242.64 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796360694; b=EKpWhH434Ngi6yq+ABHjcnm6wp61ioymwF4nUbe8KeiAbZjAjFsHSqRaOpOFm4IeRnsO l/B2WqxQQA8dvW2JojhrETbWkJEt0S0OiPWoQkhnDrzVLhDa+bCkCN4to57CsOpJfkdkz t4q82VAf1O+O357PB2Ply4f2UziDYtmHM58Yho9AP9+0XCrgVGuQLTC8iQQDxulUZol/B FBEJmA7PjDdO/eQ2IxUb/4BoyUeTX5FEcjgOREF3mso2Kq6OKcg6s+Q2A6BYlH9PzGyyu uf4Z7atA8lwtTB1HNPF9k5SOY/QYhxmsKuK4h0sLmU0qGYwSbLaSeWEZI9R3VMM8J2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796360694; h=DMARC-Filter:Received:DKIM-Signature:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=VSi7IpQuXVXThL+g8F7Vf8Lzls65J4Fl/Ah9vvKLxWc=; b=m/QCgSjrfsCKkEJISUiVxh0Azb4cqMYoXjSb9CojkCd78zsMWb2u52rErMw/xBAuWlHz rOfb5+zuvIpMF4znB8YW07FkPdJnKOXXtzcwYeqTYUbD6wP3NOTatiseZE8qV53WraSXM PRduxF7P4w+n/aUtr8CAf6IzVXuHRsrvR75DDkLVQVcesDCJ1bfqWHE/w1RSFeSIUE8Ol gmJa6BJXYzd44DfdHx12EEN8B8ncsZ4CwvFrY5IH8VnMSAS39EeHvvu1RycVBLuZkmdJL EShWer1ebEMkzv8DuwpYkcSNftnq8Th6u4yI7leTf8qEq7WWq6jm3e4eby4WqzdiyEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=NGiLqYLb; arc=none smtp.remote-ip=213.167.242.64 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E535606A32F for ; Fri, 4 Dec 2026 05:04:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1E535606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=NGiLqYLb Received: from killaraus.ideasonboard.com (fp7965754b.ap.nuro.jp [121.101.117.75]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 31D49227; Fri, 4 Dec 2026 06:02:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796360532; bh=cn82Xo7wlPhhx1jm9/Rl008Rabjk5vwMnWCB1PXfk9w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NGiLqYLbRS0pdwAgOV6n5ICb1V1Qd2EG7dYGvjDFWOzkEmLbBXYI1XI4cADl9PW4o UPb5l+8JRmtHlvUj5Np8+1xY/7mttQaQ+zXEqk4NgFHL7fZixViY1rJZ7d/bzR7HRk tTllQw2/m07zxQsxd/hu7fe+BmzTF0NIuS7LDr2Q= Date: Fri, 4 Dec 2026 14:04:45 +0900 From: Laurent Pinchart To: Ian Rogers Cc: linux-media@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sakari Ailus Subject: Re: [PATCH] [RFC] media: Drop v4l2_file_operations owner field Message-ID: <20261204050445.GC597403@killaraus.ideasonboard.com> References: <20261204021830.639597-1-laurent.pinchart@ideasonboard.com> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 03, 2026 at 08:17:00PM -0800, Ian Rogers wrote: > On Thu, Dec 3, 2026 at 6:18 PM Laurent Pinchart wrote: > > The owner field of the v4l2_file_operations structure is used only by > > the video_register_device() and video_register_device_no_warn() wrappers > > to pass the owning module to the __video_register_device() function. It > > has to be set by drivers to THIS_MODULE, in order to properly refcount > > modules an open() and release() time. > > > > The V4L2 core silently accepts a NULL owner, making this very > > error-prone. Multiple driver forgot to set the owner field, resulting in > > refcounting issues that have been unnoticed for years. > > > > We could fix those individual drivers, but the problem would be likely > > to occur again in the future. Fix it by making the error impossible > > instead: remove the owner field, and pass THIS_MODULE to > > __video_register_device() from the wrapper functions. > > > > The changes to drivers was generated with the following Coccinelle > > semantic patch: > > > > @@ > > identifier fops; > > @@ > > struct v4l2_file_operations fops = { > > ..., > > - .owner = THIS_MODULE, > > ... > > }; > > > > The only other change in this commit is the removal of the owner field > > and the changes to the wrapper functions in include/media/v4l2-dev.h. > > > > Reported-by: Ian Rogers > > Signed-off-by: Laurent Pinchart > > Hi Laurent, > > Sorry — I replied to your earlier message before seeing this RFC! > > Removing v4l2_file_operations::owner altogether and passing > THIS_MODULE directly from video_register_device() is even cleaner than > annotating .owner with __must_init, since it eliminates the bug class > at the API level (and works for GCC too). > > Two quick things I spotted while checking the tree: > > 1. drivers/media/radio/tea575x.c:532 (tea->fops.owner = owner;) and > drivers/media/radio/radio-tea5777.c:556 (tea->fops.owner = owner;) > weren't caught by the Coccinelle rule because they assign .owner at I know, I should have mentioned it was a quick RFC. I didn't want to spent time auditing every driver before getting feedback on the general approach. If people like the idea, I'll send a v2. > runtime from the caller's struct module *owner. Since both are helper > modules registering on behalf of a parent driver, they'll need > __video_register_device(..., 1, owner) directly instead of > video_register_device() (which also lets them drop copying > tea575x_fops into mutable tea->fops). > 2. For my 5-patch series: patches 1–4 may still be useful for stable > backports (since this tree-wide refactor won't backport), and patch 5 > (media: sunxi: a83t-mipi-csi2) fixes struct phy_ops::owner rather than > v4l2_file_operations, so it's independent of this RFC. > > Thanks for putting this together! > Ian -- Regards, Laurent Pinchart