From patchwork Wed Feb 16 13:00:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 543179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24957C433FE for ; Wed, 16 Feb 2022 13:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233590AbiBPNBo (ORCPT ); Wed, 16 Feb 2022 08:01:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233598AbiBPNBl (ORCPT ); Wed, 16 Feb 2022 08:01:41 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA4AF6257 for ; Wed, 16 Feb 2022 05:01:23 -0800 (PST) Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8720B1516; Wed, 16 Feb 2022 14:01:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1645016479; bh=YFkuZVujCbxSq0j6B4sRbhcEXlX5xB8J9H2B8/7GM2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+dSyXM7UcQPoXl+wpTuysbTng5T0hhGRvMR/ZedUBQ4xuO/246xohPH+amLpmr6c TS+bCCFSpNCUXwLtfmZXjf4otb8WeCzbYxVORBCpY1AlZvXLuBiPL2A6n2JUVzb85c zBAHnuZIXsPLMBgaSTwCPXOebYN85JVH0aPjC8gk= From: Tomi Valkeinen To: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com, Jacopo Mondi , Laurent Pinchart , niklas.soderlund+renesas@ragnatech.se, Mauro Carvalho Chehab , Hans Verkuil , Pratyush Yadav Cc: Tomi Valkeinen Subject: [PATCH v4 5/7] media: subdev: Add v4l2_subdev_lock_and_return_state() Date: Wed, 16 Feb 2022 15:00:47 +0200 Message-Id: <20220216130049.508664-6-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220216130049.508664-1-tomi.valkeinen@ideasonboard.com> References: <20220216130049.508664-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org All suitable subdev ops are now passed either the TRY or the ACTIVE state by the v4l2 core. However, other subdev drivers can still call the ops passing NULL as the state, implying the active case. For all current upstream drivers this doesn't matter, as they do not expect to get a valid state for ACTIVE case. But future drivers which support multiplexed streaming and routing will depend on getting a state for both active and try cases. For new drivers we can mandate that the pipelines where the drivers are used need to pass the state properly, or preferably, not call such subdev ops at all. However, if an existing subdev driver is changed to support multiplexed streams, the driver has to consider cases where its ops will be called with NULL state. The problem can easily be solved by using the v4l2_subdev_lock_and_return_state() helper, introduced here. Signed-off-by: Tomi Valkeinen --- include/media/v4l2-subdev.h | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 8d089a2dbd32..84c02488d53f 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1278,6 +1278,44 @@ void v4l2_subdev_lock_state(struct v4l2_subdev_state *state); */ void v4l2_subdev_unlock_state(struct v4l2_subdev_state *state); +/** + * v4l2_subdev_lock_and_return_state() - Gets locked try or active subdev state + * @sd: subdevice + * @state: subdevice state as passed to the subdev op + * + * Due to legacy reasons, when subdev drivers call ops in other subdevs they use + * NULL as the state parameter, as subdevs always used to have their active + * state stored privately. + * + * However, newer state-aware subdev drivers, which store their active state in + * a common place, subdev->active_state, expect to always get a proper state as + * a parameter. + * + * These state-aware drivers can use v4l2_subdev_lock_and_return_state() instead + * of v4l2_subdev_lock_state(). v4l2_subdev_lock_and_return_state() solves the + * issue by using subdev->active_state in case the passed state is NULL. + * + * This is a temporary helper function, and should be removed when we can ensure + * that all drivers pass proper state when calling other subdevs. + */ +static inline struct v4l2_subdev_state * +v4l2_subdev_lock_and_return_state(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state) +{ + if (state) + return state; + + dev_notice_once(sd->dev, + "The provided state is NULL. Adjusting to the subdev active state.\n" + "Please consider porting your driver to the new state management API.\n"); + + state = sd->active_state; + + v4l2_subdev_lock_state(state); + + return state; +} + #endif /* CONFIG_MEDIA_CONTROLLER */ /**