OSDN Git Service

drm/cma-helper: Turn to_drm_gem_cma_obj() into a macro
authorNoralf Trønnes <noralf@tronnes.org>
Tue, 7 Nov 2017 19:13:42 +0000 (20:13 +0100)
committerNoralf Trønnes <noralf@tronnes.org>
Sat, 11 Nov 2017 10:22:20 +0000 (11:22 +0100)
commit8d25ccebef55b8fc47b674f24ccdccbef08e2f32
tree7da3ee743db350e7970192fbc2b2af96bd289f1c
parentf02b604b07d5314d01968eda4e199e6c46352a6d
drm/cma-helper: Turn to_drm_gem_cma_obj() into a macro

This allows the argument to be a const.

The other option was to keep it an inline function and make the argument
a const:

static inline struct drm_gem_cma_object *
to_drm_gem_cma_obj(const struct drm_gem_object *gem_obj)
{
return container_of(gem_obj, struct drm_gem_cma_object, base);
}

This will happily return a non-const pointer to the drm_gem_cma_object
based on a const pointer to the contained drm_gem_object, thus creating
const-safety problems.

There was an attempt to fix the problem in the container_of() macro
itself (see https://lkml.org/lkml/2017/5/19/381) but the patch seems to
have fallen through the cracks. It would require turning this inline
function into a macro.

By making this a macro now, we will benefit from a possible future
enhancement of container_of(). We don't loose type checking by doing
this, container_of() takes care of that.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171107191348.17555-7-noralf@tronnes.org
include/drm/drm_gem_cma_helper.h