Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp441848lqh; Sat, 4 May 2024 07:19:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVN7HzlCp2+20uQhpmMXfIt91acvhLfYfE0NDxB2PwW5MNbgScPsmBsRyIdC2s+5eZHd1wLQBINmW2BfShfn+Y3zMPDGyPhWMspkP9sgQ== X-Google-Smtp-Source: AGHT+IG3L/Q9HSTEIrO4dI2gEFrcS/o/9GSAoN4hTTUDghmedBrnbBrUR59xgRhEbfGM0mwGAvmU X-Received: by 2002:a05:6a21:2d8c:b0:1ad:9413:d5bd with SMTP id ty12-20020a056a212d8c00b001ad9413d5bdmr7225948pzb.9.1714832349917; Sat, 04 May 2024 07:19:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714832349; cv=pass; d=google.com; s=arc-20160816; b=qCIkWRBOeD3ltskypXcbjyxdu16McXh5luNtCNO8uHlmQPVOII2ut+XIvPVRsUd+gG DmJ0dZdXyeiDJTgAIgvMshCbqTIu8gQoktrurBLcyHFa2mm0l87tlsPXBa4j0wMdJXsH 9qH0BsVekj19KLvbLzLJOMYT5ssuKu2oCQUhzj1jLDWVjvQjdqpU66OysPNODfDrTUah W28OAfio0REJDBTuiZxReT7ETrPfv2Digt4VutADP/S4PgLDXLMN7b+0pz/i+5YFHu6w rnvmgfOreFOV3OkonRCJLdsjOff7dVbJ9iw6JQTUlcGr+CEF9jzQoONqAmEukQKW7sZK Dr7Q== 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=mwaA5+zom+5Wo0XH1dRd/TWj5pnnZZRN8SLtWgQr2EA=; fh=qIgA8LePr2qjuVpsHwZsgS1Y+Hq/GCkG9TZ4zqHPijQ=; b=yyHDv2wtygSED5ZS8eCuYmwL6FXEF6jZ5y4BpBLEDBzGK/K8mg/sfZ+52r0A8QoIDs vLbLPvWQepUGnPemX5ALf9eL/iCFmzS696WSeD0Ma4llOj6L7xK+MV6YNVLQQXbW1Tmb MB1hoC7JSKce81K/MfKXUpyn+mEIlQqiLZoARZhhuSVOHEtATlbC2R5vAZ/uMCx6nMBF ujS10KIcj6f7jpn6sa/x2Xlv6jioPp8/vFFVfKgD6CbCNNMvyevQyHhzAIwAuCBrJf+8 lN60jtuLy+7c81RZPS3DglQgSyzNvKzR7F+MHjm/XwksMH4pAfR0zvcjY/A0yv+WA26N doEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=oc2a49Dv; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-168700-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168700-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jc6-20020a056a006c8600b006f44e3a03a4si2850702pfb.264.2024.05.04.07.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 07:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168700-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=oc2a49Dv; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-168700-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168700-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 4B618282BA3 for ; Sat, 4 May 2024 14:19:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6DE33BBE8; Sat, 4 May 2024 14:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oc2a49Dv" 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 39BAC39FEB; Sat, 4 May 2024 14:18:57 +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=1714832338; cv=none; b=DwvMrb0lWSJkgOlL1RnhKZF/fdBScvuuh7LxUzcFmfcwnddLZ4XFQ7tN29gR7CzUVxLVtsyFp6M+9DIDpXL20jfMyihHfmOH5T5WEmHbtekS6rtlZleDxOm9fqt2gC5p/hYxo644Sr4a8HPQZpKNvb/+6ykvDQJNaxG5Qpw3xW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714832338; c=relaxed/simple; bh=w6bn/4no8NMVEJqPP561BcxXipVz/9y/dItL/1UBPSY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=szivVnzZ6f1pzVAPUv2OItJDKGjGHxGtanoKnuNlV/auFSkWQvJj72/Bg9lif6tJAp/Ll13MWSQaw2MLaZMEdTH6bgWhO+lSBMZpSXB7LHBD5C0Px9vuC/03iI+tjCRkyWgxttUjXdhFrEkGOBv65xNnyFQlxCPd1HFGFZ+uOXg= 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=oc2a49Dv; 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 85A2D33D; Sat, 4 May 2024 16:17:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1714832273; bh=w6bn/4no8NMVEJqPP561BcxXipVz/9y/dItL/1UBPSY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oc2a49DvYCMivQW8QKuerCPDE3NB3M4O9gQMO9h7ew1S3EyQGPeuVqDZMxOQ0Rhx8 noPhHVWfaI4WgcUwRiPdTUdxX6QxUwk259ygX79+BNPafprI95tRigE5Hftkcr53OA fLFvCGMtvo6Bbhyh2FDfgLBjJcV+gwxbyscJXnXg= Date: Sat, 4 May 2024 17:18:45 +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: <20240504141845.GC24548@pendragon.ideasonboard.com> 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=utf-8 Content-Disposition: inline In-Reply-To: On Thu, May 02, 2024 at 04:24:04PM +0000, Sakari Ailus wrote: > 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. I don't really see where the penalty is. What's the urgency to switch from calling v4l2_async_nf_unregister() and v4l2_async_nf_cleanup() to a helper that we know goes in the wrong direction ? > 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. There's already a .release() callback that can be used, and some drivers use it. > A similar situation exists with clk_unprepare() and clk_disable(). -- Regards, Laurent Pinchart