Skip to content

Commit

Permalink
imx-drm: use supplied drm_device where possible
Browse files Browse the repository at this point in the history
The component helper provides us the drm_device which is being
registered.  Rather than having to reference a global in imx-drm-core,
use this to get the imxdrm device, and also use it to register the CRTC
against.

This means we never have CRTCs/encoders/connectors without the drivers
private data being accessible.

Remove the module owner field as well; this provides no protection
against the device being unbound.

Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King committed Feb 24, 2014
1 parent 1df8b53 commit 32266b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
34 changes: 5 additions & 29 deletions drivers/staging/imx-drm/imx-drm-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct imx_drm_crtc {
struct imx_drm_device *imxdrm;
int pipe;
struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
struct module *owner;
struct crtc_cookie cookie;
int mux_id;
};
Expand All @@ -74,7 +73,6 @@ static int legacyfb_depth = 16;
module_param(legacyfb_depth, int, 0444);

static void imx_drm_device_put(void);
static struct imx_drm_device *__imx_drm_device(void);

int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
{
Expand Down Expand Up @@ -114,7 +112,7 @@ static int imx_drm_driver_unload(struct drm_device *drm)

struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc)
{
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_device *imxdrm = crtc->dev->dev_private;
unsigned i;

for (i = 0; i < MAX_CRTC; i++)
Expand Down Expand Up @@ -241,7 +239,6 @@ static struct drm_device *imx_drm_device_get(void)
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
struct imx_drm_connector *con;
struct imx_drm_crtc *crtc;

list_for_each_entry(enc, &imxdrm->encoder_list, list) {
if (!try_module_get(enc->owner)) {
Expand All @@ -259,19 +256,8 @@ static struct drm_device *imx_drm_device_get(void)
}
}

list_for_each_entry(crtc, &imxdrm->crtc_list, list) {
if (!try_module_get(crtc->owner)) {
dev_err(imxdrm->dev, "could not get module %s\n",
module_name(crtc->owner));
goto unwind_crtc;
}
}

return imxdrm->drm;

unwind_crtc:
list_for_each_entry_continue_reverse(crtc, &imxdrm->crtc_list, list)
module_put(crtc->owner);
unwind_con:
list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list)
module_put(con->owner);
Expand All @@ -290,13 +276,9 @@ static void imx_drm_device_put(void)
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
struct imx_drm_connector *con;
struct imx_drm_crtc *crtc;

mutex_lock(&imxdrm->mutex);

list_for_each_entry(crtc, &imxdrm->crtc_list, list)
module_put(crtc->owner);

list_for_each_entry(con, &imxdrm->connector_list, list)
module_put(con->owner);

Expand Down Expand Up @@ -536,12 +518,12 @@ static void imx_drm_update_possible_crtcs(void)
* The return value if !NULL is a cookie for the caller to pass to
* imx_drm_remove_crtc later.
*/
int imx_drm_add_crtc(struct drm_crtc *crtc,
int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
struct imx_drm_crtc **new_crtc,
const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
struct module *owner, void *cookie, int id)
void *cookie, int id)
{
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_device *imxdrm = drm->dev_private;
struct imx_drm_crtc *imx_drm_crtc;
int ret;

Expand Down Expand Up @@ -575,8 +557,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
imx_drm_crtc->crtc = crtc;
imx_drm_crtc->imxdrm = imxdrm;

imx_drm_crtc->owner = owner;

imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc;

*new_crtc = imx_drm_crtc;
Expand All @@ -588,11 +568,9 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
drm_crtc_helper_add(crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);

drm_crtc_init(imxdrm->drm, crtc,
drm_crtc_init(drm, crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);

drm_mode_group_reinit(imxdrm->drm);

imx_drm_update_possible_crtcs();

mutex_unlock(&imxdrm->mutex);
Expand Down Expand Up @@ -622,8 +600,6 @@ int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)

imxdrm->crtc[imx_drm_crtc->pipe] = NULL;

drm_mode_group_reinit(imxdrm->drm);

mutex_unlock(&imxdrm->mutex);

kfree(imx_drm_crtc);
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/imx-drm/imx-drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct imx_drm_crtc_helper_funcs {
const struct drm_crtc_funcs *crtc_funcs;
};

int imx_drm_add_crtc(struct drm_crtc *crtc,
int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
struct imx_drm_crtc **new_crtc,
const struct imx_drm_crtc_helper_funcs *imx_helper_funcs,
struct module *owner, void *cookie, int id);
void *cookie, int id);
int imx_drm_remove_crtc(struct imx_drm_crtc *);
int imx_drm_init_drm(struct platform_device *pdev,
int preferred_bpp);
Expand Down
9 changes: 5 additions & 4 deletions drivers/staging/imx-drm/ipuv3-crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static int ipu_get_resources(struct ipu_crtc *ipu_crtc,
}

static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
struct ipu_client_platformdata *pdata)
struct ipu_client_platformdata *pdata, struct drm_device *drm)
{
struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
int dp = -EINVAL;
Expand All @@ -350,9 +350,9 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
return ret;
}

ret = imx_drm_add_crtc(&ipu_crtc->base,
ret = imx_drm_add_crtc(drm, &ipu_crtc->base,
&ipu_crtc->imx_crtc,
&ipu_crtc_helper_funcs, THIS_MODULE,
&ipu_crtc_helper_funcs,
ipu_crtc->dev->parent->of_node, pdata->di);
if (ret) {
dev_err(ipu_crtc->dev, "adding crtc failed with %d.\n", ret);
Expand Down Expand Up @@ -404,6 +404,7 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
static int ipu_drm_bind(struct device *dev, struct device *master, void *data)
{
struct ipu_client_platformdata *pdata = dev->platform_data;
struct drm_device *drm = data;
struct ipu_crtc *ipu_crtc;
int ret;

Expand All @@ -413,7 +414,7 @@ static int ipu_drm_bind(struct device *dev, struct device *master, void *data)

ipu_crtc->dev = dev;

ret = ipu_crtc_init(ipu_crtc, pdata);
ret = ipu_crtc_init(ipu_crtc, pdata, drm);
if (ret)
return ret;

Expand Down

0 comments on commit 32266b4

Please sign in to comment.