Commit 70e176a5 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab
Browse files

[media] soc-camera: use devm_kzalloc in subdevice drivers



I2C drivers can use devm_kzalloc() too in their .probe() methods. Doing so
simplifies their clean up paths.

Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 25a34811
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -431,7 +431,6 @@ static int imx074_probe(struct i2c_client *client,
	struct imx074 *priv;
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
	int ret;

	if (!ssdd) {
		dev_err(&client->dev, "IMX074: missing platform data!\n");
@@ -444,7 +443,7 @@ static int imx074_probe(struct i2c_client *client,
		return -EIO;
	}

	priv = kzalloc(sizeof(struct imx074), GFP_KERNEL);
	priv = devm_kzalloc(&client->dev, sizeof(struct imx074), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

@@ -452,23 +451,15 @@ static int imx074_probe(struct i2c_client *client,

	priv->fmt	= &imx074_colour_fmts[0];

	ret = imx074_video_probe(client);
	if (ret < 0) {
		kfree(priv);
		return ret;
	}

	return ret;
	return imx074_video_probe(client);
}

static int imx074_remove(struct i2c_client *client)
{
	struct imx074 *priv = to_imx074(client);
	struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);

	if (ssdd->free_bus)
		ssdd->free_bus(ssdd);
	kfree(priv);

	return 0;
}
+4 −10
Original line number Diff line number Diff line
@@ -677,7 +677,7 @@ static int mt9m001_probe(struct i2c_client *client,
		return -EIO;
	}

	mt9m001 = kzalloc(sizeof(struct mt9m001), GFP_KERNEL);
	mt9m001 = devm_kzalloc(&client->dev, sizeof(struct mt9m001), GFP_KERNEL);
	if (!mt9m001)
		return -ENOMEM;

@@ -697,12 +697,9 @@ static int mt9m001_probe(struct i2c_client *client,
			&mt9m001_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
			V4L2_EXPOSURE_AUTO);
	mt9m001->subdev.ctrl_handler = &mt9m001->hdl;
	if (mt9m001->hdl.error) {
		int err = mt9m001->hdl.error;
	if (mt9m001->hdl.error)
		return mt9m001->hdl.error;

		kfree(mt9m001);
		return err;
	}
	v4l2_ctrl_auto_cluster(2, &mt9m001->autoexposure,
					V4L2_EXPOSURE_MANUAL, true);

@@ -714,10 +711,8 @@ static int mt9m001_probe(struct i2c_client *client,
	mt9m001->rect.height	= MT9M001_MAX_HEIGHT;

	ret = mt9m001_video_probe(ssdd, client);
	if (ret) {
	if (ret)
		v4l2_ctrl_handler_free(&mt9m001->hdl);
		kfree(mt9m001);
	}

	return ret;
}
@@ -730,7 +725,6 @@ static int mt9m001_remove(struct i2c_client *client)
	v4l2_device_unregister_subdev(&mt9m001->subdev);
	v4l2_ctrl_handler_free(&mt9m001->hdl);
	mt9m001_video_remove(ssdd);
	kfree(mt9m001);

	return 0;
}
+4 −11
Original line number Diff line number Diff line
@@ -971,7 +971,7 @@ static int mt9m111_probe(struct i2c_client *client,
		return -EIO;
	}

	mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL);
	mt9m111 = devm_kzalloc(&client->dev, sizeof(struct mt9m111), GFP_KERNEL);
	if (!mt9m111)
		return -ENOMEM;

@@ -989,12 +989,8 @@ static int mt9m111_probe(struct i2c_client *client,
			&mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
			V4L2_EXPOSURE_AUTO);
	mt9m111->subdev.ctrl_handler = &mt9m111->hdl;
	if (mt9m111->hdl.error) {
		int err = mt9m111->hdl.error;

		kfree(mt9m111);
		return err;
	}
	if (mt9m111->hdl.error)
		return mt9m111->hdl.error;

	/* Second stage probe - when a capture adapter is there */
	mt9m111->rect.left	= MT9M111_MIN_DARK_COLS;
@@ -1006,10 +1002,8 @@ static int mt9m111_probe(struct i2c_client *client,
	mutex_init(&mt9m111->power_lock);

	ret = mt9m111_video_probe(client);
	if (ret) {
	if (ret)
		v4l2_ctrl_handler_free(&mt9m111->hdl);
		kfree(mt9m111);
	}

	return ret;
}
@@ -1020,7 +1014,6 @@ static int mt9m111_remove(struct i2c_client *client)

	v4l2_device_unregister_subdev(&mt9m111->subdev);
	v4l2_ctrl_handler_free(&mt9m111->hdl);
	kfree(mt9m111);

	return 0;
}
+4 −10
Original line number Diff line number Diff line
@@ -773,7 +773,7 @@ static int mt9t031_probe(struct i2c_client *client,
		return -EIO;
	}

	mt9t031 = kzalloc(sizeof(struct mt9t031), GFP_KERNEL);
	mt9t031 = devm_kzalloc(&client->dev, sizeof(struct mt9t031), GFP_KERNEL);
	if (!mt9t031)
		return -ENOMEM;

@@ -797,12 +797,9 @@ static int mt9t031_probe(struct i2c_client *client,
			V4L2_CID_EXPOSURE, 1, 255, 1, 255);

	mt9t031->subdev.ctrl_handler = &mt9t031->hdl;
	if (mt9t031->hdl.error) {
		int err = mt9t031->hdl.error;
	if (mt9t031->hdl.error)
		return mt9t031->hdl.error;

		kfree(mt9t031);
		return err;
	}
	v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure,
				V4L2_EXPOSURE_MANUAL, true);

@@ -816,10 +813,8 @@ static int mt9t031_probe(struct i2c_client *client,
	mt9t031->yskip = 1;

	ret = mt9t031_video_probe(client);
	if (ret) {
	if (ret)
		v4l2_ctrl_handler_free(&mt9t031->hdl);
		kfree(mt9t031);
	}

	return ret;
}
@@ -830,7 +825,6 @@ static int mt9t031_remove(struct i2c_client *client)

	v4l2_device_unregister_subdev(&mt9t031->subdev);
	v4l2_ctrl_handler_free(&mt9t031->hdl);
	kfree(mt9t031);

	return 0;
}
+2 −7
Original line number Diff line number Diff line
@@ -1092,7 +1092,7 @@ static int mt9t112_probe(struct i2c_client *client,
		return -EINVAL;
	}

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

@@ -1101,10 +1101,8 @@ static int mt9t112_probe(struct i2c_client *client,
	v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);

	ret = mt9t112_camera_probe(client);
	if (ret) {
		kfree(priv);
	if (ret)
		return ret;
	}

	/* Cannot fail: using the default supported pixel code */
	mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8);
@@ -1114,9 +1112,6 @@ static int mt9t112_probe(struct i2c_client *client,

static int mt9t112_remove(struct i2c_client *client)
{
	struct mt9t112_priv *priv = to_mt9t112(client);

	kfree(priv);
	return 0;
}

Loading