All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org,
	Dafna Hirschfeld <dafna@fastmail.com>,
	Heiko Stuebner <heiko@sntech.de>,
	Helen Koike <helen.koike@collabora.com>,
	Paul Elder <paul.elder@ideasonboard.com>
Subject: [PATCH v3 01/46] media: v4l2-async: Add notifier operation to destroy asd instances
Date: Mon, 11 Jul 2022 15:42:03 +0300	[thread overview]
Message-ID: <20220711124248.2683-2-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20220711124248.2683-1-laurent.pinchart@ideasonboard.com>

Drivers typically extend the v4l2_async_subdev structure by embedding it
in a driver-specific structure, to store per-subdev custom data. The
v4l2_async_subdev instances are freed by the v4l2-async framework, which
makes this mechanism cumbersome to use safely when custom data needs
special treatment to be destroyed (such as freeing additional memory, or
releasing references to kernel objects).

To ease this, add a .destroy() operation to the
v4l2_async_notifier_operations structure. The operation is called right
before the v4l2_async_subdev is freed, giving drivers a chance to
destroy data if needed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/driver-api/media/v4l2-subdev.rst |  6 ++++++
 drivers/media/v4l2-core/v4l2-async.c           | 10 ++++++++++
 include/media/v4l2-async.h                     |  2 ++
 3 files changed, 18 insertions(+)

diff --git a/Documentation/driver-api/media/v4l2-subdev.rst b/Documentation/driver-api/media/v4l2-subdev.rst
index cf3b52bdbfb9..6f8d79926aa5 100644
--- a/Documentation/driver-api/media/v4l2-subdev.rst
+++ b/Documentation/driver-api/media/v4l2-subdev.rst
@@ -243,6 +243,12 @@ notifier callback is called. After all subdevices have been located the
 .complete() callback is called. When a subdevice is removed from the
 system the .unbind() method is called. All three callbacks are optional.
 
+Drivers can store any type of custom data in their driver-specific
+:c:type:`v4l2_async_subdev` wrapper. If any of that data requires special
+handling when the structure is freed, drivers must implement the ``.destroy()``
+notifier callback. The framework will call it right before freeing the
+:c:type:`v4l2_async_subdev`.
+
 Calling subdev operations
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index c6995718237a..735dede624b8 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -52,6 +52,15 @@ static int v4l2_async_nf_call_complete(struct v4l2_async_notifier *n)
 	return n->ops->complete(n);
 }
 
+static void v4l2_async_nf_call_destroy(struct v4l2_async_notifier *n,
+				       struct v4l2_async_subdev *asd)
+{
+	if (!n->ops || !n->ops->destroy)
+		return;
+
+	n->ops->destroy(asd);
+}
+
 static bool match_i2c(struct v4l2_async_notifier *notifier,
 		      struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
@@ -626,6 +635,7 @@ static void __v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
 		}
 
 		list_del(&asd->asd_list);
+		v4l2_async_nf_call_destroy(notifier, asd);
 		kfree(asd);
 	}
 }
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index 13ff3ad948f4..25eb1d138c06 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -81,6 +81,7 @@ struct v4l2_async_subdev {
  * @complete:	All subdevices have been probed successfully. The complete
  *		callback is only executed for the root notifier.
  * @unbind:	a subdevice is leaving
+ * @destroy:	the asd is about to be freed
  */
 struct v4l2_async_notifier_operations {
 	int (*bound)(struct v4l2_async_notifier *notifier,
@@ -90,6 +91,7 @@ struct v4l2_async_notifier_operations {
 	void (*unbind)(struct v4l2_async_notifier *notifier,
 		       struct v4l2_subdev *subdev,
 		       struct v4l2_async_subdev *asd);
+	void (*destroy)(struct v4l2_async_subdev *asd);
 };
 
 /**
-- 
Regards,

Laurent Pinchart


WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org,
	Dafna Hirschfeld <dafna@fastmail.com>,
	Heiko Stuebner <heiko@sntech.de>,
	Helen Koike <helen.koike@collabora.com>,
	Paul Elder <paul.elder@ideasonboard.com>
Subject: [PATCH v3 01/46] media: v4l2-async: Add notifier operation to destroy asd instances
Date: Mon, 11 Jul 2022 15:42:03 +0300	[thread overview]
Message-ID: <20220711124248.2683-2-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20220711124248.2683-1-laurent.pinchart@ideasonboard.com>

Drivers typically extend the v4l2_async_subdev structure by embedding it
in a driver-specific structure, to store per-subdev custom data. The
v4l2_async_subdev instances are freed by the v4l2-async framework, which
makes this mechanism cumbersome to use safely when custom data needs
special treatment to be destroyed (such as freeing additional memory, or
releasing references to kernel objects).

To ease this, add a .destroy() operation to the
v4l2_async_notifier_operations structure. The operation is called right
before the v4l2_async_subdev is freed, giving drivers a chance to
destroy data if needed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/driver-api/media/v4l2-subdev.rst |  6 ++++++
 drivers/media/v4l2-core/v4l2-async.c           | 10 ++++++++++
 include/media/v4l2-async.h                     |  2 ++
 3 files changed, 18 insertions(+)

diff --git a/Documentation/driver-api/media/v4l2-subdev.rst b/Documentation/driver-api/media/v4l2-subdev.rst
index cf3b52bdbfb9..6f8d79926aa5 100644
--- a/Documentation/driver-api/media/v4l2-subdev.rst
+++ b/Documentation/driver-api/media/v4l2-subdev.rst
@@ -243,6 +243,12 @@ notifier callback is called. After all subdevices have been located the
 .complete() callback is called. When a subdevice is removed from the
 system the .unbind() method is called. All three callbacks are optional.
 
+Drivers can store any type of custom data in their driver-specific
+:c:type:`v4l2_async_subdev` wrapper. If any of that data requires special
+handling when the structure is freed, drivers must implement the ``.destroy()``
+notifier callback. The framework will call it right before freeing the
+:c:type:`v4l2_async_subdev`.
+
 Calling subdev operations
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index c6995718237a..735dede624b8 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -52,6 +52,15 @@ static int v4l2_async_nf_call_complete(struct v4l2_async_notifier *n)
 	return n->ops->complete(n);
 }
 
+static void v4l2_async_nf_call_destroy(struct v4l2_async_notifier *n,
+				       struct v4l2_async_subdev *asd)
+{
+	if (!n->ops || !n->ops->destroy)
+		return;
+
+	n->ops->destroy(asd);
+}
+
 static bool match_i2c(struct v4l2_async_notifier *notifier,
 		      struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
 {
@@ -626,6 +635,7 @@ static void __v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
 		}
 
 		list_del(&asd->asd_list);
+		v4l2_async_nf_call_destroy(notifier, asd);
 		kfree(asd);
 	}
 }
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index 13ff3ad948f4..25eb1d138c06 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -81,6 +81,7 @@ struct v4l2_async_subdev {
  * @complete:	All subdevices have been probed successfully. The complete
  *		callback is only executed for the root notifier.
  * @unbind:	a subdevice is leaving
+ * @destroy:	the asd is about to be freed
  */
 struct v4l2_async_notifier_operations {
 	int (*bound)(struct v4l2_async_notifier *notifier,
@@ -90,6 +91,7 @@ struct v4l2_async_notifier_operations {
 	void (*unbind)(struct v4l2_async_notifier *notifier,
 		       struct v4l2_subdev *subdev,
 		       struct v4l2_async_subdev *asd);
+	void (*destroy)(struct v4l2_async_subdev *asd);
 };
 
 /**
-- 
Regards,

Laurent Pinchart


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  reply	other threads:[~2022-07-11 12:43 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11 12:42 [PATCH v3 00/46] media: rkisp1: Cleanups to prepare for i.MX8MP support Laurent Pinchart
2022-07-11 12:42 ` Laurent Pinchart
2022-07-11 12:42 ` Laurent Pinchart [this message]
2022-07-11 12:42   ` [PATCH v3 01/46] media: v4l2-async: Add notifier operation to destroy asd instances Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 02/46] media: mc-entity: Rename media_entity_remote_pad() to media_pad_remote_pad_first() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-15 14:41   ` [PATCH v3.1 " Laurent Pinchart
2022-07-15 14:41     ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 03/46] media: mc-entity: Add a new helper function to get a remote pad Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 04/46] media: mc-entity: Add a new helper function to get a remote pad for a pad Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 05/46] media: rkisp1: Enable compilation on ARCH_MXC Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 06/46] media: rkisp1: Disable runtime PM in probe error path Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 07/46] media: rkisp1: Read the ID register at probe time instead of streamon Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 08/46] media: rkisp1: Rename rkisp1_match_data to rkisp1_info Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 09/46] media: rkisp1: Save info pointer in rkisp1_device Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 10/46] media: rkisp1: Access ISP version from info pointer Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 11/46] media: rkisp1: Make rkisp1_isp_mbus_info common Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 12/46] media: rkisp1: cap: Print debug message on failed link validation Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 13/46] media: rkisp1: Move sensor .s_stream() call to ISP Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 14/46] media: rkisp1: Reject sensors without pixel rate control at bound time Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 15/46] media: rkisp1: Create link from sensor to ISP at notifier " Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 16/46] media: rkisp1: Create internal links at probe time Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 17/46] media: rkisp1: Rename rkisp1_subdev_notifier() to rkisp1_subdev_notifier_register() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 18/46] media: rkisp1: Fix sensor source pad retrieval at bound time Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 19/46] media: rkisp1: Split CSI handling to separate file Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 20/46] media: rkisp1: isp: Start CSI-2 receiver before ISP Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 21/46] media: rkisp1: csi: Handle CSI-2 RX configuration fully in rkisp1-csi.c Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-16 19:01   ` Laurent Pinchart
2022-07-16 19:01     ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 22/46] media: rkisp1: csi: Rename CSI functions with a common rkisp1_csi prefix Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 23/46] media: rkisp1: csi: Move start delay to rkisp1_csi_start() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 24/46] media: rkisp1: csi: Pass sensor pointer to rkisp1_csi_config() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 25/46] media: rkisp1: csi: Constify argument to rkisp1_csi_start() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 26/46] media: rkisp1: isp: Don't initialize ret to 0 in rkisp1_isp_s_stream() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 27/46] media: rkisp1: isp: Pass mbus type and flags to rkisp1_config_cif() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 28/46] media: rkisp1: isp: Rename rkisp1_device.active_sensor to source Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 29/46] media: rkisp1: isp: Add container_of wrapper to cast subdev to rkisp1_isp Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 30/46] media: rkisp1: isp: Add rkisp1_device backpointer " Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 31/46] media: rkisp1: isp: Pass rkisp1_isp pointer to internal ISP functions Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 32/46] media: rkisp1: isp: Move input configuration to rkisp1_config_isp() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 33/46] media: rkisp1: isp: Merge ISP_ACQ_PROP configuration in single variable Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 34/46] media: rkisp1: isp: Initialize some variables at declaration time Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 35/46] media: rkisp1: isp: Fix whitespace issues Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 36/46] media: rkisp1: isp: Constify various local variables Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 37/46] media: rkisp1: isp: Rename rkisp1_get_remote_source() Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 38/46] media: rkisp1: isp: Disallow multiple active sources Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-12 18:40   ` Dafna Hirschfeld
2022-07-12 18:40     ` Dafna Hirschfeld
2022-07-12 19:18     ` Laurent Pinchart
2022-07-12 19:18       ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 39/46] media: rkisp1: csi: Implement a V4L2 subdev for the CSI receiver Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-12 18:31   ` Dafna Hirschfeld
2022-07-12 18:31     ` Dafna Hirschfeld
2022-07-11 12:42 ` [PATCH v3 40/46] media: rkisp1: csi: Plumb the CSI RX subdev Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 41/46] media: rkisp1: Use fwnode_graph_for_each_endpoint Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 42/46] dt-bindings: media: rkisp1: Add port for parallel interface Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 43/46] media: rkisp1: Support the ISP parallel input Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 44/46] media: rkisp1: Add infrastructure to support ISP features Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 16:37   ` Michael Riesch
2022-07-11 16:37     ` Michael Riesch
2022-07-11 16:50     ` Laurent Pinchart
2022-07-11 16:50       ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 45/46] media: rkisp1: Make the internal CSI-2 receiver optional Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-11 12:42 ` [PATCH v3 46/46] media: rkisp1: debug: Add dump file in debugfs for MI main path registers Laurent Pinchart
2022-07-11 12:42   ` Laurent Pinchart
2022-07-12 18:42   ` Dafna Hirschfeld
2022-07-12 18:42     ` Dafna Hirschfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220711124248.2683-2-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dafna@fastmail.com \
    --cc=heiko@sntech.de \
    --cc=helen.koike@collabora.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=paul.elder@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.