Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1252441lqm; Thu, 2 May 2024 09:10:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrf5ukyJ7iMMEB2FnIYXt1cQ1k935zs5EZhi1kp1oQEsr6DnGiyfhkDnd4JmrSB85heNU0/R6CjUevM+na60ICLu+8fa1qYJaU0py6cw== X-Google-Smtp-Source: AGHT+IG7lEEKoILdsXbsobKniNGkx1fb8G0Peg3XmkuL0rJUR8VbiJUO8tvB6vUtz9LRX2XW7E14 X-Received: by 2002:a17:90a:1307:b0:2ab:9819:64bc with SMTP id h7-20020a17090a130700b002ab981964bcmr180205pja.32.1714666241381; Thu, 02 May 2024 09:10:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714666241; cv=pass; d=google.com; s=arc-20160816; b=SpIYjs5Ci1gG8XvEhtrzXUeozzwOE0WSL2tAcaihu4unsbOcKLUzmMyo0+T7Yh7LmJ GXngtJffvoUzQlGRB2a8UYJVcV6N+PoesMu/cp+iMMeHZoTNRV2XRbJ9269ha92WYjEn kkDE4ReEfT85LktIIIyTKf5icfSBdmp3G2TnkMTaUHB97qa8dGAu+bRfSqXauzX0ZbAR hH2srEuu2ETe/e8vx2QJOe2rYAijrx1U6tpVrRMtDXlCTsd5EelYYXN0C/dzMiOh6nex UqB7MSMl0LuiQH6/bquN0N6WCSvctzMkW3gkzJujDCl7Ys4YnaEsGQqQnrS4lsngExx8 RyzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8nZRUFkGdkwoa3LS8HFiFNi0zm+ERcrhbhtyHupPkc8=; fh=qIgA8LePr2qjuVpsHwZsgS1Y+Hq/GCkG9TZ4zqHPijQ=; b=DFMKglMyKMl3hYAjUnRQhsjRNjuloFOwOsHUVNTUpN6Gymidb5tL7WRXYa/mhpAfUY 7S4BlwXGgBHrmMsp11O9kjliBEjduPxykDAde2vHHDPuUZajDuEHqtPCstvJ/2hmu2F6 2hexUS0/8VABx1wp/ug2i7lZYNV+qk1yHLVDvvSX6+H4xnT/6iloIdgK/XOiwa2NF2ub 0MnhZn5KJGMvHDcJVyl+yIOBoi3r34CVUiYcZqOUE27VPpbA2PpykWCPWxVuNekw06sh ZuMn5X5mKO50qcDX996xqdEAIxAR9fzFiRL6JXxkoEHOkjueRGumdsAIXG2LffJIigNV YhSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Sp++7kuI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-166692-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166692-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l24-20020a17090aec1800b002b079e5cee3si1268216pjy.133.2024.05.02.09.10.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166692-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Sp++7kuI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-166692-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166692-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 03B95289023 for ; Thu, 2 May 2024 16:09:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2FFA15CD7B; Thu, 2 May 2024 16:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Sp++7kuI" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A25915E1F6; Thu, 2 May 2024 16:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714666121; cv=none; b=lP+kmycoKhzvVvCDBeu+vu5OEb6Y9h/pi/w8967pg9V3WeJ5XJB/ge+V5rsLKcHbJZiQrDSkUmtPkVBbm9uQCtByEKXiEaPs9uqz/FhE0ZTYxGPBQkusB4sQBiDcq5ee0rrfK8OONzgI8IGLmHiAoWvErTIq/miV8M5DaMkl2NY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714666121; c=relaxed/simple; bh=1zxbeK2Vc5xzfg9ivasxN0Y8bxeQt6RGSMFz/qIJEB0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KOZPijtHsdzTU36PQhByTl4BEEvxNIHx/yrAiggI5aYl0tH1XOli+T1USG/52Ah22UvaK9AjiFbgwREImuhYpIeZMeCCsz3HUgEP9WCBLcP2oJESX5hITAJSrWytGL9ul92Hn7YJ37ISLCpZeMNw+eVhxK1tpaQVrsHn20c1d14= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=Sp++7kuI; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 50D974D4; Thu, 2 May 2024 18:07:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1714666059; bh=1zxbeK2Vc5xzfg9ivasxN0Y8bxeQt6RGSMFz/qIJEB0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Sp++7kuIo7u0MWn92GCxF9L94GCFpxrJwg8v0jK9FWCLWTQXiLcmGPrhGhzZkfM7E 637vea6WUMWJ4A5o8RWfMKEhzyGsgm4Z3MNtZDwDfy83U9wUHOM0plYnky+y+NlbYU ozCC8vCzQXC5O9dQNjVpuQnijTzGK8LEvmClhovE= Date: Thu, 2 May 2024 19:08:30 +0300 From: Laurent Pinchart To: Sakari Ailus Cc: Julien Massot , Mauro Carvalho Chehab , Tomi Valkeinen , Jacopo Mondi , Kieran Bingham , Niklas =?utf-8?Q?S=C3=B6derlund?= , Benjamin Mugnier , Sylvain Petinot , Yong Zhi , Bingbu Cao , Dan Scally , Tianshu Qiu , Eugen Hristev , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Maxime Ripard , Rui Miguel Silva , Martin Kepplinger , Purism Kernel Team , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Robert Foss , Todor Tomov , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio , Fabrizio Castro , Dafna Hirschfeld , Heiko Stuebner , Sylwester Nawrocki , Krzysztof Kozlowski , Alim Akhtar , Hugues Fruchet , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Yong Deng , Paul Kocialkowski , Benoit Parrot , Jai Luthra , Philipp Zabel , Michal Simek , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-staging@lists.linux.dev, linux-tegra@vger.kernel.org Subject: Re: [PATCH 0/2] Introduce v4l2_async_nf_unregister_cleanup Message-ID: <20240502160830.GB11443@pendragon.ideasonboard.com> References: <20240502-master-v1-0-8bd109c6a3ba@collabora.com> <20240502155626.GD15807@pendragon.ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Thu, May 02, 2024 at 04:01:45PM +0000, Sakari Ailus wrote: > On Thu, May 02, 2024 at 06:56:26PM +0300, Laurent Pinchart wrote: > > On Thu, May 02, 2024 at 05:22:20PM +0200, Julien Massot wrote: > > > Many drivers has > > > v4l2_async_nf_unregister(¬ifier); > > > v4l2_async_nf_cleanup(¬ifier); > > > > > > Introduce a helper function to call both functions in one line. > > > > Does this really go in the right direction ? For other objects (video > > devices, media devices, ...), the unregistration should be done at > > .remove() time, and the cleanup at .release() time (the operation called > > when the last reference to the object is released). This is needed to > > ensure proper lifetime management of the objects, and avoid a > > use-after-free for objects that can be reached from userspace. > > > > It could be argued that the notifier isn't exposed to userspace, but can > > we guarantee that no driver will have a need to access the notifier in a > > code path triggered by a userspace operation ? I think it would be safer > > to adopt the same split for the nofifier unregistration and cleanup. In > > my opinion using the same rule across different APIs also make it easier > > for driver authors and for reviewers to get it right. > > > > As shown by your series, lots of drivers call v4l2_async_nf_cleanup() > > and .remove() time instead of .release(). That's because most drivers > > get lifetime management wrong and don't even implement .release(). > > That's something Sakari is addressing with ongoing work. This patch > > series seems to go in the opposite direction. > > This still avoids the driver authors feeling they need to implement wrapper > functions for v4l2_async_nf_{unregister,cleanup}. I'd be in favour merging > this. > > I don't see this getting in the way of adding use counts as the code will > need to be changed in any case. Fixing the lifetime issues would essentially revert 2/2 and move the v4l2_async_nf_cleanup() call to .remove(). I don't think providing a helper that forces the cleanup at .remove() time is a good idea, it gives a false sense of doing things right to drivers. This is the same reason why devm_kzalloc() is so harmful, it gave the wrong message, and created (or participated in) all those lifetime issues. -- Regards, Laurent Pinchart