Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1394686lqm; Thu, 2 May 2024 13:28:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCVwfpnPEs15Rwiiz8gFaR36FLHA6bYh24DYE1/leFGANK1QPaHx0slAsdZ8gogPmGuDRigZah5rTaKUwwD/v59+42dBrMAdVTMARA9Q== X-Google-Smtp-Source: AGHT+IHeALfm34EsPwc980qhXqzTkWo4Y5adWX8fNCXv3t//W+a3PnMNxYbNuNoSLuL5FwmoSjrj X-Received: by 2002:a92:ca0f:0:b0:36c:5d24:c77e with SMTP id j15-20020a92ca0f000000b0036c5d24c77emr1122948ils.12.1714681703908; Thu, 02 May 2024 13:28:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714681703; cv=pass; d=google.com; s=arc-20160816; b=sM6x6jzLYTLyO0iCabMh2FAGa4BVGPoIqfZHmcqFoSMeG8xojR3zuc/3RXT3iWHtzI IkdsSori09C7ASVaY4Y2A6vYE9lDIkVdwVMPRMaRXwZyROrNA2fa4eV/F6P9rBWu+Jx2 hmFy2ODhrUuXHPQo9OytbRJ4rcoGOS4ZW/mR4ihtVA6BRvNDMILb4I/lX/DNBbpiYQdo O84abfcsDr6F021fm1lV2rWGpjqkaWfAd+k2GAHuCEiyB8eFqMa+N2C+fm0QOanYgfUa Hmik28Ynw7HsoSDn7og5veEi9x3hWPkL8+BNFg3geaBvDsCySoKkp3hjouFRETePK4gz pE6Q== 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=wMVql5KdjuwfmJbfrh110ouV61yVttlpz4aqxOfQ0nE=; fh=bedqjpcyVmPTMGowvNer4dKgCGtZLVf532JH9/MihvE=; b=rkwqT1a9gx8ifLE/yCEk3rg7zJNruUaZm0X3bnrtUvvmEKEXlU+7sRebg1oPC8fdlv AZjPX3ec3SUxYw1mQxnxjBKEzietXxc4b4i0xbOtazozsJjqBR7A/w29sI5XmTiqZTPq 1P/rTIafzkgWw6n/FOtmtYYSl0/V6Mrsdf2+sWp3QQf2I8y0Bc++JK+vJxP7B+hOtHIV FCkj9sNYkKD1DGxYz+b86h2oJPnocf1SH0CtqfvCBv1J2gttA2WrY4uMQFKrj6R9h3uY CmTAyDLbP0prjtfU9/M2/v/AC6mGezcyil1VosebeXj36ZWPOpmbTnUnVHGR/sI/Ioch zHjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GKKa37gI; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-166714-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cb11-20020a056a02070b00b006147e2440fbsi1651240pgb.267.2024.05.02.13.28.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 13:28:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166714-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 header.i=@intel.com header.s=Intel header.b=GKKa37gI; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-166714-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 AB77328302E for ; Thu, 2 May 2024 16:24:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D6C515ECE7; Thu, 2 May 2024 16:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GKKa37gI" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 9ADFC286BD; Thu, 2 May 2024 16:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714667053; cv=none; b=WM3ZuFArbuJfP5NHdxj80nLWrRUxLFpwr6MktZ2ZCnL/E3JywKPcXMcxZ/RCo/ucXof6KYIZN2Wtyj88l0zO30cXXVCW+5gx8zzKH17oJk8Cq3DEcTPQ9Q2baq2wDFfV2WlH8HxCgtBfSdSB/UzIfIAeaGF7PuYeCoPa19AMr4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714667053; c=relaxed/simple; bh=8bnm0Mp6aA159OPgwtTWCVCezNkfmBxywIMR3Q9y61E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TTHwmjXElx7r/GLNaUyH0aye27vmjzKsY31Jo3u6zVfcBsSawHH/HK3k/cr9rdvTU7lL3hxnDkY6Oe342RBzlvxE+g4WaRTWbjUmRvFMTPxu0ix9XugTj1FuKcK8/8wKSP0iygvBiKigdu9W2Up7YQWVxsjLZ1hLtcYtYcZn+Fo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GKKa37gI; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714667051; x=1746203051; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=8bnm0Mp6aA159OPgwtTWCVCezNkfmBxywIMR3Q9y61E=; b=GKKa37gIIqWAHAiSatkA6xRV62Z9ho76bEiVxAGHZAx9M2cP69HPjoeu TqqNKxA5F0p6kEk2Ah6Bi9ytVzuUFfL0Js7fqKVjVfmgjG1t40KpZVqot B8+E6XdSOq1m4YO+VraMcbQABr4nKIXSfNDW38DBH6LXo/ru4Kq0vmzlM ISOCeUvH65/fM96jUMNQmIvcnjxXtDpWU1ZtZCuZuLUs3aMijqia6bNMQ 4kbfECwvGQOye77QaUMHs0ssHQU0vWq4KO4cwNjIbXZyeX95TPOfQxaAa ru4EO9lxBYAYzhSCLh5qcyXyI3RHZ2OD7lxtZ4i6vVgqC/yFuKqbzZG/T g==; X-CSE-ConnectionGUID: CJqBmeXIR+m8P55T7I1EBA== X-CSE-MsgGUID: zMIcjpw9Tha5uYbS0pnuHQ== X-IronPort-AV: E=McAfee;i="6600,9927,11062"; a="10378778" X-IronPort-AV: E=Sophos;i="6.07,247,1708416000"; d="scan'208";a="10378778" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 May 2024 09:24:11 -0700 X-CSE-ConnectionGUID: gyKOMwuERVWbe1SWC/Pk/g== X-CSE-MsgGUID: 2BvGVijpR2OhXI8q1CaqkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,247,1708416000"; d="scan'208";a="31662271" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 May 2024 09:24:07 -0700 Received: from kekkonen.localdomain (localhost [127.0.0.1]) by kekkonen.fi.intel.com (Postfix) with SMTP id 8C03A11FA94; Thu, 2 May 2024 19:24:04 +0300 (EEST) Date: Thu, 2 May 2024 16:24:04 +0000 From: Sakari Ailus To: Laurent Pinchart Cc: Julien Massot , Mauro Carvalho Chehab , Tomi Valkeinen , Jacopo Mondi , Kieran Bingham , Niklas =?iso-8859-1?Q?S=F6derlund?= , 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: References: <20240502-master-v1-0-8bd109c6a3ba@collabora.com> <20240502155626.GD15807@pendragon.ideasonboard.com> <20240502160830.GB11443@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=us-ascii Content-Disposition: inline In-Reply-To: <20240502160830.GB11443@pendragon.ideasonboard.com> Hi Laurent, On Thu, May 02, 2024 at 07:08:30PM +0300, Laurent Pinchart wrote: > 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. I still prefer having devm_*alloc() functions than having the drivers open coding the same -- with the same result. The frameworks won't enable doing this right at the moment and I don't think drivers (or us!) should be penalised for that. The driver authors will only change what they do, with these patches or without, when told so. But we don't really have an alternative today. A similar situation exists with clk_unprepare() and clk_disable(). -- Kind regards, Sakari Ailus