Re: [PATCH v3 02/14] media: mt9m111: prevent module removal while in use

From: Hans Verkuil
Date: Sun Aug 14 2016 - 05:09:43 EST


On 08/08/2016 09:30 PM, Robert Jarzmik wrote:
> The mt9m111 can be a removable module : the only case where the module
> should be kept loaded is while it is used, ie. while an active
> transation is ongoing on it.
>
> The notion of active transaction is mapped on the power state of the
> module : if powered on the removal is prohibited.

I don't really see the purpose of this patch: if this driver is loaded
by a platform driver (such as pxa_camera), then the module count should be
1 and it isn't possible to unload.

So you shouldn't need this patch. Am I missing something?

No other driver in drivers/media/i2c does something like this.

Regards,

Hans

>
> Signed-off-by: Robert Jarzmik <robert.jarzmik@xxxxxxx>
> ---
> drivers/media/i2c/soc_camera/mt9m111.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
> index a7efaa5964d1..ea5b5e709402 100644
> --- a/drivers/media/i2c/soc_camera/mt9m111.c
> +++ b/drivers/media/i2c/soc_camera/mt9m111.c
> @@ -780,23 +780,33 @@ static int mt9m111_power_on(struct mt9m111 *mt9m111)
> struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
> int ret;
>
> + if (!try_module_get(THIS_MODULE))
> + return -ENXIO;
> +
> ret = v4l2_clk_enable(mt9m111->clk);
> if (ret < 0)
> - return ret;
> + goto out_module_put;
>
> ret = mt9m111_resume(mt9m111);
> if (ret < 0) {
> dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret);
> - v4l2_clk_disable(mt9m111->clk);
> + goto out_clk_disable;
> }
>
> return ret;
> +
> +out_clk_disable:
> + v4l2_clk_disable(mt9m111->clk);
> +out_module_put:
> + module_put(THIS_MODULE);
> + return ret;
> }
>
> static void mt9m111_power_off(struct mt9m111 *mt9m111)
> {
> mt9m111_suspend(mt9m111);
> v4l2_clk_disable(mt9m111->clk);
> + module_put(THIS_MODULE);
> }
>
> static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
>