From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF619C43334 for ; Fri, 1 Jul 2022 11:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wZLWTy5l9+1d1inDYiDx1EBqENin6ovcX4qz9iRYaeA=; b=BjLAlFufXyWobW 2C8GTwAOPtvPhZFu3F8R+l6CcMpPRsG/YHm/CS2ttxClRpmOFiu+VhfjLi1xluy6QJK2xyXeksYI3 P8eez97lS9FpobfSlqTe2D2nYA8VmvxT/BMBic33RwXUfjvNtL2YeousPifUBecKdWP3jUmNB/XTu kwDUqfHYB3BEgDvcy2939yWf1Trilsh0yy0mtYwjJKRxEO5YU7K5odMchihcO+DERDfvgNoV/BnwH xUOQF6U9FHL42eiRCeK5pjvyxWuXX6gJeVwAmNF2jdFDKTDBA+U/4Ef/9aa0ruOzRfmR4uSHclFqP Se5wybJVdGSbOlcVuZnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7EqW-004MzO-01; Fri, 01 Jul 2022 11:30:00 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7EqS-004Mum-P8 for linux-rockchip@lists.infradead.org; Fri, 01 Jul 2022 11:29:58 +0000 Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4642C25C; Fri, 1 Jul 2022 13:29:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656674991; bh=XgcTw8PU6I3n9hYJoCLdk4qKokseuI1tXq5PoF/JwYo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W3pAjBPaZNtpFWgLpHMfsLPQChJxVa4r6yLfqY5WF7b9Ud5LDRvlRX3aDcflSr0JU LtZ0ppPCJRDcJMvdgxNfVK2Qf9t6a6hLk2buE1UwGv/cSKlgPHEpIJ8/vqtDhJ+8H5 0Bsz+fdCWxo46d2PBkw+gnmqldEehk/1b7VNxqtU= Date: Fri, 1 Jul 2022 14:29:30 +0300 From: Laurent Pinchart To: Dafna Hirschfeld Cc: Paul Elder , linux-media@vger.kernel.org, heiko@sntech.de, jeanmichel.hautbois@ideasonboard.com, jacopo@jmondi.org, djrscally@gmail.com, helen.koike@collabora.com, linux-rockchip@lists.infradead.org Subject: Re: [PATCH 17/55] media: rkisp1: Fix sensor source pad retrieval at bound time Message-ID: References: <20220614191127.3420492-1-paul.elder@ideasonboard.com> <20220614191127.3420492-18-paul.elder@ideasonboard.com> <20220701043641.bo3sgetazko3fwoi@guri> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220701043641.bo3sgetazko3fwoi@guri> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220701_042957_071143_7BD381C0 X-CRM114-Status: GOOD ( 25.34 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Hi Dafna, On Fri, Jul 01, 2022 at 07:36:41AM +0300, Dafna Hirschfeld wrote: > On 15.06.2022 04:10, Paul Elder wrote: > > From: Laurent Pinchart > > > > When a sensor is bound, its source pad is retrieved in the .bound() > > operation with a call to media_entity_get_fwnode_pad(). The function > > should be called with the source endpoint fwnode of the sensor, but is > > instead called with the sensor's device fwnode. > > > > Fix this, which involves storing a reference to the source endpoint > > fwnode in the rkisp1_sensor_async structure, and thus implementing the > > subdev notifier .destroy() operation to release the reference. > > > > Signed-off-by: Laurent Pinchart > > --- > > .../platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ > > .../platform/rockchip/rkisp1/rkisp1-dev.c | 28 ++++++++++++++++--- > > 2 files changed, 26 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > index ba11baf75fa9..60c5462e1746 100644 > > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h > > @@ -117,6 +117,7 @@ struct rkisp1_info { > > * > > * @asd: async_subdev variable for the sensor > > * @index: index of the sensor (counting sensor found in DT) > > + * @source_ep: fwnode for the sensor source endpoint > > * @lanes: number of lanes > > * @mbus_type: type of bus (currently only CSI2 is supported) > > * @mbus_flags: media bus (V4L2_MBUS_*) flags > > @@ -127,6 +128,7 @@ struct rkisp1_info { > > struct rkisp1_sensor_async { > > struct v4l2_async_subdev asd; > > unsigned int index; > > + struct fwnode_handle *source_ep; > > unsigned int lanes; > > enum v4l2_mbus_type mbus_type; > > unsigned int mbus_flags; > > diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > index 386c1c17aec2..0f3e45cdbf2a 100644 > > --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c > > @@ -138,7 +138,7 @@ static int rkisp1_subdev_notifier_bound(struct v4l2_async_notifier *notifier, > > phy_init(s_asd->dphy); > > > > /* Create the link to the sensor. */ > > - source_pad = media_entity_get_fwnode_pad(&sd->entity, sd->fwnode, > > + source_pad = media_entity_get_fwnode_pad(&sd->entity, s_asd->source_ep, > > MEDIA_PAD_FL_SOURCE); > > if (source_pad < 0) { > > dev_err(rkisp1->dev, "failed to find source pad for %s\n", > > @@ -170,10 +170,19 @@ static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier) > > return v4l2_device_register_subdev_nodes(&rkisp1->v4l2_dev); > > } > > > > +static void rkisp1_subdev_notifier_destroy(struct v4l2_async_subdev *asd) > > +{ > > + struct rkisp1_sensor_async *rk_asd = > > + container_of(asd, struct rkisp1_sensor_async, asd); > > + > > + fwnode_handle_put(rk_asd->source_ep); > > +} > > + > > static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = { > > .bound = rkisp1_subdev_notifier_bound, > > .unbind = rkisp1_subdev_notifier_unbind, > > .complete = rkisp1_subdev_notifier_complete, > > + .destroy = rkisp1_subdev_notifier_destroy, > > }; > > > > static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1) > > @@ -190,6 +199,7 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1) > > .bus_type = V4L2_MBUS_CSI2_DPHY > > }; > > struct rkisp1_sensor_async *rk_asd; > > + struct fwnode_handle *source = NULL; > > struct fwnode_handle *ep; > > > > ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev), > > @@ -202,15 +212,24 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1) > > if (ret) > > goto err_parse; > > > > - rk_asd = v4l2_async_nf_add_fwnode_remote(ntf, ep, > > - struct > > - rkisp1_sensor_async); > > + source = fwnode_graph_get_remote_endpoint(ep); > > + if (!source) { > > + dev_err(rkisp1->dev, > > + "endpoint %pfw has no remote endpoint\n", > > + ep); > > + ret = -ENODEV; > > + goto err_parse; > > + } > > + > > + rk_asd = v4l2_async_nf_add_fwnode(ntf, source, > > + struct rkisp1_sensor_async); > > if (IS_ERR(rk_asd)) { > > ret = PTR_ERR(rk_asd); > > goto err_parse; > > } > > > > rk_asd->index = index++; > > + rk_asd->source_ep = source; > > here do 'source = NULL', see reason below > > > rk_asd->mbus_type = vep.bus_type; > > rk_asd->mbus_flags = vep.bus.mipi_csi2.flags; > > rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes; > > @@ -225,6 +244,7 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1) > > continue; > > err_parse: > > fwnode_handle_put(ep); > > + fwnode_handle_put(source); > > if v4l2_fwnode_endpoint_parse fails then here you put the source of previous iteration source is a variable local to the loop, and it's initialized to NULL in the declaration, so it will be reset to NULL at every iteration. > > v4l2_async_nf_cleanup(ntf); > > return ret; > > } -- Regards, Laurent Pinchart _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip