Commit d0ec32ca authored by Jyri Sarha's avatar Jyri Sarha

drm/tilcdc: Use devm_kzalloc() and devm_kcalloc() for private data

Use devm_kzalloc() and devm_kcalloc() for private data allocation at
driver load time.
Signed-off-by: default avatarJyri Sarha <jsarha@ti.com>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
parent d66284fb
...@@ -127,8 +127,6 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc) ...@@ -127,8 +127,6 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
of_node_put(crtc->port); of_node_put(crtc->port);
drm_crtc_cleanup(crtc); drm_crtc_cleanup(crtc);
drm_flip_work_cleanup(&tilcdc_crtc->unref_work); drm_flip_work_cleanup(&tilcdc_crtc->unref_work);
kfree(tilcdc_crtc);
} }
static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb) static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
...@@ -755,7 +753,7 @@ struct drm_crtc *tilcdc_crtc_create(struct drm_device *dev) ...@@ -755,7 +753,7 @@ struct drm_crtc *tilcdc_crtc_create(struct drm_device *dev)
struct drm_crtc *crtc; struct drm_crtc *crtc;
int ret; int ret;
tilcdc_crtc = kzalloc(sizeof(*tilcdc_crtc), GFP_KERNEL); tilcdc_crtc = devm_kzalloc(dev->dev, sizeof(*tilcdc_crtc), GFP_KERNEL);
if (!tilcdc_crtc) { if (!tilcdc_crtc) {
dev_err(dev->dev, "allocation failed\n"); dev_err(dev->dev, "allocation failed\n");
return NULL; return NULL;
......
...@@ -143,9 +143,6 @@ static int tilcdc_unload(struct drm_device *dev) ...@@ -143,9 +143,6 @@ static int tilcdc_unload(struct drm_device *dev)
pm_runtime_disable(dev->dev); pm_runtime_disable(dev->dev);
kfree(priv->saved_register);
kfree(priv);
return 0; return 0;
} }
...@@ -161,13 +158,12 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags) ...@@ -161,13 +158,12 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
u32 bpp = 0; u32 bpp = 0;
int ret; int ret;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev->dev, sizeof(*priv), GFP_KERNEL);
if (priv) if (priv)
priv->saved_register = kcalloc(tilcdc_num_regs(), priv->saved_register =
sizeof(*priv->saved_register), devm_kcalloc(dev->dev, tilcdc_num_regs(),
GFP_KERNEL); sizeof(*priv->saved_register), GFP_KERNEL);
if (!priv || !priv->saved_register) { if (!priv || !priv->saved_register) {
kfree(priv);
dev_err(dev->dev, "failed to allocate private data\n"); dev_err(dev->dev, "failed to allocate private data\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -180,7 +176,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags) ...@@ -180,7 +176,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
priv->wq = alloc_ordered_workqueue("tilcdc", 0); priv->wq = alloc_ordered_workqueue("tilcdc", 0);
if (!priv->wq) { if (!priv->wq) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_free_priv; goto fail_unset_priv;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -346,10 +342,9 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags) ...@@ -346,10 +342,9 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
flush_workqueue(priv->wq); flush_workqueue(priv->wq);
destroy_workqueue(priv->wq); destroy_workqueue(priv->wq);
fail_free_priv: fail_unset_priv:
dev->dev_private = NULL; dev->dev_private = NULL;
kfree(priv->saved_register);
kfree(priv);
return ret; return ret;
} }
......
...@@ -45,14 +45,6 @@ struct panel_encoder { ...@@ -45,14 +45,6 @@ struct panel_encoder {
}; };
#define to_panel_encoder(x) container_of(x, struct panel_encoder, base) #define to_panel_encoder(x) container_of(x, struct panel_encoder, base)
static void panel_encoder_destroy(struct drm_encoder *encoder)
{
struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
drm_encoder_cleanup(encoder);
kfree(panel_encoder);
}
static void panel_encoder_dpms(struct drm_encoder *encoder, int mode) static void panel_encoder_dpms(struct drm_encoder *encoder, int mode)
{ {
struct panel_encoder *panel_encoder = to_panel_encoder(encoder); struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
...@@ -90,7 +82,7 @@ static void panel_encoder_mode_set(struct drm_encoder *encoder, ...@@ -90,7 +82,7 @@ static void panel_encoder_mode_set(struct drm_encoder *encoder,
} }
static const struct drm_encoder_funcs panel_encoder_funcs = { static const struct drm_encoder_funcs panel_encoder_funcs = {
.destroy = panel_encoder_destroy, .destroy = drm_encoder_cleanup,
}; };
static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = { static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = {
...@@ -107,7 +99,8 @@ static struct drm_encoder *panel_encoder_create(struct drm_device *dev, ...@@ -107,7 +99,8 @@ static struct drm_encoder *panel_encoder_create(struct drm_device *dev,
struct drm_encoder *encoder; struct drm_encoder *encoder;
int ret; int ret;
panel_encoder = kzalloc(sizeof(*panel_encoder), GFP_KERNEL); panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder),
GFP_KERNEL);
if (!panel_encoder) { if (!panel_encoder) {
dev_err(dev->dev, "allocation failed\n"); dev_err(dev->dev, "allocation failed\n");
return NULL; return NULL;
...@@ -128,7 +121,7 @@ static struct drm_encoder *panel_encoder_create(struct drm_device *dev, ...@@ -128,7 +121,7 @@ static struct drm_encoder *panel_encoder_create(struct drm_device *dev,
return encoder; return encoder;
fail: fail:
panel_encoder_destroy(encoder); drm_encoder_cleanup(encoder);
return NULL; return NULL;
} }
...@@ -147,10 +140,8 @@ struct panel_connector { ...@@ -147,10 +140,8 @@ struct panel_connector {
static void panel_connector_destroy(struct drm_connector *connector) static void panel_connector_destroy(struct drm_connector *connector)
{ {
struct panel_connector *panel_connector = to_panel_connector(connector);
drm_connector_unregister(connector); drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(panel_connector);
} }
static enum drm_connector_status panel_connector_detect( static enum drm_connector_status panel_connector_detect(
...@@ -223,7 +214,8 @@ static struct drm_connector *panel_connector_create(struct drm_device *dev, ...@@ -223,7 +214,8 @@ static struct drm_connector *panel_connector_create(struct drm_device *dev,
struct drm_connector *connector; struct drm_connector *connector;
int ret; int ret;
panel_connector = kzalloc(sizeof(*panel_connector), GFP_KERNEL); panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector),
GFP_KERNEL);
if (!panel_connector) { if (!panel_connector) {
dev_err(dev->dev, "allocation failed\n"); dev_err(dev->dev, "allocation failed\n");
return NULL; return NULL;
......
...@@ -54,14 +54,6 @@ struct tfp410_encoder { ...@@ -54,14 +54,6 @@ struct tfp410_encoder {
}; };
#define to_tfp410_encoder(x) container_of(x, struct tfp410_encoder, base) #define to_tfp410_encoder(x) container_of(x, struct tfp410_encoder, base)
static void tfp410_encoder_destroy(struct drm_encoder *encoder)
{
struct tfp410_encoder *tfp410_encoder = to_tfp410_encoder(encoder);
drm_encoder_cleanup(encoder);
kfree(tfp410_encoder);
}
static void tfp410_encoder_dpms(struct drm_encoder *encoder, int mode) static void tfp410_encoder_dpms(struct drm_encoder *encoder, int mode)
{ {
struct tfp410_encoder *tfp410_encoder = to_tfp410_encoder(encoder); struct tfp410_encoder *tfp410_encoder = to_tfp410_encoder(encoder);
...@@ -99,7 +91,7 @@ static void tfp410_encoder_mode_set(struct drm_encoder *encoder, ...@@ -99,7 +91,7 @@ static void tfp410_encoder_mode_set(struct drm_encoder *encoder,
} }
static const struct drm_encoder_funcs tfp410_encoder_funcs = { static const struct drm_encoder_funcs tfp410_encoder_funcs = {
.destroy = tfp410_encoder_destroy, .destroy = drm_encoder_cleanup,
}; };
static const struct drm_encoder_helper_funcs tfp410_encoder_helper_funcs = { static const struct drm_encoder_helper_funcs tfp410_encoder_helper_funcs = {
...@@ -116,7 +108,8 @@ static struct drm_encoder *tfp410_encoder_create(struct drm_device *dev, ...@@ -116,7 +108,8 @@ static struct drm_encoder *tfp410_encoder_create(struct drm_device *dev,
struct drm_encoder *encoder; struct drm_encoder *encoder;
int ret; int ret;
tfp410_encoder = kzalloc(sizeof(*tfp410_encoder), GFP_KERNEL); tfp410_encoder = devm_kzalloc(dev->dev, sizeof(*tfp410_encoder),
GFP_KERNEL);
if (!tfp410_encoder) { if (!tfp410_encoder) {
dev_err(dev->dev, "allocation failed\n"); dev_err(dev->dev, "allocation failed\n");
return NULL; return NULL;
...@@ -138,7 +131,7 @@ static struct drm_encoder *tfp410_encoder_create(struct drm_device *dev, ...@@ -138,7 +131,7 @@ static struct drm_encoder *tfp410_encoder_create(struct drm_device *dev,
return encoder; return encoder;
fail: fail:
tfp410_encoder_destroy(encoder); drm_encoder_cleanup(encoder);
return NULL; return NULL;
} }
...@@ -157,10 +150,8 @@ struct tfp410_connector { ...@@ -157,10 +150,8 @@ struct tfp410_connector {
static void tfp410_connector_destroy(struct drm_connector *connector) static void tfp410_connector_destroy(struct drm_connector *connector)
{ {
struct tfp410_connector *tfp410_connector = to_tfp410_connector(connector);
drm_connector_unregister(connector); drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(tfp410_connector);
} }
static enum drm_connector_status tfp410_connector_detect( static enum drm_connector_status tfp410_connector_detect(
...@@ -228,7 +219,8 @@ static struct drm_connector *tfp410_connector_create(struct drm_device *dev, ...@@ -228,7 +219,8 @@ static struct drm_connector *tfp410_connector_create(struct drm_device *dev,
struct drm_connector *connector; struct drm_connector *connector;
int ret; int ret;
tfp410_connector = kzalloc(sizeof(*tfp410_connector), GFP_KERNEL); tfp410_connector = devm_kzalloc(dev->dev, sizeof(*tfp410_connector),
GFP_KERNEL);
if (!tfp410_connector) { if (!tfp410_connector) {
dev_err(dev->dev, "allocation failed\n"); dev_err(dev->dev, "allocation failed\n");
return NULL; return NULL;
...@@ -313,7 +305,7 @@ static int tfp410_probe(struct platform_device *pdev) ...@@ -313,7 +305,7 @@ static int tfp410_probe(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
} }
tfp410_mod = kzalloc(sizeof(*tfp410_mod), GFP_KERNEL); tfp410_mod = devm_kzalloc(&pdev->dev, sizeof(*tfp410_mod), GFP_KERNEL);
if (!tfp410_mod) if (!tfp410_mod)
return -ENOMEM; return -ENOMEM;
...@@ -366,7 +358,6 @@ static int tfp410_probe(struct platform_device *pdev) ...@@ -366,7 +358,6 @@ static int tfp410_probe(struct platform_device *pdev)
i2c_put_adapter(tfp410_mod->i2c); i2c_put_adapter(tfp410_mod->i2c);
fail: fail:
kfree(tfp410_mod);
tilcdc_module_cleanup(mod); tilcdc_module_cleanup(mod);
return ret; return ret;
} }
...@@ -380,7 +371,6 @@ static int tfp410_remove(struct platform_device *pdev) ...@@ -380,7 +371,6 @@ static int tfp410_remove(struct platform_device *pdev)
gpio_free(tfp410_mod->gpio); gpio_free(tfp410_mod->gpio);
tilcdc_module_cleanup(mod); tilcdc_module_cleanup(mod);
kfree(tfp410_mod);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment