@@ -134,28 +134,70 @@ int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
int __must_check drm_atomic_commit(struct drm_atomic_state *state);
int __must_check drm_atomic_async_commit(struct drm_atomic_state *state);
+static inline int next_connector(struct drm_connector **pconnector,
+ struct drm_connector **connectors,
+ struct drm_connector_state **pstate,
+ struct drm_connector_state **states,
+ int index, int max)
+{
+ while (index < max && (connectors[index] == NULL || states[index] == NULL))
+ index++;
+
+ if (index < max) {
+ *pconnector = connectors[index];
+ *pstate = states[index];
+ }
+
+ return index;
+}
+
+static inline int next_crtc(struct drm_crtc **pcrtc,
+ struct drm_crtc **crtcs,
+ struct drm_crtc_state **pstate,
+ struct drm_crtc_state **states,
+ int index, int max)
+{
+ while (index < max && (crtcs[index] == NULL || states[index] == NULL))
+ index++;
+
+ if (index < max) {
+ *pcrtc = crtcs[index];
+ *pstate = states[index];
+ }
+
+ return index;
+}
+
+static inline int next_plane(struct drm_plane **pplane,
+ struct drm_plane **planes,
+ struct drm_plane_state **pstate,
+ struct drm_plane_state **states,
+ int index, int max)
+{
+ while (index < max && (planes[index] == NULL || states[index] == NULL))
+ index++;
+
+ if (index < max) {
+ *pplane = planes[index];
+ *pstate = states[index];
+ }
+
+ return index;
+}
+
#define for_each_connector_in_state(state, connector, connector_state, __i) \
- for ((__i) = 0; \
- (connector) = (state)->connectors[__i], \
- (connector_state) = (state)->connector_states[__i], \
+ for ((__i) = next_connector(&(connector), (state)->connectors, &(connector_state), (state)->connector_states, 0, (state)->num_connector); \
(__i) < (state)->num_connector; \
- (__i)++) \
- if (connector)
-
-#define for_each_crtc_in_state(state, crtc, crtc_state, __i) \
- for ((__i) = 0; \
- (crtc) = (state)->crtcs[__i], \
- (crtc_state) = (state)->crtc_states[__i], \
- (__i) < (state)->dev->mode_config.num_crtc; \
- (__i)++) \
- if (crtc_state)
-
-#define for_each_plane_in_state(state, plane, plane_state, __i) \
- for ((__i) = 0; \
- (plane) = (state)->planes[__i], \
- (plane_state) = (state)->plane_states[__i], \
- (__i) < (state)->dev->mode_config.num_total_plane; \
- (__i)++) \
- if (plane_state)
+ (__i) = next_connector(&(connector), (state)->connectors, &(connector_state), (state)->connector_states, (__i), (state)->num_connector))
+
+#define for_each_crtc_in_state(state, crtc, crtc_state, __i) \
+ for ((__i) = next_crtc(&(crtc), (state)->crtcs, &(crtc_state), (state)->crtc_states, 0, (state)->dev->mode_config.num_crtc); \
+ (__i) < (state)->dev->mode_config.num_crtc; \
+ (__i) = next_crtc(&crtc, (state)->crtcs, &(crtc_state), (state)->crtc_states, (__i), (state)->dev->mode_config.num_crtc))
+
+#define for_each_plane_in_state(state, plane, plane_state, __i) \
+ for ((__i) = next_plane(&(plane), (state)->planes, &(plane_state), (state)->plane_states, 0, (state)->dev->mode_config.num_total_plane); \
+ (__i) < (state)->dev->mode_config.num_total_plane; \
+ (__i) = next_plane(&(plane), (state)->planes, &(plane_state), (state)->plane_states, (__i), (state)->dev->mode_config.num_total_plane))
#endif /* DRM_ATOMIC_H_ */