Commit 89164fc8 authored by Ville Syrjälä's avatar Ville Syrjälä

drm/i915: Use container_of_const() for states

commit 64f6a5d1 ("container_of: add container_of_const()
that preserves const-ness of the pointer") is nice. Let's use
it so that we don't accidentally cast away the const from our
state pointers.

The only thing I don't particularly like about container_of_const()
is that it still accepts void* in addition to the proper pointer
types, but that's how most other things in C work anyway so I
guess we can live with it.

And while at it rename the macro arguments to be a bit more
descriptive than just 'x'.

TODO: maybe convert *all* container_of() uses to container_of_const()?
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240307151810.24208-4-ville.syrjala@linux.intel.comReviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
parent 7e0c5caf
...@@ -52,7 +52,8 @@ struct intel_bw_state { ...@@ -52,7 +52,8 @@ struct intel_bw_state {
u8 num_active_planes[I915_MAX_PIPES]; u8 num_active_planes[I915_MAX_PIPES];
}; };
#define to_intel_bw_state(x) container_of((x), struct intel_bw_state, base) #define to_intel_bw_state(global_state) \
container_of_const((global_state), struct intel_bw_state, base)
struct intel_bw_state * struct intel_bw_state *
intel_atomic_get_old_bw_state(struct intel_atomic_state *state); intel_atomic_get_old_bw_state(struct intel_atomic_state *state);
......
...@@ -80,7 +80,9 @@ int intel_cdclk_state_set_joined_mbus(struct intel_atomic_state *state, bool joi ...@@ -80,7 +80,9 @@ int intel_cdclk_state_set_joined_mbus(struct intel_atomic_state *state, bool joi
struct intel_cdclk_state * struct intel_cdclk_state *
intel_atomic_get_cdclk_state(struct intel_atomic_state *state); intel_atomic_get_cdclk_state(struct intel_atomic_state *state);
#define to_intel_cdclk_state(x) container_of((x), struct intel_cdclk_state, base) #define to_intel_cdclk_state(global_state) \
container_of_const((global_state), struct intel_cdclk_state, base)
#define intel_atomic_get_old_cdclk_state(state) \ #define intel_atomic_get_old_cdclk_state(state) \
to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, &to_i915(state->base.dev)->display.cdclk.obj)) to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, &to_i915(state->base.dev)->display.cdclk.obj))
#define intel_atomic_get_new_cdclk_state(state) \ #define intel_atomic_get_new_cdclk_state(state) \
......
...@@ -661,7 +661,8 @@ struct intel_digital_connector_state { ...@@ -661,7 +661,8 @@ struct intel_digital_connector_state {
int broadcast_rgb; int broadcast_rgb;
}; };
#define to_intel_digital_connector_state(x) container_of(x, struct intel_digital_connector_state, base) #define to_intel_digital_connector_state(conn_state) \
container_of_const((conn_state), struct intel_digital_connector_state, base)
struct dpll { struct dpll {
/* given values */ /* given values */
...@@ -1617,12 +1618,17 @@ struct intel_watermark_params { ...@@ -1617,12 +1618,17 @@ struct intel_watermark_params {
#define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base) #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
#define to_intel_crtc(x) container_of(x, struct intel_crtc, base) #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
#define to_intel_crtc_state(x) container_of(x, struct intel_crtc_state, uapi)
#define to_intel_connector(x) container_of(x, struct intel_connector, base) #define to_intel_connector(x) container_of(x, struct intel_connector, base)
#define to_intel_encoder(x) container_of(x, struct intel_encoder, base) #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
#define to_intel_plane(x) container_of(x, struct intel_plane, base) #define to_intel_plane(x) container_of(x, struct intel_plane, base)
#define to_intel_plane_state(x) container_of(x, struct intel_plane_state, uapi)
#define to_intel_crtc_state(crtc_state) \
container_of_const((crtc_state), struct intel_crtc_state, uapi)
#define to_intel_plane_state(plane_state) \
container_of_const((plane_state), struct intel_plane_state, uapi)
#define to_intel_framebuffer(fb) \
container_of_const((fb), struct intel_framebuffer, base)
#define intel_fb_obj(x) ((x) ? to_intel_bo((x)->obj[0]) : NULL) #define intel_fb_obj(x) ((x) ? to_intel_bo((x)->obj[0]) : NULL)
struct intel_hdmi { struct intel_hdmi {
......
...@@ -43,9 +43,8 @@ struct intel_pmdemand_state { ...@@ -43,9 +43,8 @@ struct intel_pmdemand_state {
struct pmdemand_params params; struct pmdemand_params params;
}; };
#define to_intel_pmdemand_state(x) container_of((x), \ #define to_intel_pmdemand_state(global_state) \
struct intel_pmdemand_state, \ container_of_const((global_state), struct intel_pmdemand_state, base)
base)
void intel_pmdemand_init_early(struct drm_i915_private *i915); void intel_pmdemand_init_early(struct drm_i915_private *i915);
int intel_pmdemand_init(struct drm_i915_private *i915); int intel_pmdemand_init(struct drm_i915_private *i915);
......
...@@ -193,7 +193,7 @@ to_intel_sdvo_connector(struct drm_connector *connector) ...@@ -193,7 +193,7 @@ to_intel_sdvo_connector(struct drm_connector *connector)
} }
#define to_intel_sdvo_connector_state(conn_state) \ #define to_intel_sdvo_connector_state(conn_state) \
container_of((conn_state), struct intel_sdvo_connector_state, base.base) container_of_const((conn_state), struct intel_sdvo_connector_state, base.base)
static bool static bool
intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo); intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo);
......
...@@ -885,7 +885,8 @@ struct intel_tv_connector_state { ...@@ -885,7 +885,8 @@ struct intel_tv_connector_state {
bool bypass_vfilter; bool bypass_vfilter;
}; };
#define to_intel_tv_connector_state(x) container_of(x, struct intel_tv_connector_state, base) #define to_intel_tv_connector_state(conn_state) \
container_of_const((conn_state), struct intel_tv_connector_state, base)
static struct drm_connector_state * static struct drm_connector_state *
intel_tv_connector_duplicate_state(struct drm_connector *connector) intel_tv_connector_duplicate_state(struct drm_connector *connector)
......
...@@ -65,7 +65,9 @@ struct intel_dbuf_state { ...@@ -65,7 +65,9 @@ struct intel_dbuf_state {
struct intel_dbuf_state * struct intel_dbuf_state *
intel_atomic_get_dbuf_state(struct intel_atomic_state *state); intel_atomic_get_dbuf_state(struct intel_atomic_state *state);
#define to_intel_dbuf_state(x) container_of((x), struct intel_dbuf_state, base) #define to_intel_dbuf_state(global_state) \
container_of_const((global_state), struct intel_dbuf_state, base)
#define intel_atomic_get_old_dbuf_state(state) \ #define intel_atomic_get_old_dbuf_state(state) \
to_intel_dbuf_state(intel_atomic_get_old_global_obj_state(state, &to_i915(state->base.dev)->display.dbuf.obj)) to_intel_dbuf_state(intel_atomic_get_old_global_obj_state(state, &to_i915(state->base.dev)->display.dbuf.obj))
#define intel_atomic_get_new_dbuf_state(state) \ #define intel_atomic_get_new_dbuf_state(state) \
......
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