[PATCH 1/2] drm: omapdrm: Use sizeof(*var) instead of sizeof(type) for structures
Daniel Vetter
daniel at ffwll.ch
Tue Dec 13 21:12:12 UTC 2016
On Tue, Dec 13, 2016 at 05:21:42PM +0200, Laurent Pinchart wrote:
> By linking the sizeof to a variable type the code will be less prone to
> bugs due to future type changes of variables.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
Isn't there some cocci magic that does this for you?
-Daniel
> ---
> drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c | 2 +-
> drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c | 3 +--
> drivers/gpu/drm/omapdrm/omap_connector.c | 4 ++--
> drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 4 ++--
> drivers/gpu/drm/omapdrm/omap_encoder.c | 2 +-
> 5 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
> index dc026a843712..a2bb855a2851 100644
> --- a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
> +++ b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
> @@ -1253,7 +1253,7 @@ static int dsicm_probe(struct platform_device *pdev)
> dsicm_hw_reset(ddata);
>
> if (ddata->use_dsi_backlight) {
> - memset(&props, 0, sizeof(struct backlight_properties));
> + memset(&props, 0, sizeof(props));
> props.max_brightness = 255;
>
> props.type = BACKLIGHT_RAW;
> diff --git a/drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c b/drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c
> index 136d30484d02..bf626acae271 100644
> --- a/drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c
> +++ b/drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c
> @@ -119,8 +119,7 @@ static void __init omapdss_omapify_node(struct device_node *node)
>
> static void __init omapdss_add_to_list(struct device_node *node, bool root)
> {
> - struct dss_conv_node *n = kmalloc(sizeof(struct dss_conv_node),
> - GFP_KERNEL);
> + struct dss_conv_node *n = kmalloc(sizeof(*n), GFP_KERNEL);
> if (n) {
> n->node = node;
> n->root = root;
> diff --git a/drivers/gpu/drm/omapdrm/omap_connector.c b/drivers/gpu/drm/omapdrm/omap_connector.c
> index 2580e8673908..691cffebb76e 100644
> --- a/drivers/gpu/drm/omapdrm/omap_connector.c
> +++ b/drivers/gpu/drm/omapdrm/omap_connector.c
> @@ -162,7 +162,7 @@ static int omap_connector_mode_valid(struct drm_connector *connector,
>
> dssdrv->get_timings(dssdev, &t);
>
> - if (memcmp(&vm, &t, sizeof(struct videomode)))
> + if (memcmp(&vm, &t, sizeof(vm)))
> r = -EINVAL;
> else
> r = 0;
> @@ -217,7 +217,7 @@ struct drm_connector *omap_connector_init(struct drm_device *dev,
>
> omap_dss_get_device(dssdev);
>
> - omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL);
> + omap_connector = kzalloc(sizeof(*omap_connector), GFP_KERNEL);
> if (!omap_connector)
> goto fail;
>
> diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> index 4ceed7a9762f..3cab06661a08 100644
> --- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> +++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
> @@ -224,7 +224,7 @@ static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area,
> int rows = (1 + area->y1 - area->y0);
> int i = columns*rows;
>
> - pat = alloc_dma(txn, sizeof(struct pat), &pat_pa);
> + pat = alloc_dma(txn, sizeof(*pat), &pat_pa);
>
> if (txn->last_pat)
> txn->last_pat->next_pa = (uint32_t)pat_pa;
> @@ -735,7 +735,7 @@ static int omap_dmm_probe(struct platform_device *dev)
>
> /* alloc engines */
> omap_dmm->engines = kcalloc(omap_dmm->num_engines,
> - sizeof(struct refill_engine), GFP_KERNEL);
> + sizeof(*omap_dmm->engines), GFP_KERNEL);
> if (!omap_dmm->engines) {
> ret = -ENOMEM;
> goto fail;
> diff --git a/drivers/gpu/drm/omapdrm/omap_encoder.c b/drivers/gpu/drm/omapdrm/omap_encoder.c
> index a20f30039aee..86c977b7189a 100644
> --- a/drivers/gpu/drm/omapdrm/omap_encoder.c
> +++ b/drivers/gpu/drm/omapdrm/omap_encoder.c
> @@ -117,7 +117,7 @@ static int omap_encoder_update(struct drm_encoder *encoder,
>
> dssdrv->get_timings(dssdev, &t);
>
> - if (memcmp(vm, &t, sizeof(struct videomode)))
> + if (memcmp(vm, &t, sizeof(*vm)))
> ret = -EINVAL;
> else
> ret = 0;
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the dri-devel
mailing list