All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
To: linux-media@vger.kernel.org, dafna.hirschfeld@collabora.com,
	helen.koike@collabora.com, ezequiel@collabora.com,
	hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com,
	mchehab@kernel.org, laurent.pinchart@ideasonboard.com
Subject: [PATCH 2/5] media: vimc: handle error in vimc_add_subdevs
Date: Sat, 28 Mar 2020 08:52:51 +0100	[thread overview]
Message-ID: <20200328075254.4616-3-dafna.hirschfeld@collabora.com> (raw)
In-Reply-To: <20200328075254.4616-1-dafna.hirschfeld@collabora.com>

In case the 'add' callback of an entity fails,
then all other entities should unregister and released.
This should be done inside vimc_add_subdevs so that
the function handles its own failure.

In order to call vimc_unregister_subdevs and vimc_release_subdevs from
vimc_add_subdevs, the order of the function should change.

Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
---
 drivers/media/platform/vimc/vimc-core.c | 42 +++++++++++++------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/vimc/vimc-core.c b/drivers/media/platform/vimc/vimc-core.c
index 1f8498837646..dab01cbc31d2 100644
--- a/drivers/media/platform/vimc/vimc-core.c
+++ b/drivers/media/platform/vimc/vimc-core.c
@@ -160,24 +160,6 @@ static int vimc_create_links(struct vimc_device *vimc)
 	return ret;
 }
 
-static int vimc_add_subdevs(struct vimc_device *vimc)
-{
-	unsigned int i;
-
-	for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
-		dev_dbg(vimc->mdev.dev, "new entity for %s\n",
-			vimc->pipe_cfg->ents[i].name);
-		vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
-					vimc->pipe_cfg->ents[i].name);
-		if (!vimc->ent_devs[i]) {
-			dev_err(vimc->mdev.dev, "add new entity for %s\n",
-				vimc->pipe_cfg->ents[i].name);
-			return -EINVAL;
-		}
-	}
-	return 0;
-}
-
 static void vimc_release_subdevs(struct vimc_device *vimc)
 {
 	unsigned int i;
@@ -196,6 +178,26 @@ static void vimc_unregister_subdevs(struct vimc_device *vimc)
 			vimc->pipe_cfg->ents[i].unregister(vimc->ent_devs[i]);
 }
 
+static int vimc_add_subdevs(struct vimc_device *vimc)
+{
+	unsigned int i;
+
+	for (i = 0; i < vimc->pipe_cfg->num_ents; i++) {
+		dev_dbg(vimc->mdev.dev, "new entity for %s\n",
+			vimc->pipe_cfg->ents[i].name);
+		vimc->ent_devs[i] = vimc->pipe_cfg->ents[i].add(vimc,
+					vimc->pipe_cfg->ents[i].name);
+		if (!vimc->ent_devs[i]) {
+			dev_err(vimc->mdev.dev, "add new entity for %s\n",
+				vimc->pipe_cfg->ents[i].name);
+			vimc_unregister_subdevs(vimc);
+			vimc_release_subdevs(vimc);
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
 static void vimc_v4l2_dev_release(struct v4l2_device *v4l2_dev)
 {
 	struct vimc_device *vimc =
@@ -229,8 +231,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
 	/* Invoke entity config hooks to initialize and register subdevs */
 	ret = vimc_add_subdevs(vimc);
 	if (ret)
-		/* remove sundevs that got added */
-		goto err_rm_subdevs;
+		goto err_free_ent_devs;
 
 	/* Initialize links */
 	ret = vimc_create_links(vimc);
@@ -261,6 +262,7 @@ static int vimc_register_devices(struct vimc_device *vimc)
 err_rm_subdevs:
 	vimc_unregister_subdevs(vimc);
 	vimc_release_subdevs(vimc);
+err_free_ent_devs:
 	kfree(vimc->ent_devs);
 err_v4l2_unregister:
 	v4l2_device_unregister(&vimc->v4l2_dev);
-- 
2.17.1


  parent reply	other threads:[~2020-03-28  7:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-28  7:52 [PATCH 0/5] media: vimc: various fixes Dafna Hirschfeld
2020-03-28  7:52 ` [PATCH 1/5] media: vimc: remove the function vimc_unregister Dafna Hirschfeld
2020-03-28  7:52 ` Dafna Hirschfeld [this message]
2020-03-28  7:52 ` [PATCH 3/5] media: vimc: keep the error value when adding an entity fails Dafna Hirschfeld
2020-03-28  7:52 ` [PATCH 4/5] media: vimc: fix issues in documentation in vimc-common.h Dafna Hirschfeld
2020-03-28  7:52 ` [PATCH 5/5] media: vimc: add vimc_ent_type struct for the callbacks of entities Dafna Hirschfeld
2020-03-30 12:10   ` Hans Verkuil
2020-03-30 12:11     ` Hans Verkuil
2020-03-30 15:57     ` 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=20200328075254.4616-3-dafna.hirschfeld@collabora.com \
    --to=dafna.hirschfeld@collabora.com \
    --cc=dafna3@gmail.com \
    --cc=ezequiel@collabora.com \
    --cc=helen.koike@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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.