/*
* Find out whether an async sub-device was set up already or
* whether it exists in a given notifier before @this_index.
+ * If @this_index < 0, search the notifier's entire @asd_list.
*/
static bool
v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier,
struct v4l2_async_subdev *asd,
- unsigned int this_index)
+ int this_index)
{
struct v4l2_async_subdev *asd_y;
- unsigned int j;
+ int j = 0;
lockdep_assert_held(&list_lock);
/* Check that an asd is not being added more than once. */
- if (notifier->subdevs) {
- for (j = 0; j < this_index; j++) {
- asd_y = notifier->subdevs[j];
- if (asd_equal(asd, asd_y))
- return true;
- }
- } else {
- j = 0;
- list_for_each_entry(asd_y, ¬ifier->asd_list, asd_list) {
- if (j++ >= this_index)
- break;
- if (asd_equal(asd, asd_y))
- return true;
- }
+ list_for_each_entry(asd_y, ¬ifier->asd_list, asd_list) {
+ if (this_index >= 0 && j++ >= this_index)
+ break;
+ if (asd_equal(asd, asd_y))
+ return true;
}
/* Check that an asd does not exist in other notifiers. */
static int v4l2_async_notifier_asd_valid(struct v4l2_async_notifier *notifier,
struct v4l2_async_subdev *asd,
- unsigned int this_index)
+ int this_index)
{
struct device *dev =
notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL;
static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
{
struct v4l2_async_subdev *asd;
- int ret;
- int i;
-
- if (notifier->num_subdevs > V4L2_MAX_SUBDEVS)
- return -EINVAL;
+ int ret, i = 0;
INIT_LIST_HEAD(¬ifier->waiting);
INIT_LIST_HEAD(¬ifier->done);
mutex_lock(&list_lock);
- if (notifier->subdevs) {
- for (i = 0; i < notifier->num_subdevs; i++) {
- asd = notifier->subdevs[i];
-
- ret = v4l2_async_notifier_asd_valid(notifier, asd, i);
- if (ret)
- goto err_unlock;
+ list_for_each_entry(asd, ¬ifier->asd_list, asd_list) {
+ ret = v4l2_async_notifier_asd_valid(notifier, asd, i++);
+ if (ret)
+ goto err_unlock;
- list_add_tail(&asd->list, ¬ifier->waiting);
- }
- } else {
- i = 0;
- list_for_each_entry(asd, ¬ifier->asd_list, asd_list) {
- ret = v4l2_async_notifier_asd_valid(notifier, asd, i++);
- if (ret)
- goto err_unlock;
-
- list_add_tail(&asd->list, ¬ifier->waiting);
- }
+ list_add_tail(&asd->list, ¬ifier->waiting);
}
ret = v4l2_async_notifier_try_all_subdevs(notifier);
static void __v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier)
{
struct v4l2_async_subdev *asd, *tmp;
- unsigned int i;
if (!notifier)
return;
- if (notifier->subdevs) {
- for (i = 0; i < notifier->num_subdevs; i++) {
- asd = notifier->subdevs[i];
-
- switch (asd->match_type) {
- case V4L2_ASYNC_MATCH_FWNODE:
- fwnode_handle_put(asd->match.fwnode);
- break;
- default:
- break;
- }
-
- kfree(asd);
+ list_for_each_entry_safe(asd, tmp, ¬ifier->asd_list, asd_list) {
+ switch (asd->match_type) {
+ case V4L2_ASYNC_MATCH_FWNODE:
+ fwnode_handle_put(asd->match.fwnode);
+ break;
+ default:
+ break;
}
- kvfree(notifier->subdevs);
- notifier->subdevs = NULL;
- } else {
- list_for_each_entry_safe(asd, tmp,
- ¬ifier->asd_list, asd_list) {
- switch (asd->match_type) {
- case V4L2_ASYNC_MATCH_FWNODE:
- fwnode_handle_put(asd->match.fwnode);
- break;
- default:
- break;
- }
-
- list_del(&asd->asd_list);
- kfree(asd);
- }
+ list_del(&asd->asd_list);
+ kfree(asd);
}
-
- notifier->num_subdevs = 0;
}
void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier)
mutex_lock(&list_lock);
- if (notifier->num_subdevs >= V4L2_MAX_SUBDEVS) {
- ret = -EINVAL;
- goto unlock;
- }
-
- /*
- * If caller uses this function, it cannot also allocate and
- * place asd's in the notifier->subdevs array.
- */
- if (WARN_ON(notifier->subdevs)) {
- ret = -EINVAL;
- goto unlock;
- }
-
- ret = v4l2_async_notifier_asd_valid(notifier, asd,
- notifier->num_subdevs);
+ ret = v4l2_async_notifier_asd_valid(notifier, asd, -1);
if (ret)
goto unlock;
list_add_tail(&asd->asd_list, ¬ifier->asd_list);
- notifier->num_subdevs++;
unlock:
mutex_unlock(&list_lock);
struct v4l2_subdev;
struct v4l2_async_notifier;
-/* A random max subdevice number, used to allocate an array on stack */
-#define V4L2_MAX_SUBDEVS 128U
-
/**
* enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
* in order to identify a match
* struct v4l2_async_notifier - v4l2_device notifier data
*
* @ops: notifier operations
- * @num_subdevs: number of subdevices used in the subdevs array
- * @subdevs: array of pointers to subdevice descriptors
* @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
* @sd: sub-device that registered the notifier, NULL otherwise
* @parent: parent notifier
- * @asd_list: master list of struct v4l2_async_subdev, replaces @subdevs
+ * @asd_list: master list of struct v4l2_async_subdev
* @waiting: list of struct v4l2_async_subdev, waiting for their drivers
* @done: list of struct v4l2_subdev, already probed
* @list: member in a global list of notifiers
*/
struct v4l2_async_notifier {
const struct v4l2_async_notifier_operations *ops;
- unsigned int num_subdevs;
- struct v4l2_async_subdev **subdevs;
struct v4l2_device *v4l2_dev;
struct v4l2_subdev *sd;
struct v4l2_async_notifier *parent;
* @notifier: pointer to &struct v4l2_async_notifier
* @asd: pointer to &struct v4l2_async_subdev
*
- * This can be used before registering a notifier to add an
- * asd to the notifiers @asd_list. If the caller uses this
- * method to compose an asd list, it must never allocate
- * or place asd's in the @subdevs array.
+ * Call this function before registering a notifier to link the
+ * provided asd to the notifiers master @asd_list.
*/
int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
struct v4l2_async_subdev *asd);
* the driver's async sub-device struct, i.e. both
* begin at the same memory address.
*
- * This can be used before registering a notifier to add a
- * fwnode-matched asd to the notifiers master asd_list. If the caller
- * uses this method to compose an asd list, it must never allocate
- * or place asd's in the @subdevs array.
+ * Allocate a fwnode-matched asd of size asd_struct_size, and add it
+ * to the notifiers @asd_list.
*/
struct v4l2_async_subdev *
v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
* This function may not be called on a registered notifier and may be called on
* a notifier only once.
*
- * Do not allocate the notifier's subdevs array, or change the notifier's
- * num_subdevs field. This is because this function uses
- * @v4l2_async_notifier_add_subdev to populate the notifier's asd_list,
- * which is in-place-of the subdevs array which must remain unallocated
- * and unused.
- *
* The &struct v4l2_fwnode_endpoint passed to the callback function
* @parse_endpoint is released once the function is finished. If there is a need
* to retain that configuration, the user needs to allocate memory for it.
* This function may not be called on a registered notifier and may be called on
* a notifier only once per port.
*
- * Do not allocate the notifier's subdevs array, or change the notifier's
- * num_subdevs field. This is because this function uses
- * @v4l2_async_notifier_add_subdev to populate the notifier's asd_list,
- * which is in-place-of the subdevs array which must remain unallocated
- * and unused.
- *
* The &struct v4l2_fwnode_endpoint passed to the callback function
* @parse_endpoint is released once the function is finished. If there is a need
* to retain that configuration, the user needs to allocate memory for it.