From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl
Subject: [PATCH 3/6] smiapp: Error handling cleanups and fixes
Date: Mon, 19 Aug 2019 15:47:25 +0300 [thread overview]
Message-ID: <20190819124728.10511-4-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20190819124728.10511-1-sakari.ailus@linux.intel.com>
Probe error handling cleanups and fixes:
- Move mutex initialisation at a later time for easier error handling.
- Issue destroy_mutex on the sensor mutex on probe failure and driver
remove,
- Remove smiapp_cleanup and add its contents in probe / remove on right
locations.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/i2c/smiapp/smiapp-core.c | 48 ++++++++++++++------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 9adf8e034e7d..c9d0416f9b03 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2579,16 +2579,6 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
return rval;
}
-static void smiapp_cleanup(struct smiapp_sensor *sensor)
-{
- struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-
- device_remove_file(&client->dev, &dev_attr_nvm);
- device_remove_file(&client->dev, &dev_attr_ident);
-
- smiapp_free_controls(sensor);
-}
-
static void smiapp_create_subdev(struct smiapp_sensor *sensor,
struct smiapp_subdev *ssd, const char *name,
unsigned short num_pads)
@@ -2862,7 +2852,6 @@ static int smiapp_probe(struct i2c_client *client)
return -ENOMEM;
sensor->hwcfg = hwcfg;
- mutex_init(&sensor->mutex);
sensor->src = &sensor->ssds[sensor->ssds_used];
v4l2_i2c_subdev_init(&sensor->src->sd, client, &smiapp_ops);
@@ -2922,9 +2911,11 @@ static int smiapp_probe(struct i2c_client *client)
if (IS_ERR(sensor->xshutdown))
return PTR_ERR(sensor->xshutdown);
+ mutex_init(&sensor->mutex);
+
rval = smiapp_power_on(&client->dev);
if (rval < 0)
- return rval;
+ goto out_mutex_destroy;
rval = smiapp_identify_module(sensor);
if (rval) {
@@ -3011,13 +3002,13 @@ static int smiapp_probe(struct i2c_client *client)
sensor->hwcfg->nvm_size, GFP_KERNEL);
if (sensor->nvm == NULL) {
rval = -ENOMEM;
- goto out_cleanup;
+ goto out_remove_ident_attr;
}
if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
dev_err(&client->dev, "sysfs nvm entry failed\n");
rval = -EBUSY;
- goto out_cleanup;
+ goto out_remove_ident_attr;
}
}
@@ -3067,22 +3058,22 @@ static int smiapp_probe(struct i2c_client *client)
rval = smiapp_init_controls(sensor);
if (rval < 0)
- goto out_cleanup;
+ goto out_free_controls;
rval = smiapp_call_quirk(sensor, init);
if (rval)
- goto out_cleanup;
+ goto out_free_controls;
rval = smiapp_get_mbus_formats(sensor);
if (rval) {
rval = -ENODEV;
- goto out_cleanup;
+ goto out_free_controls;
}
rval = smiapp_init_late_controls(sensor);
if (rval) {
rval = -ENODEV;
- goto out_cleanup;
+ goto out_free_controls;
}
mutex_lock(&sensor->mutex);
@@ -3090,7 +3081,7 @@ static int smiapp_probe(struct i2c_client *client)
mutex_unlock(&sensor->mutex);
if (rval) {
dev_err(&client->dev, "update mode failed\n");
- goto out_cleanup;
+ goto out_free_controls;
}
sensor->streaming = false;
@@ -3117,12 +3108,19 @@ static int smiapp_probe(struct i2c_client *client)
out_media_entity_cleanup:
media_entity_cleanup(&sensor->src->sd.entity);
-out_cleanup:
- smiapp_cleanup(sensor);
+out_remove_ident_attr:
+ device_remove_file(&client->dev, &dev_attr_ident);
+
+out_free_controls:
+ device_remove_file(&client->dev, &dev_attr_nvm);
+ smiapp_free_controls(sensor);
out_power_off:
smiapp_power_off(&client->dev);
+out_mutex_destroy:
+ mutex_destroy(&sensor->mutex);
+
return rval;
}
@@ -3143,7 +3141,13 @@ static int smiapp_remove(struct i2c_client *client)
v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
media_entity_cleanup(&sensor->ssds[i].sd.entity);
}
- smiapp_cleanup(sensor);
+
+ device_remove_file(&client->dev, &dev_attr_ident);
+ device_remove_file(&client->dev, &dev_attr_nvm);
+
+ smiapp_free_controls(sensor);
+
+ mutex_destroy(&sensor->mutex);
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2019-08-19 12:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 12:47 [PATCH 0/6] Provide a serialisation mechanism for subdev ops Sakari Ailus
2019-08-19 12:47 ` [PATCH 1/6] v4l: subdev: Set sd->devnode before registering the subdev Sakari Ailus
2019-09-12 12:40 ` Hans Verkuil
2019-08-19 12:47 ` [PATCH 2/6] v4l: subdev: Provide a locking scheme for subdev operations Sakari Ailus
2019-09-12 13:11 ` Hans Verkuil
2019-09-12 13:24 ` Sakari Ailus
2019-08-19 12:47 ` Sakari Ailus [this message]
2019-08-19 12:47 ` [PATCH 4/6] smiapp: Rely on V4L2 sub-device framework to do the locking Sakari Ailus
2019-08-19 12:47 ` [PATCH 5/6] smiapp: Remove the active field from sensor's struct Sakari Ailus
2019-08-19 12:47 ` [PATCH 6/6] smiapp: Avoid fall-through in switch Sakari Ailus
2019-09-12 13:17 ` Hans Verkuil
2019-09-13 6:50 ` Sakari Ailus
2019-09-13 6:47 ` [PATCH v2 " Sakari Ailus
2019-09-13 6:52 ` Hans Verkuil
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=20190819124728.10511-4-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.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