From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-media@vger.kernel.org,
Hans Verkuil <hans.verkuil@cisco.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 4/6] [media] go7007: Use common error handling code in s2250_probe()
Date: Mon, 18 Sep 2017 15:57:21 +0200 [thread overview]
Message-ID: <c4d2e584-39ca-6e30-43ee-56088905149e@users.sourceforge.net> (raw)
In-Reply-To: <b36ece3f-0f31-9bb6-14ae-c4abf7cd23ee@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 18 Sep 2017 13:50:45 +0200
Adjust jump targets so that a bit of exception handling can be better
reused at the end of this function.
This refactoring might fix also an error situation where the
function "i2c_unregister_device" was not called after a software failure
was noticed by the data member "hdl.error".
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/usb/go7007/s2250-board.c | 37 +++++++++++++++++-----------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/drivers/media/usb/go7007/s2250-board.c b/drivers/media/usb/go7007/s2250-board.c
index 1fd4c09dd516..1bd9a7f2e7a3 100644
--- a/drivers/media/usb/go7007/s2250-board.c
+++ b/drivers/media/usb/go7007/s2250-board.c
@@ -510,6 +510,7 @@ static int s2250_probe(struct i2c_client *client,
u8 *data;
struct go7007 *go = i2c_get_adapdata(adapter);
struct go7007_usb *usb = go->hpi_context;
+ int code;
audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1);
if (!audio)
@@ -517,8 +518,8 @@ static int s2250_probe(struct i2c_client *client,
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state) {
- i2c_unregister_device(audio);
- return -ENOMEM;
+ code = -ENOMEM;
+ goto unregister_device;
}
sd = &state->sd;
@@ -538,11 +539,8 @@ static int s2250_probe(struct i2c_client *client,
V4L2_CID_HUE, -512, 511, 1, 0);
sd->ctrl_handler = &state->hdl;
if (state->hdl.error) {
- int err = state->hdl.error;
-
- v4l2_ctrl_handler_free(&state->hdl);
- kfree(state);
- return err;
+ code = state->hdl.error;
+ goto free_handler;
}
state->std = V4L2_STD_NTSC;
@@ -555,17 +553,13 @@ static int s2250_probe(struct i2c_client *client,
/* initialize the audio */
if (write_regs(audio, aud_regs) < 0) {
dev_err(&client->dev, "error initializing audio\n");
- goto fail;
+ goto e_io;
}
- if (write_regs(client, vid_regs) < 0) {
- dev_err(&client->dev, "error initializing decoder\n");
- goto fail;
- }
- if (write_regs_fp(client, vid_regs_fp) < 0) {
- dev_err(&client->dev, "error initializing decoder\n");
- goto fail;
- }
+ if (write_regs(client, vid_regs) < 0 ||
+ write_regs_fp(client, vid_regs_fp) < 0)
+ goto report_write_failure;
+
/* set default channel */
/* composite */
write_reg_fp(client, 0x20, 0x020 | 1);
@@ -602,11 +596,16 @@ static int s2250_probe(struct i2c_client *client,
v4l2_info(sd, "initialized successfully\n");
return 0;
-fail:
- i2c_unregister_device(audio);
+report_write_failure:
+ dev_err(&client->dev, "error initializing decoder\n");
+e_io:
+ code = -EIO;
+free_handler:
v4l2_ctrl_handler_free(&state->hdl);
kfree(state);
- return -EIO;
+unregister_device:
+ i2c_unregister_device(audio);
+ return code;
}
static int s2250_remove(struct i2c_client *client)
--
2.14.1
next prev parent reply other threads:[~2017-09-18 13:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-18 13:52 [PATCH 0/6] [media] Go7007: Adjustments for some function implementations SF Markus Elfring
2017-09-18 13:53 ` [PATCH 1/6] [media] go7007: Delete an error message for a failed memory allocation in go7007_load_encoder() SF Markus Elfring
2017-09-18 13:55 ` [PATCH 2/6] [media] go7007: Adjust 35 checks for null pointers SF Markus Elfring
2017-09-18 13:56 ` [PATCH 3/6] [media] go7007: Improve a size determination in four functions SF Markus Elfring
2017-09-18 13:57 ` SF Markus Elfring [this message]
2017-09-19 8:42 ` [PATCH 4/6] [media] go7007: Use common error handling code in s2250_probe() Dan Carpenter
2017-09-20 7:09 ` SF Markus Elfring
2017-09-20 9:12 ` Dan Carpenter
2017-09-18 13:58 ` [PATCH 5/6] [media] go7007: Use common error handling code in go7007_snd_init() SF Markus Elfring
2017-09-19 8:49 ` Dan Carpenter
2017-09-18 14:00 ` [PATCH 6/6] [media] go7007: Delete an unnecessary variable initialisation " SF Markus Elfring
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=c4d2e584-39ca-6e30-43ee-56088905149e@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=hans.verkuil@cisco.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).